1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
using Xunit;
namespace System.DirectoryServices.Protocols.Tests
{
public class SortRequestControlTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/dotnet/corefx/issues/21217", TargetFrameworkMonikers.UapAot)]
public void Ctor_SortKeys(bool critical)
{
SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) };
var control = new SortRequestControl(sortKeys);
Assert.True(control.IsCritical);
Assert.True(control.ServerSide);
Assert.Equal("1.2.840.113556.1.4.473", control.Type);
Assert.NotSame(sortKeys, control.SortKeys);
for (int i = 0; i < sortKeys.Length; i++)
{
Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName);
Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule);
Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder);
}
control.IsCritical = critical;
Assert.Equal(new byte[]
{
48, 132, 0, 0, 0, 43, 48, 132, 0, 0, 0, 17, 4, 5,110,
97, 109, 101, 49, 128, 5, 114, 117, 108, 101, 49, 129,
1, 255, 48, 132, 0, 0, 0, 14, 4, 5, 110, 97, 109, 101,
50, 128, 5, 114, 117, 108, 101, 50
}, control.GetValue());
}
[Fact]
public void Ctor_NullSortKeys_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("sortKeys", () => new SortRequestControl(null));
}
[Fact]
public void CtorNullValueInSortKeys_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("sortKeys", () => new SortRequestControl(new SortKey[] { null }));
}
[Fact]
public void Ctor_AttributeName_ReverseOrder()
{
var control = new SortRequestControl("AttributeName", true);
SortKey sortKey = Assert.Single(control.SortKeys);
Assert.Equal("AttributeName", sortKey.AttributeName);
Assert.True(control.IsCritical);
Assert.Null(sortKey.MatchingRule);
Assert.True(sortKey.ReverseOrder);
Assert.True(control.ServerSide);
Assert.Equal("1.2.840.113556.1.4.473", control.Type);
}
[Fact]
public void Ctor_AttributeName_MatchingRule_ReverseOrder()
{
var control = new SortRequestControl("AttributeName", "MatchingRule", true);
SortKey sortKey = Assert.Single(control.SortKeys);
Assert.Equal("AttributeName", sortKey.AttributeName);
Assert.True(control.IsCritical);
Assert.Equal("MatchingRule", sortKey.MatchingRule);
Assert.True(sortKey.ReverseOrder);
Assert.True(control.ServerSide);
Assert.Equal("1.2.840.113556.1.4.473", control.Type);
}
[Fact]
public void SortKeys_SetValid_GetReturnsExpected()
{
SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) };
var control = new SortRequestControl { SortKeys = sortKeys };
Assert.NotSame(sortKeys, control.SortKeys);
for (int i = 0; i < sortKeys.Length; i++)
{
Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName);
Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule);
Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder);
}
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "The field _keys in full framework is called keys, so GetField returns null and ends up in a NRE")]
public void SortKeys_GetNull_ReturnsEmptyArray()
{
var control = new SortRequestControl();
FieldInfo field = control.GetType().GetField("_keys", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(control, null);
Assert.Empty(control.SortKeys);
}
[Fact]
public void SortKeys_SetNull_ThrowsArgumentNullException()
{
var control = new SortRequestControl(new SortKey[0]);
AssertExtensions.Throws<ArgumentNullException>("value", () => control.SortKeys = null);
}
[Fact]
public void SortKeys_SetNullInValue_ThrowsArgumentException()
{
var control = new SortRequestControl(new SortKey[0]);
AssertExtensions.Throws<ArgumentException>("value", () => control.SortKeys = new SortKey[] { null });
}
}
}
|