@@ -25,26 +25,33 @@ namespace MongoDB.Driver.Core.Tests.Core.NativeLibraryLoader
2525{
2626 public class NativeLibraryLoaderTests
2727 {
28+ [ Fact ]
29+ public void GetLibraryBasePath_should_get_correct_paths_for_assembly_based_path ( )
30+ {
31+ var subject = new TestRelativeLibraryLocator ( mockedAssemblyUri : null ) ;
32+
33+ var result = subject . GetLibraryBasePath ( ) ;
34+
35+ // Ideally the root folder for expectedResult should be mongo-csharp-driver,
36+ // but since it's not mocked logic it limits us where we can run our tests from. Avoid it by
37+ // making a test assertation less straight
38+ var expectedResult = GetCommonTestAssemblyFolderEnding ( ) ;
39+ result . Should ( ) . EndWith ( expectedResult ) ;
40+ }
41+
2842 [ Theory ]
29- [ InlineData ( null , "mongo-csharp-driver" ) ] // the default assembly-based logic
3043 [ InlineData ( "mongo-csharp-driver" , "mongo-csharp-driver" ) ]
3144 [ InlineData ( "mongo csharp driver" , "mongo csharp driver" ) ]
3245 [ InlineData ( "&mongo$csharp@driver%" , "&mongo$csharp@driver%" ) ]
33- public void GetLibraryBasePath_should_get_correct_paths ( string rootTestFolder , string expectedRootTestFolder )
46+ public void GetLibraryBasePath_should_get_correct_paths_with_mocking ( string rootTestFolder , string expectedRootTestFolder )
3447 {
35- string testAssemblyCodeBaseUri = null ; // use assembly-based CodeBase for null
36- if ( rootTestFolder != null )
37- {
38- // mock assembly-based CodeBase path
39- var assemblyPath = Path . Combine (
40- RequirePlatform . GetCurrentOperatingSystem ( ) == SupportedOperatingSystem . Windows ? "C:/" : @"\\data" ,
41- rootTestFolder ,
42- GetCommonTestAssemblyFolderEnding ( ) ,
43- "MongoDB.Driver.Core.dll" ) ;
44- testAssemblyCodeBaseUri = new Uri ( assemblyPath ) . ToString ( ) ;
45- }
46-
47- var subject = new TestRelativeLibraryLocator ( testAssemblyCodeBaseUri ) ;
48+ var assemblyCodeBase = Path . Combine (
49+ RequirePlatform . GetCurrentOperatingSystem ( ) == SupportedOperatingSystem . Windows ? "C:/" : @"\\data" ,
50+ rootTestFolder ,
51+ GetCommonTestAssemblyFolderEnding ( ) ,
52+ "MongoDB.Driver.Core.dll" ) ;
53+ var testAssemblyCodeBaseUri = new Uri ( assemblyCodeBase ) . ToString ( ) ;
54+ var subject = new TestRelativeLibraryLocator ( mockedAssemblyUri : testAssemblyCodeBaseUri ) ;
4855
4956 var result = subject . GetLibraryBasePath ( ) ;
5057
@@ -82,15 +89,16 @@ private string GetTargetFrameworkMonikerName() =>
8289 // nested types
8390 private class TestRelativeLibraryLocator : RelativeLibraryLocatorBase
8491 {
85- private readonly string _testAssemblyUri ;
92+ private readonly string _mockedAssemblyUri ;
8693
87- public TestRelativeLibraryLocator ( string testAssemblyUri )
94+ public TestRelativeLibraryLocator ( string mockedAssemblyUri )
8895 {
89- _testAssemblyUri = testAssemblyUri ; // can be null
96+ _mockedAssemblyUri = mockedAssemblyUri ; // can be null
9097 }
9198
92- public override string GetBaseAssemblyUri ( ) => _testAssemblyUri ?? base . GetBaseAssemblyUri ( ) ;
99+ public override string GetBaseAssemblyUri ( ) => _mockedAssemblyUri ?? base . GetBaseAssemblyUri ( ) ;
93100
101+ // not required for these tests yet
94102 public override string GetLibraryRelativePath ( OperatingSystemPlatform currentPlatform ) => throw new NotImplementedException ( ) ;
95103 }
96104 }
0 commit comments