Exemple #1
0
        internal void KnownRuntime(Platform platform, string runtime, string expectedRuntimeGraph, string expectedCompatibleRuntimes, string expectedUnmanagedMap)
        {
            var cache = TestableDependencyContextAssemblyCache.Create(platform, runtime);

            Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                              message => Assert.Equal <object>($"[XunitPackageCompilationAssemblyResolver.GetDefaultProbeDirectories] returns: ['{NuGetHelper.PackageCachePath}']", message),
                              message => Assert.Equal <object>($"[DependencyContextAssemblyCache..ctor] Runtime graph: {expectedRuntimeGraph}", message),
                              message => Assert.Equal <object>($"[DependencyContextAssemblyCache..ctor] Compatible runtimes: {expectedCompatibleRuntimes}", message),
                              message => Assert.Equal <object>("[DependencyContextAssemblyCache..ctor] Managed assembly map: ['managed.ref1','managed.ref2']", message),
                              message => Assert.Equal <object>($"[DependencyContextAssemblyCache..ctor] Unmanaged assembly map: {expectedUnmanagedMap}", message)
                              );
        }
Exemple #2
0
        internal void UnknownRuntime(Platform platform, string runtime, string expectedFallbackRuntime, string expectedCompatibleRuntimes)
        {
            var cache = TestableDependencyContextAssemblyCache.Create(platform, runtime);

            Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                              message => { }, // NuGet path is same as known runtime
                              message => { }, // Runtime graph is same as known runtime
                              message => Assert.Equal($"[DependencyContextAssemblyCache.GetFallbackRuntime] Could not find runtime '{runtime}', falling back to '{expectedFallbackRuntime}'", message),
                              message => Assert.Equal($"[DependencyContextAssemblyCache..ctor] Compatible runtimes: {expectedCompatibleRuntimes}", message),
                              message => { }, // Managed assembly map is the same as known runtime
                              message => { } // Unmanaged assembly map is the same as known runtime
                              );
        }
Exemple #3
0
            public void NotInCache()
            {
                var cache = TestableDependencyContextAssemblyCache.Create();

                cache.GetAndClearDiagnosticMessages();

                var result = cache.LoadManagedDll("managed.ref1");

                Assert.Null(result);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal <object>("[DependencyContextAssemblyCache.ResolveManagedAssembly] Resolving 'managed.ref1', found in dependency map, but unable to resolve a path in ['runtime/any/managed.ref1.dll','runtime/any/managed.ref2.dll']", message),
                                  message => Assert.Equal <object>("[DependencyContextAssemblyCache.LoadManagedDll] Resolution for 'managed.ref1' failed, passed down to next resolver", message)
                                  );
            }
Exemple #4
0
        public void NotInCache()
        {
            var cache = TestableDependencyContextAssemblyCache.Create();

            cache.GetAndClearDiagnosticMessages();

            var result = cache.LoadUnmanagedLibrary("dependency1");

            Assert.Equal(IntPtr.Zero, result);
            Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                              message => Assert.Equal("[DependencyContextAssemblyCache.ResolveUnmanagedLibrary] Found in dependency map, but unable to resolve a path in ['native/win/dependency1.dll','native/win/dependency2.dll']", message),
                              message => Assert.Equal("[DependencyContextAssemblyCache.LoadUnmanagedLibrary] Resolution for 'dependency1' failed, passed down to next resolver", message)
                              );
        }
Exemple #5
0
            public void WithNoSuitableRuntime()
            {
                var cache = TestableDependencyContextAssemblyCache.Create(Platform.Darwin, "osx.10.10-x64", "osx.10.12-x64");

                cache.GetAndClearDiagnosticMessages();
                cache.MockAllLibrariesPresentInNuGetCache();

                var result = cache.LoadManagedDll("managed.ref1");

                Assert.Null(result);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal("[DependencyContextAssemblyCache.LoadManagedDll] Resolution for 'managed.ref1' failed, passed down to next resolver", message)
                                  );
            }
Exemple #6
0
        internal void InCache(Platform platform, string runtime, string unmanagedLibraryName, string relativePath)
        {
            var cache = TestableDependencyContextAssemblyCache.Create(platform, runtime);

            cache.GetAndClearDiagnosticMessages();
            cache.MockAllLibrariesPresentInNuGetCache();
            var expectedPath = Path.GetFullPath(Path.Combine(NuGetHelper.PackageCachePath, "packagename/1.2.3.4", relativePath));

            var result = cache.LoadUnmanagedLibrary(unmanagedLibraryName);

            Assert.NotEqual(IntPtr.Zero, result);
            var message = Assert.Single(cache.GetAndClearDiagnosticMessages());

            Assert.Equal($"[DependencyContextAssemblyCache.LoadUnmanagedLibrary] Resolved '{unmanagedLibraryName}' to '{expectedPath}'", message);
        }
Exemple #7
0
        public void WontLoad()
        {
            var cache = TestableDependencyContextAssemblyCache.Create();

            cache.GetAndClearDiagnosticMessages();
            cache.MockAllLibrariesPresentInNuGetCache();
            var expectedPath = Path.GetFullPath(Path.Combine(NuGetHelper.PackageCachePath, "packagename/1.2.3.4/native/win/dependency1.dll"));

            var result = cache.LoadUnmanagedLibrary("dependency1", _ => IntPtr.Zero);

            Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                              message => Assert.Equal($"[DependencyContextAssemblyCache.LoadUnmanagedLibrary] Resolving 'dependency1', found assembly path '{expectedPath}' but the assembly would not load", message),
                              message => Assert.Equal("[DependencyContextAssemblyCache.LoadUnmanagedLibrary] Resolution for 'dependency1' failed, passed down to next resolver", message)
                              );
        }
Exemple #8
0
            public void InCache(string relativePath)
            {
                var cache = TestableDependencyContextAssemblyCache.Create();

                cache.GetAndClearDiagnosticMessages();
                cache.MockAllLibrariesPresentInNuGetCache();
                var fileName     = Path.GetFileNameWithoutExtension(relativePath);
                var expectedPath = Path.GetFullPath(Path.Combine(NuGetHelper.PackageCachePath, "packagename/1.2.3.4", relativePath));

                var result = cache.LoadManagedDll(fileName);

                Assert.Equal(expectedPath, result.Location);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal($"[DependencyContextAssemblyCache.LoadManagedDll] Resolved '{fileName}' to '{expectedPath}'", message)
                                  );
            }
Exemple #9
0
            public void WontLoad()
            {
                var cache = TestableDependencyContextAssemblyCache.Create();

                cache.GetAndClearDiagnosticMessages();
                cache.MockAllLibrariesPresentInNuGetCache();
                var expectedPath = Path.GetFullPath(Path.Combine(NuGetHelper.PackageCachePath, "packagename/1.2.3.4/runtime/any/managed.ref1.dll"));

                var result = cache.LoadManagedDll("managed.ref1", _ => null);

                Assert.Null(result);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal($"[DependencyContextAssemblyCache.ResolveManagedAssembly] Resolving 'managed.ref1', found assembly path '{expectedPath}' but the assembly would not load", message),
                                  message => Assert.Equal("[DependencyContextAssemblyCache.LoadManagedDll] Resolution for 'managed.ref1' failed, passed down to next resolver", message)
                                  );
            }
Exemple #10
0
            public void WithDownlevelRuntime()
            {
                var cache = TestableDependencyContextAssemblyCache.Create(Platform.Darwin, "osx.10.12-x64", "osx.10.11-x64");

                cache.GetAndClearDiagnosticMessages();
                cache.MockAllLibrariesPresentInNuGetCache();
                var expectedPath = Path.GetFullPath(Path.Combine(NuGetHelper.PackageCachePath, "packagename/1.2.3.4/runtime/osx.10.11-x64/managed.ref1.dll"));

                var result = cache.LoadManagedDll("managed.ref1");

                Assert.NotNull(result);
                Assert.Equal(expectedPath, result.Location);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal($"[DependencyContextAssemblyCache.LoadManagedDll] Resolved 'managed.ref1' to '{expectedPath}'", message)
                                  );
            }
Exemple #11
0
            public void PresentLocally()
            {
                var cache = TestableDependencyContextAssemblyCache.Create();

                cache.GetAndClearDiagnosticMessages();
                cache.MockAllLibrariesPresentInNuGetCache();
                var expectedPath = Path.GetFullPath(Path.Combine(cache.AssemblyFolder, "managed.ref1.dll"));

                cache.FileSystem.File.Exists(expectedPath).Returns(true);

                var result = cache.LoadManagedDll("managed.ref1");

                Assert.Equal(expectedPath, result.Location);
                Assert.Collection(cache.GetAndClearDiagnosticMessages(),
                                  message => Assert.Equal($"[DependencyContextAssemblyCache.LoadManagedDll] Resolved 'managed.ref1' to '{expectedPath}'", message)
                                  );
            }