public void StartService_ReadsMultipleAddinsFilesFromSingleDirectory() { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var addinsFile1 = Substitute.For <IFile>(); addinsFile1.Parent.Returns(startDirectory); addinsFile1.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile1 }); var addinsFile2 = Substitute.For <IFile>(); addinsFile1.Parent.Returns(startDirectory); addinsFile1.FullName.Returns(Path.Combine(startDirectoryPath, "test2.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile1, addinsFile2 }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); var sut = new ExtensionService(false, addinsReader, fileSystem); // Act sut.StartService(); // Assert startDirectory.Received().GetFiles("*.addins"); addinsReader.Received().Read(addinsFile1); addinsReader.Received().Read(addinsFile2); }
public void ProcessAddinsFile_InvalidAbsolutePathToDirectory_NonWindows(string windowsPath) { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var addinsFile = Substitute.For <IFile>(); addinsFile.Parent.Returns(startDirectory); addinsFile.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); addinsReader.Read(addinsFile).Returns(new[] { windowsPath }); var directoryFinder = Substitute.For <IDirectoryFinder>(); var sut = new ExtensionService(false, addinsReader, fileSystem, directoryFinder); // Act sut.StartService(); // Assert addinsReader.Received().Read(addinsFile); directoryFinder.Received().GetDirectories(startDirectory, windowsPath); }
public void StartService_UseFileSystemAbstraction() { var fileSystem = Substitute.For <IFileSystem>(); var service = new ExtensionService(false, fileSystem); var workingDir = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); service.StartService(); fileSystem.Received().GetDirectory(workingDir); }
public void ProcessAddinsFile_ReadsAddinsFileFromReferencedDirectory() { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var referencedDirectoryPath = Path.Combine(startDirectoryPath, "metamorphosator"); var referencedDirectory = Substitute.For <IDirectory>(); referencedDirectory.FullName.Returns(referencedDirectoryPath); referencedDirectory.Parent.Returns(startDirectory); var addinsFile = Substitute.For <IFile>(); addinsFile.Parent.Returns(startDirectory); addinsFile.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); var referencedAddinsFile = Substitute.For <IFile>(); referencedAddinsFile.Parent.Returns(referencedDirectory); referencedAddinsFile.FullName.Returns(Path.Combine(referencedDirectoryPath, "test2.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile }); referencedDirectory.GetFiles("*.addins").Returns(new[] { referencedAddinsFile }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(referencedDirectoryPath).Returns(referencedDirectory); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); addinsReader.Read(addinsFile).Returns(new[] { "./metamorphosator/" }); var directoryFinder = Substitute.For <IDirectoryFinder>(); directoryFinder.GetDirectories(startDirectory, "./metamorphosator/").Returns(new[] { referencedDirectory }); var sut = new ExtensionService(false, addinsReader, fileSystem, directoryFinder); // Act sut.StartService(); // Assert startDirectory.Received().GetFiles("*.addins"); addinsReader.Received().Read(addinsFile); referencedDirectory.Received().GetFiles("*.addins"); addinsReader.Received().Read(referencedAddinsFile); }
public void ProcessAddinsFile_RelativePaths() { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var addinsFile = Substitute.For <IFile>(); addinsFile.Parent.Returns(startDirectory); addinsFile.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); addinsReader.Read(addinsFile).Returns( new[] { "path/to/directory/", "directory2/", "**/wildcard-directory/", "path/to/file/file1.dll", "file2.dll", "**/wildcard-file.dll" }); var directoryFinder = Substitute.For <IDirectoryFinder>(); var sut = new ExtensionService(false, addinsReader, fileSystem, directoryFinder); // Act sut.StartService(); // Assert addinsReader.Received().Read(addinsFile); directoryFinder.Received().GetDirectories(startDirectory, "path/to/directory/"); directoryFinder.Received().GetDirectories(startDirectory, "directory2/"); directoryFinder.Received().GetDirectories(startDirectory, "**/wildcard-directory/"); directoryFinder.Received().GetFiles(startDirectory, "path/to/file/file1.dll"); directoryFinder.Received().GetFiles(startDirectory, "file2.dll"); directoryFinder.Received().GetFiles(startDirectory, "**/wildcard-file.dll"); }
public void StartService_ReadsAddinsFilesFromMultipleDirectories() { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var subdirectoryPath = Path.Combine(startDirectoryPath, "subdirectory"); var subdirectory = Substitute.For <IDirectory>(); subdirectory.FullName.Returns(subdirectoryPath); subdirectory.GetDirectories(Arg.Any <string>(), Arg.Any <SearchOption>()).Returns(new IDirectory[] { }); subdirectory.GetFiles(Arg.Any <string>()).Returns(new IFile[] { }); var addinsFile = Substitute.For <IFile>(); addinsFile.Parent.Returns(startDirectory); addinsFile.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); var addinsFile2 = Substitute.For <IFile>(); addinsFile2.Parent.Returns(subdirectory); addinsFile2.FullName.Returns(Path.Combine(subdirectoryPath, "second.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile }); startDirectory.GetDirectories("subdirectory", SearchOption.TopDirectoryOnly).Returns(new[] { subdirectory }); subdirectory.GetFiles(Arg.Any <string>()).Returns(ci => (string)ci[0] == "*.addins" ? new[] { addinsFile2 } : new IFile[] { }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); fileSystem.GetDirectory(subdirectoryPath).Returns(subdirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); addinsReader.Read(addinsFile).Returns(new[] { "subdirectory/" }); var sut = new ExtensionService(false, addinsReader, fileSystem); // Act sut.StartService(); // Assert startDirectory.Received().GetFiles("*.addins"); addinsReader.Received().Read(addinsFile); subdirectory.Received().GetFiles("*.addins"); addinsReader.Received().Read(addinsFile2); }
public void ProcessAddinsFile_AbsolutePath_NonWindows() { // Arrange var startDirectoryPath = AssemblyHelper.GetDirectoryName(typeof(ExtensionService).Assembly); var startDirectory = Substitute.For <IDirectory>(); startDirectory.FullName.Returns(startDirectoryPath); var metamorphosatorDirectoryPath = "/tmp/tools/metamorphosator"; var metamorphosatorDirectory = Substitute.For <IDirectory>(); metamorphosatorDirectory.FullName.Returns(metamorphosatorDirectoryPath); var usrDirectoryPath = "/usr"; var toolsDirectory = Substitute.For <IDirectory>(); toolsDirectory.FullName.Returns(usrDirectoryPath); var addinsFile = Substitute.For <IFile>(); addinsFile.Parent.Returns(startDirectory); addinsFile.FullName.Returns(Path.Combine(startDirectoryPath, "test.addins")); startDirectory.GetFiles("*.addins").Returns(new[] { addinsFile }); var fileSystem = Substitute.For <IFileSystem>(); fileSystem.GetDirectory(startDirectoryPath).Returns(startDirectory); fileSystem.GetDirectory(metamorphosatorDirectoryPath + "/").Returns(metamorphosatorDirectory); fileSystem.GetDirectory(usrDirectoryPath).Returns(toolsDirectory); var addinsReader = Substitute.For <IAddinsFileReader>(); addinsReader.Read(addinsFile).Returns(new[] { "/tmp/tools/metamorphosator/", "/usr/frobuscator.dll" }); var directoryFinder = Substitute.For <IDirectoryFinder>(); var sut = new ExtensionService(false, addinsReader, fileSystem, directoryFinder); // Act sut.StartService(); // Assert addinsReader.Received().Read(addinsFile); directoryFinder.Received().GetDirectories(metamorphosatorDirectory, string.Empty); directoryFinder.Received().GetFiles(toolsDirectory, "frobuscator.dll"); directoryFinder.DidNotReceive().GetDirectories(toolsDirectory, Arg.Is <string>(s => s != "frobuscator.dll")); }
public void CreateService() { _extensionService = new ExtensionService(); _extensionService.StartService(); }