Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 696bc03

Browse files
committed
Port the DirectoryService test fix from master branch
1 parent 09b3cc0 commit 696bc03

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransportTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ public void FindByTransportType_DomainNoDomainAssociatedWithoutName_ThrowsArgume
6060
[InlineData(DirectoryContextType.DirectoryServer)]
6161
[InlineData(DirectoryContextType.Domain)]
6262
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Access to common path is denied inside App")]
63-
public void FindByTransportType_InvalidContextTypeWithName_ThrowsArgumentException(DirectoryContextType type)
63+
public void FindByTransportType_InvalidContextTypeWithName(DirectoryContextType type)
6464
{
6565
var context = new DirectoryContext(type, "Name");
66-
AssertExtensions.Throws<ArgumentException>("context", () => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));
66+
Exception exception = Record.Exception(() => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));
67+
Assert.NotNull(exception);
68+
Assert.True(exception is ArgumentException ||
69+
exception is ActiveDirectoryOperationException,
70+
$"We got unrecognized exception {exception}");
6771
}
6872

6973
[Fact]

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/DomainControllerTests.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@ public void GetDomainController_InvalidContextType_ThrowsArgumentException(Direc
3131
[InlineData("\0")]
3232
[InlineData("[")]
3333
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Access to path is denied when in App container")]
34-
public void GetDomainController_InvalidName_ThrowsActiveDirectoryObjectNotFoundException(string name)
34+
public void GetDomainController_InvalidName(string name)
3535
{
3636
var context = new DirectoryContext(DirectoryContextType.DirectoryServer, name);
37-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => DomainController.GetDomainController(context));
37+
Exception exception = Record.Exception(() => DomainController.GetDomainController(context));
38+
Assert.NotNull(exception);
39+
Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
40+
exception is ActiveDirectoryOperationException,
41+
$"We got unrecognized exception {exception}");
3842
}
3943

4044
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
4145
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Access to path is denied when in App container")]
42-
public void GetDomainController_InvalidIPV6_ThrowsActiveDirectoryObjectNotFoundException()
46+
public void GetDomainController_InvalidIPV6()
4347
{
4448
var context = new DirectoryContext(DirectoryContextType.DirectoryServer, "[::1]:port");
45-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => DomainController.GetDomainController(context));
49+
Exception exception = Record.Exception(() => DomainController.GetDomainController(context));
50+
Assert.NotNull(exception);
51+
Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
52+
exception is ActiveDirectoryOperationException,
53+
$"We got unrecognized exception {exception}");
4654
}
4755

4856
[Fact]

src/System.DirectoryServices/tests/System/DirectoryServices/ActiveDirectory/ForestTests.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,23 @@ public void GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectN
5353
[InlineData(DirectoryContextType.Forest, "\0")]
5454
[InlineData(DirectoryContextType.DirectoryServer, "server:port")]
5555
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Not approved COM object for app")]
56-
public void GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectNotFoundException_NonUap(DirectoryContextType type, string name)
56+
public void GetForest_NonNullNameAndNotRootedDomain_NonUap(DirectoryContextType type, string name)
5757
{
5858
var context = new DirectoryContext(type, name);
5959
if (!PlatformDetection.IsDomainJoinedMachine)
6060
{
61-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
61+
Exception exception = Record.Exception(() => Forest.GetForest(context));
62+
Assert.NotNull(exception);
63+
Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
64+
exception is ActiveDirectoryOperationException,
65+
$"We got unrecognized exception {exception}");
6266

6367
// The result of validation is cached, so repeat this to make sure it's cached properly.
64-
Assert.Throws<ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
68+
exception = Record.Exception(() => Forest.GetForest(context));
69+
Assert.NotNull(exception);
70+
Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
71+
exception is ActiveDirectoryOperationException,
72+
$"We got unrecognized exception {exception}");
6573
}
6674
}
6775
}

0 commit comments

Comments
 (0)