1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using Xunit;
6 
7 namespace System.DirectoryServices.Protocols.Tests
8 {
9     public class DirectoryControlTests
10     {
11         [Theory]
12         [InlineData("", null, false, false)]
13         [InlineData("Type", new byte[] { 1, 2, 3 }, true, true)]
Ctor_Type_Value_IsCritical_ServerSide(string type, byte[] value, bool isCritical, bool serverSide)14         public void Ctor_Type_Value_IsCritical_ServerSide(string type, byte[] value, bool isCritical, bool serverSide)
15         {
16             var control = new DirectoryControl(type, value, isCritical, serverSide);
17             Assert.Equal(type, control.Type);
18             Assert.Equal(isCritical, control.IsCritical);
19             Assert.Equal(serverSide, control.ServerSide);
20 
21             byte[] controlValue = control.GetValue();
22             Assert.NotSame(controlValue, value);
23             Assert.Equal(value ?? Array.Empty<byte>(), controlValue);
24         }
25 
26         [Fact]
Ctor_NullType_ThrowsArgumentNullException()27         public void Ctor_NullType_ThrowsArgumentNullException()
28         {
29             AssertExtensions.Throws<ArgumentNullException>("type", () => new DirectoryControl(null, new byte[0], false, false));
30         }
31 
32         [Fact]
IsCritical_Set_GetReturnsExpected()33         public void IsCritical_Set_GetReturnsExpected()
34         {
35             var control = new DirectoryControl("Type", null, false, true);
36             Assert.False(control.IsCritical);
37 
38             control.IsCritical = true;
39             Assert.True(control.IsCritical);
40         }
41 
42         [Fact]
ServerSide_Set_GetReturnsExpected()43         public void ServerSide_Set_GetReturnsExpected()
44         {
45             var control = new DirectoryControl("Type", null, true, false);
46             Assert.False(control.ServerSide);
47 
48             control.ServerSide = true;
49             Assert.True(control.ServerSide);
50         }
51     }
52 }
53