public FileDeleteFixture() { // Setup the files in the file system. Paths = new List <FilePath>(); Files = new List <IFile>(); _lookup = new Dictionary <string, IFile>(); CreateFile("./file1.txt", "/Working/file1.txt"); CreateFile("./file2.txt", "/Working/file2.txt"); // Setup the globber to return all files for wild card. Globber = Substitute.For <IGlobber>(); Globber.Match("*").Returns(c => Paths); // Setup the file system to return correct files when asked for. FileSystem = Substitute.For <IFileSystem>(); FileSystem.GetFile(Arg.Is <FilePath>(c => _lookup.ContainsKey(c.FullPath))) .Returns(c => _lookup[c.Arg <FilePath>().FullPath]); // Set the working directory. Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory.Returns("/Working"); // Prepare the context. Context = Substitute.For <ICakeContext>(); Context.FileSystem.Returns(FileSystem); Context.Environment.Returns(Environment); Context.Globber.Returns(Globber); }
public SignToolSignRunnerFixture() { Settings = new SignToolSignSettings(); Settings.CertPath = "./cert.pfx"; Settings.Password = "******"; Settings.TimeStampUri = new Uri("https://t.com"); AssemblyFile = Substitute.For <IFile>(); AssemblyFile.Exists.Returns(true); CertificateFile = Substitute.For <IFile>(); CertificateFile.Exists.Returns(true); DefaultToolFile = Substitute.For <IFile>(); DefaultToolFile.Exists.Returns(true); FileSystem = Substitute.For <IFileSystem>(); FileSystem.GetFile(Arg.Is <FilePath>(p => p.FullPath == "/Working/a.dll")).Returns(AssemblyFile); FileSystem.GetFile(Arg.Is <FilePath>(p => p.FullPath == "/Working/cert.pfx")).Returns(CertificateFile); FileSystem.GetFile(Arg.Is <FilePath>(p => p.FullPath == "/Working/Default/tool.exe")).Returns(DefaultToolFile); Resolver = Substitute.For <ISignToolResolver>(); Resolver.GetPath().Returns("/Working/Default/tool.exe"); Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/signtool.exe").Returns(new[] { (FilePath)"/Working/Default/tool.exe" }); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory.Returns("/Working"); ProcessRunner = Substitute.For <IProcessRunner>(); }
public CMakeRunnerFixture(FilePath toolPath = null, bool defaultToolExist = true) { Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory = "/Working"; Environment.IsUnix().Returns(false); Globber = Substitute.For <IGlobber>(); FileSystem = Substitute.For <IFileSystem>(); if (defaultToolExist) { Globber.Match("./tools/**/cmake.exe").Returns(new[] { (FilePath)"/Working/tools/cmake.exe" }); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/cmake.exe")).Returns(true); } if (toolPath != null) { FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true); } SourcePath = "./source"; Settings = new CMakeSettings(); }
public OctopusDeployReleaseCreatorFixture(FilePath toolPath = null, bool defaultToolExist = true) { Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory.Returns("/Working"); Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/Octo.exe").Returns(new[] { (FilePath)"/Working/tools/Octo.exe" }); FileSystem = Substitute.For <IFileSystem>(); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/Octo.exe")).Returns(defaultToolExist); if (toolPath != null) { FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true); } ProjectName = "testProject"; Settings = new CreateReleaseSettings { Server = "http://octopus", ApiKey = "API-12345" }; }
public FileCopyFixture() { // Setup the target directory. TargetDirectory = Substitute.For <IDirectory>(); TargetDirectory.Exists.Returns(true); // Setup the files in the file system. SourceFilePaths = new List <FilePath>(); TargetFiles = new List <IFile>(); TargetFilePaths = new List <FilePath>(); CreateTargetFile("./file1.txt", "/Working/file1.txt"); CreateTargetFile("./file2.txt", "/Working/file2.txt"); // Setup the globber to return all files for wild card. Globber = Substitute.For <IGlobber>(); Globber.Match("*").Returns(c => TargetFilePaths); // Setup the file system to return correct directories when asked for. FileSystem = Substitute.For <IFileSystem>(); FileSystem.GetDirectory(Arg.Is <DirectoryPath>(p => p.FullPath == "/Working/target")).Returns(c => TargetDirectory); FileSystem.GetFile(Arg.Is <FilePath>(p => p.FullPath == TargetFilePaths[0].FullPath)).Returns(c => TargetFiles[0]); FileSystem.GetFile(Arg.Is <FilePath>(p => p.FullPath == TargetFilePaths[1].FullPath)).Returns(c => TargetFiles[1]); // Set the working directory. Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory.Returns("/Working"); // Prepare the context. Context = Substitute.For <ICakeContext>(); Context.FileSystem.Returns(FileSystem); Context.Environment.Returns(Environment); Context.Globber.Returns(Globber); }
public NuGetFixture(FilePath toolPath = null, bool defaultToolExist = true) { Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory.Returns("/Working"); Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/NuGet.exe").Returns(new[] { (FilePath)"/Working/tools/NuGet.exe" }); Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <ProcessStartInfo>()).Returns(Process); Log = Substitute.For <ICakeLog>(); FileSystem = new FakeFileSystem(true); FileSystem.GetCreatedFile("/Working/existing.nuspec", Resources.Nuspec_NoMetadataValues); if (defaultToolExist) { FileSystem.GetCreatedFile("/Working/tools/NuGet.exe"); } if (toolPath != null) { FileSystem.GetCreatedFile(toolPath); } }
public ILMergeRunnerFixture(FilePath toolPath = null, bool defaultToolExist = true) { OutputAssemblyPath = "output.exe"; PrimaryAssemblyPath = "input.exe"; AssemblyPaths = new List <FilePath>(); Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <ProcessStartInfo>()).Returns(Process); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory = "/Working"; Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/ILMerge.exe").Returns(new[] { (FilePath)"/Working/tools/ILMerge.exe" }); FileSystem = Substitute.For <IFileSystem>(); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/ILMerge.exe")).Returns(defaultToolExist); if (toolPath != null) { FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true); } Settings = new ILMergeSettings(); }
public void Should_Ignore_Case_Sensitivity_On_Case_Insensitive_Operative_System(bool isUnix, bool shouldFindFile) { // Given var fixture = new GlobberFixture(isUnix); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = globber.Match("/Temp/**/text.txt").ToArray(); // Then Assert.Equal(shouldFindFile, result.Length == 1); }
public void Will_Append_Relative_Root_With_Implicit_Working_Directory() { // Given var fixture = new GlobberFixture(); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = globber.Match("Hello/World/Text.txt").ToArray(); // Then Assert.Equal(1, result.Length); Assert.Equal("/Working/Hello/World/Text.txt", result[0].FullPath); }
public void Should_Throw_If_Pattern_Is_Empty() { // Given var fixture = new GlobberFixture(); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = Record.Exception(() => globber.Match(null)); // Then Assert.IsType <ArgumentNullException>(result); Assert.Equal("pattern", ((ArgumentNullException)result).ParamName); }
public void Should_Throw_If_Unc_Root_Was_Encountered() { // Given var fixture = new GlobberFixture(isUnix: false); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = Record.Exception(() => globber.Match("//Hello/World/Text.txt")); // Then Assert.IsType <NotSupportedException>(result); Assert.Equal("UNC paths are not supported.", result.Message); }
public void Can_Traverse_Recursivly() { // Given var fixture = new GlobberFixture(); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = globber.Match("/Temp/**/*.txt").ToArray(); // Then Assert.Equal(2, result.Length); Assert.Equal("/Temp/Hello/World/Text.txt", result[0].FullPath); Assert.Equal("/Temp/Goodbye/OtherText.txt", result[1].FullPath); }
public void Will_Fix_Root_If_Drive_Is_Missing_By_Using_The_Drive_From_The_Working_Directory() { // Given var fixture = new GlobberFixture(isUnix: false); fixture.Environment.WorkingDirectory.Returns("C:/Working/"); var globber = new Globber(fixture.FileSystem, fixture.Environment); // When var result = globber.Match("/Temp/Hello/World/Text.txt").ToArray(); // Then Assert.Equal(1, result.Length); Assert.Equal("C:/Temp/Hello/World/Text.txt", result[0].FullPath); }
public XmlDocExampleCodeParserFixture() { XmlFilePath = "/Working/Cake.Common.xml"; Pattern = "/Working/Cake.*.xml"; var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile(XmlFilePath.FullPath).SetContent(Resources.XmlDoc_ExampeCode_Cake_Common_Xml); fileSystem.CreateFile("/Working/Cake.UnCommon.xml").SetContent(Resources.XmlDoc_ExampeCode_Cake_Common_Xml); FileSystem = fileSystem; Globber = Substitute.For <IGlobber>(); Globber.Match(Pattern, Arg.Any <GlobberSettings>()).Returns( new FilePath[] { "/Working/Cake.Common.xml", "/Working/Cake.UnCommon.xml" }); Log = Substitute.For <ICakeLog>(); }
public DupFinderRunnerFixture() { Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); ProcessRunner.Start( Arg.Any <FilePath>(), Arg.Do <ProcessSettings>(p => ProcessArguments = p.Arguments.Render()) ); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory = "/Working"; Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/dupfinder.exe").Returns(new[] { (FilePath)"/Working/tools/dupfinder.exe" }); FileSystem = Substitute.For <IFileSystem>(); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/dupfinder.exe")).Returns(true); }