public void Parts() { var catalog = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); Assert.NotNull(catalog.Parts); Assert.True(catalog.Parts.Count() > 0); }
public void GetExports() { var catalog = new AggregateCatalog(); Expression <Func <ExportDefinition, bool> > constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > matchingExports = null; matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() == 0); var testsDirectoryCatalog = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); catalog.Catalogs.Add(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() >= 0); IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > expectedMatchingExports = catalog.Parts .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple <ComposablePartDefinition, ExportDefinition>(part, export)) .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport))); Assert.True(matchingExports.SequenceEqual(expectedMatchingExports)); catalog.Catalogs.Remove(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.NotNull(matchingExports); Assert.True(matchingExports.Count() == 0); }
public void Refresh_AssemblyAdded_ShouldFireOnChanged() { bool changedFired = false; bool changingFired = false; var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); Assert.Equal(0, cat.Parts.Count()); cat.Changing += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) => { Assert.Equal(0, cat.Parts.Count()); changingFired = true; }); cat.Changed += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) => { Assert.NotEqual(0, cat.Parts.Count()); changedFired = true; }); File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.dll")); cat.Refresh(); Assert.True(changingFired); Assert.True(changedFired); }
public void Constructor_NonExistentDirectory_ShouldThrow() { Assert.Throws <DirectoryNotFoundException>(() => new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory() + @"\NonexistentDirectoryWithoutEndingSlash")); Assert.Throws <DirectoryNotFoundException>(() => new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory() + @"\NonexistentDirectoryWithEndingSlash\")); }
public void Refresh_DirectoryRemoved_ShouldThrowDirectoryNotFound() { DirectoryCatalog cat; cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); ExceptionAssert.Throws <DirectoryNotFoundException>(RetryMode.DoNotRetry, () => cat.Refresh()); }
public void Refresh_NoChanges_ShouldNotFireOnChanged() { var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); cat.Changed += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) => Assert.False(true)); cat.Refresh(); }
public void Parts_ShouldSetDefinitionOriginToCatalogItself() { var catalog = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); Assert.True(catalog.Parts.Count() > 0); foreach (ICompositionElement definition in catalog.Parts) { Assert.Same(catalog, definition.Origin); } }
public void AddAndRemoveDirectory() { var cat = new AggregateCatalog(); var container = new CompositionContainer(cat); Assert.False(container.IsPresent <MyExport>()); var dir1 = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); cat.Catalogs.Add(dir1); Assert.True(container.IsPresent <MyExport>()); cat.Catalogs.Remove(dir1); Assert.False(container.IsPresent <MyExport>()); }
public void Path_ValidPath_ShouldBeFine() { var expectations = new ExpectationCollection <string, string>(); expectations.Add(".", "."); expectations.Add(TemporaryFileCopier.RootTemporaryDirectoryName, TemporaryFileCopier.RootTemporaryDirectoryName); expectations.Add(TemporaryFileCopier.GetRootTemporaryDirectory(), TemporaryFileCopier.GetRootTemporaryDirectory()); expectations.Add(TemporaryFileCopier.GetTemporaryDirectory(), TemporaryFileCopier.GetTemporaryDirectory()); foreach (var e in expectations) { var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern); Assert.Equal(e.Output, cat.Path); } }
public void LoadedFiles_ContainsMultipleDllsAndSomeNonDll_ShouldOnlyContainDlls() { // Add one text file using (File.CreateText(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.txt"))) { } // Add two dll's string dll1 = Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test1.dll"); string dll2 = Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test2.dll"); File.Copy(Assembly.GetExecutingAssembly().Location, dll1); File.Copy(Assembly.GetExecutingAssembly().Location, dll2); var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); EqualityExtensions.CheckEquals(new string[] { dll1.ToUpperInvariant(), dll2.ToUpperInvariant() }, cat.LoadedFiles); }
public void Refresh_AssemblyRemoved_ShouldFireOnChanged() { string file = Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.dll"); File.Copy(Assembly.GetExecutingAssembly().Location, file); bool changedFired = false; var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); cat.Changed += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) => changedFired = true); // This assembly can be deleted because it was already loaded by the CLR in another context // in another location so it isn't locked on disk. File.Delete(file); cat.Refresh(); Assert.True(changedFired); }
public void FullPath_ValidPath_ShouldBeFine() { var expectations = new ExpectationCollection <string, string>(); // Ensure the path is always normalized properly. string rootTempPath = Path.GetFullPath(TemporaryFileCopier.GetRootTemporaryDirectory()).ToUpperInvariant(); // Note: These relative paths work properly because the unit test temporary directories are always // created as a subfolder off the AppDomain.CurrentDomain.BaseDirectory. expectations.Add(".", Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".")).ToUpperInvariant()); expectations.Add(TemporaryFileCopier.RootTemporaryDirectoryName, rootTempPath); expectations.Add(TemporaryFileCopier.GetRootTemporaryDirectory(), rootTempPath); expectations.Add(TemporaryFileCopier.GetTemporaryDirectory(), Path.GetFullPath(TemporaryFileCopier.GetTemporaryDirectory()).ToUpperInvariant()); foreach (var e in expectations) { var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern); Assert.Equal(e.Output, cat.FullPath); } }
public void Constructor_PassNonExistingFileName_ShouldThrow() { Assert.Throws <DirectoryNotFoundException>(() => new DirectoryCatalog(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "NonExistingFile.txt"))); }
public void Constructor_PassExistingFileName_ShouldThrow() { using (File.CreateText(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.txt"))) { } Assert.Throws <IOException>(() => new DirectoryCatalog(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.txt"))); }
public void Constructor_InvalidAssembly_ShouldBeFine() { using (File.CreateText(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.dll"))) { } var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); }
public void LoadedFiles_EmptyDirectory_ShouldBeFine() { var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory()); Assert.Equal(0, cat.LoadedFiles.Count); }