public void LoadFromPath_CanLoadAssembly() { using (var directory = TempDirectory.Create()) { // Arrange var alphaFilePath = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha.dll"); var loader = new TestDefaultExtensionAssemblyLoader(Path.Combine(directory.DirectoryPath, "shadow")); // Act var assembly = loader.LoadFromPath(alphaFilePath); // Assert Assert.NotNull(assembly); } }
public void Load_CanLoadAssemblyByName_AfterLoadingByPath() { using (var directory = TempDirectory.Create()) { // Arrange var alphaFilePath = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha.dll"); var loader = new TestDefaultExtensionAssemblyLoader(Path.Combine(directory.DirectoryPath, "shadow")); var assembly1 = loader.LoadFromPath(alphaFilePath); // Act var assembly2 = loader.Load(assembly1.FullName); // Assert Assert.Same(assembly1, assembly2); } }
public void GetMetadata_MultipleFiles_ReturnsDifferentResultsAndAddsToCache() { using (var directory = TempDirectory.Create()) { // Arrange var metadataCache = new MetadataCache(); var assemblyFilePath1 = LoaderTestResources.Delta.WriteToFile(directory.DirectoryPath, "Delta.dll"); var assemblyFilePath2 = LoaderTestResources.Gamma.WriteToFile(directory.DirectoryPath, "Gamma.dll"); // Act var result1 = metadataCache.GetMetadata(assemblyFilePath1); var result2 = metadataCache.GetMetadata(assemblyFilePath2); // Assert Assert.NotSame(result1, result2); Assert.Equal(2, metadataCache.Cache.Count); } }
public void Check_ReturnsFalse_WithMissingDependency() { using (var directory = TempDirectory.Create()) { // Arrange var output = new StringWriter(); var alphaFilePath = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha.dll"); var loader = new TestDefaultExtensionAssemblyLoader(Path.Combine(directory.DirectoryPath, "shadow")); var checker = new DefaultExtensionDependencyChecker(loader, output); // Act var result = checker.Check(new[] { alphaFilePath, }); // Assert Assert.False(result, "Check should not have passed: " + output.ToString()); } }
public void LoadFromPath_DoesNotAddDuplicates_AfterLoadingByName() { using (var directory = TempDirectory.Create()) { // Arrange var alphaFilePath = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha.dll"); var alphaFilePath2 = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha2.dll"); var loader = new TestDefaultExtensionAssemblyLoader(Path.Combine(directory.DirectoryPath, "shadow")); loader.AddAssemblyLocation(alphaFilePath); var assembly1 = loader.Load("Alpha"); // Act var assembly2 = loader.LoadFromPath(alphaFilePath2); // Assert Assert.Same(assembly1, assembly2); } }
public void Check_ReturnsFalse_WhenLoaderThrows() { using (var directory = TempDirectory.Create()) { // Arrange var output = new StringWriter(); var deltaFilePath = LoaderTestResources.Delta.WriteToFile(directory.DirectoryPath, "Delta.dll"); var loader = new Mock <ExtensionAssemblyLoader>(); loader .Setup(l => l.LoadFromPath(It.IsAny <string>())) .Throws(new InvalidOperationException()); var checker = new DefaultExtensionDependencyChecker(loader.Object, output); // Act var result = checker.Check(new[] { deltaFilePath, }); // Assert Assert.False(result, "Check should not have passed: " + output.ToString()); } }
public void Check_ReturnsTrue_WithAllDependenciesProvided() { using (var directory = TempDirectory.Create()) { // Arrange var output = new StringWriter(); var alphaFilePath = LoaderTestResources.Alpha.WriteToFile(directory.DirectoryPath, "Alpha.dll"); var betaFilePath = LoaderTestResources.Beta.WriteToFile(directory.DirectoryPath, "Beta.dll"); var gammaFilePath = LoaderTestResources.Gamma.WriteToFile(directory.DirectoryPath, "Gamma.dll"); var deltaFilePath = LoaderTestResources.Delta.WriteToFile(directory.DirectoryPath, "Delta.dll"); var loader = new TestDefaultExtensionAssemblyLoader(Path.Combine(directory.DirectoryPath, "shadow")); var checker = new DefaultExtensionDependencyChecker(loader, output); // Act var result = checker.Check(new[] { alphaFilePath, betaFilePath, gammaFilePath, deltaFilePath, }); // Assert Assert.True(result, "Check should have passed: " + output.ToString()); } }
public void GetMetadata_UsesCache() { using (var directory = TempDirectory.Create()) { // Arrange var metadataCache = new MetadataCache(); var assemblyFilePath = LoaderTestResources.Delta.WriteToFile(directory.DirectoryPath, "Delta.dll"); // Act 1 var result = metadataCache.GetMetadata(assemblyFilePath); // Assert 1 Assert.NotNull(result); Assert.Equal(1, metadataCache.Cache.Count); // Act 2 var cacheResult = metadataCache.GetMetadata(assemblyFilePath); // Assert 2 Assert.Same(result, cacheResult); Assert.Equal(1, metadataCache.Cache.Count); } }