@@ -25,26 +25,33 @@ namespace MongoDB.Driver.Core.Tests.Core.NativeLibraryLoader
25
25
{
26
26
public class NativeLibraryLoaderTests
27
27
{
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
+
28
42
[ Theory ]
29
- [ InlineData ( null , "mongo-csharp-driver" ) ] // the default assembly-based logic
30
43
[ InlineData ( "mongo-csharp-driver" , "mongo-csharp-driver" ) ]
31
44
[ InlineData ( "mongo csharp driver" , "mongo csharp driver" ) ]
32
45
[ 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 )
34
47
{
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 ) ;
48
55
49
56
var result = subject . GetLibraryBasePath ( ) ;
50
57
@@ -82,15 +89,16 @@ private string GetTargetFrameworkMonikerName() =>
82
89
// nested types
83
90
private class TestRelativeLibraryLocator : RelativeLibraryLocatorBase
84
91
{
85
- private readonly string _testAssemblyUri ;
92
+ private readonly string _mockedAssemblyUri ;
86
93
87
- public TestRelativeLibraryLocator ( string testAssemblyUri )
94
+ public TestRelativeLibraryLocator ( string mockedAssemblyUri )
88
95
{
89
- _testAssemblyUri = testAssemblyUri ; // can be null
96
+ _mockedAssemblyUri = mockedAssemblyUri ; // can be null
90
97
}
91
98
92
- public override string GetBaseAssemblyUri ( ) => _testAssemblyUri ?? base . GetBaseAssemblyUri ( ) ;
99
+ public override string GetBaseAssemblyUri ( ) => _mockedAssemblyUri ?? base . GetBaseAssemblyUri ( ) ;
93
100
101
+ // not required for these tests yet
94
102
public override string GetLibraryRelativePath ( OperatingSystemPlatform currentPlatform ) => throw new NotImplementedException ( ) ;
95
103
}
96
104
}
0 commit comments