public void Should_Return_The_Latest_Release_Notes() { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Working/ReleaseNotes.md").SetContent("* 1.2.3 - Line 1\n* 1.2.5 Line 2\n* 1.2.4 Line 3"); context.FileSystem.Returns(fileSystem); context.Environment.Returns(environment); // When var result = context.ParseReleaseNotes("ReleaseNotes.md"); // Then Assert.Equal("1.2.5", result.Version.ToString()); }
public void Should_Be_Able_To_Resolve_Path_From_The_Tools_Directory() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); var globber = Substitute.For <IGlobber>(); globber.Match("./tools/**/NuGet.exe").Returns(p => new FilePath[] { "/root/tools/nuget.exe" }); fileSystem.CreateFile("/root/tools/nuget.exe"); var resolver = new NuGetToolResolver(fileSystem, environment, globber); // When var result = resolver.ResolvePath(); // Then Assert.Equal("/root/tools/nuget.exe", result.FullPath); }
public void Should_Read_Content_Of_File_And_Parse_It() { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Working/ReleaseNotes.md").SetContent("### New in 1.2.3"); context.FileSystem.Returns(fileSystem); context.Environment.Returns(environment); // When var result = context.ParseAllReleaseNotes("ReleaseNotes.md"); // Then Assert.Equal("1.2.3", result[0].Version.ToString()); }
public void Kill_Process_Returns_Minus1_ExitCode() { var environment = FakeEnvironment.CreateWindowsEnvironment(); var log = new FakeLog(); var runner = new AdvProcessRunner(environment, log); var settings = new AdvProcessSettings() .UseWorkingDirectory(Environment.CurrentDirectory) .WithArguments(args => args.Append("--sleep 5000 --exitcode 3")); using (var process = runner.Start(_appExe, settings)) { process.Kill(); process.GetExitCode().Should().Be(-1); } }
public void Should_Throw_If_Source_Directory_Does_Not_Exist() { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); context.FileSystem.Returns(new FakeFileSystem(environment)); var sourcePath = new DirectoryPath("C:/Temp"); var destinationPath = new DirectoryPath("C:/Temp2"); // When var result = Record.Exception(() => DirectoryAliases.CopyDirectory(context, sourcePath, destinationPath)); // Then Assert.IsType <DirectoryNotFoundException>(result); }
public void Should_Throw_If_File_Is_Not_Relative_To_Root() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/NotRoot/file.txt"); var log = Substitute.For <ICakeLog>(); var zipper = new Zipper(fileSystem, environment, log); // When var result = Record.Exception(() => zipper.Zip("/Root", "/file.zip", new FilePath[] { "/NotRoot/file.txt" })); // Then Assert.IsType <CakeException>(result); Assert.Equal("File '/NotRoot/file.txt' is not relative to root path '/Root'.", result?.Message); }
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.GetFiles(Pattern).Returns(new FilePath[] { "/Working/Cake.Common.xml", "/Working/Cake.UnCommon.xml" }); Log = Substitute.For <ICakeLog>(); }
public void Should_Use_The_Script_Directory_As_Root_For_Configuration_File() { // Given var fileSystem = Substitute.For <IFileSystem>(); var environment = FakeEnvironment.CreateUnixEnvironment(); var provider = new CakeConfigurationProvider(fileSystem, environment); var registry = new ContainerRegistrar(); var options = new CakeOptions { Script = "./foo/bar/build.cake" }; var module = new ConfigurationModule(provider, options); // When module.Register(registry); // Then fileSystem.Received(1).Exist(Arg.Is <FilePath>(f => f.FullPath == "/Working/foo/bar/cake.config")); }
public void Process_Can_Be_Killed() { var environment = FakeEnvironment.CreateWindowsEnvironment(); var log = new FakeLog(); var runner = new AdvProcessRunner(environment, log); var settings = new AdvProcessSettings() .UseWorkingDirectory(Environment.CurrentDirectory) .WithArguments(args => args.Append("--sleep 5000")); using (var process = runner.Start(_appExe, settings)) { process.Kill(); process.HasExited.Should().BeTrue(); } }
public void Process_With_Output_Not_Redirected_Will_Throw() { var environment = FakeEnvironment.CreateWindowsEnvironment(); var log = new FakeLog(); var runner = new AdvProcessRunner(environment, log); var settings = new AdvProcessSettings() .WithArguments(args => args.Append("--out OutputLine1")) .UseWorkingDirectory(Environment.CurrentDirectory) .SetRedirectStandardOutput(false); using (var process = runner.Start(_appExe, settings)) { process.Invoking(sut => sut.OutputDataReceived += (sender, args) => { }) .ShouldThrow <InvalidOperationException>(); } }
public ScriptProcessorFixture() { Environment = FakeEnvironment.CreateUnixEnvironment(); FileSystem = new FakeFileSystem(Environment); Log = Substitute.For <ICakeLog>(); Tools = Substitute.For <IToolLocator>(); Installer = Substitute.For <IPackageInstaller>(); Installer.CanInstall(Arg.Any <PackageReference>(), Arg.Any <PackageType>()).Returns(true); InstallPath = new DirectoryPath("/Working/Bin"); // Create the script analyzer result. var script = new ScriptInformation("/Working/build.cake"); script.Addins.Add(new PackageReference("custom:?package=addin")); script.Tools.Add(new PackageReference("custom:?package=tool")); Result = new ScriptAnalyzerResult(script, new List <string>()); }
public void Should_Return_Empty_If_Package_Directory_Does_Not_Exist() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); var log = Substitute.For <ICakeLog>(); var assemblyCompatibilityFilter = Substitute.For <INuGetAssemblyCompatibilityFilter>(); var locator = new NuGetPackageAssembliesLocator(fileSystem, log, assemblyCompatibilityFilter, environment); var addinDirectory = DirectoryPath.FromString("/NonExistentDir"); // When var result = locator.FindAssemblies(addinDirectory); // Then Assert.Empty(result); }
public NUnit3XmlReaderFixture() { NUnit2ResultPath = "/Working/nunit2results.xml"; NUnit3ResultPath = "/Working/nunit3results.xml"; NUnit3ResultDuplicateNamePath = "/Working/nunit3duplicateresults.xml"; NonExistantPath = "/Working/nonexistantpath.xml"; var environment = FakeEnvironment.CreateUnixEnvironment(); Environment = environment; var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile(NUnit2ResultPath.FullPath).SetContent(Resources.XmlTestResults_NUnit2); fileSystem.CreateFile(NUnit3ResultPath.FullPath).SetContent(Resources.XmlTestResults_NUnit3); fileSystem.CreateFile(NUnit3ResultDuplicateNamePath.FullPath).SetContent(Resources.XmlTestResults_NUnit3_DuplicateTestName); FileSystem = fileSystem; }
public void Should_Copy_Files() { // Given var context = Substitute.For<ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); CreateFileStructure(fileSystem); context.FileSystem.Returns(fileSystem); var sourcePath = new DirectoryPath("/Temp"); var destinationPath = new DirectoryPath("/Temp2"); // When DirectoryAliases.CopyDirectory(context, sourcePath, destinationPath); // Then Assert.True(fileSystem.GetFile("/Temp/file1.txt").Exists); Assert.True(fileSystem.GetFile("/Temp/file2.txt").Exists); }
public void Should_Add_Unknown_Arguments_To_Argument_List_Without_Script() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fakeFileSystem = new FakeFileSystem(environment); fakeFileSystem.CreateFile(new FilePath("build.cake")); var fixture = new ArgumentParserFixture { FileSystem = fakeFileSystem }; var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); // When var result = parser.Parse(new[] { "--unknown" }); // Then Assert.True(result.Arguments.ContainsKey("unknown")); }
public ScriptProcessorFixture() { Environment = FakeEnvironment.CreateUnixEnvironment(); FileSystem = new FakeFileSystem(Environment); Log = Substitute.For <ICakeLog>(); ToolLocator = Substitute.For <IToolLocator>(); Installer = Substitute.For <IPackageInstaller>(); Installer.CanInstall(Arg.Any <PackageReference>(), Arg.Any <PackageType>()).Returns(true); InstallPath = new DirectoryPath("/Working/Bin"); Addins = new List <PackageReference> { new PackageReference("custom:?package=addin") }; Tools = new List <PackageReference> { new PackageReference("custom:?package=tool") }; }
public void Should_Parse_Ini_With_Sections_Correctly() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Working/cake.config").SetContent(Resources.Ini_Configuration); var parser = new ConfigurationParser(fileSystem, environment); // When var result = parser.Read("/Working/cake.config"); // Then Assert.True(result.ContainsKey("Section1_Foo")); Assert.Equal("Bar", result["Section1_Foo"]); Assert.True(result.ContainsKey("Section2_Baz")); Assert.Equal("Qux", result["Section2_Baz"]); }
public void Should_Return_True_If_Absolute_Path_Exist() { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); environment.WorkingDirectory = "/Working/target"; var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Working/target/some file.txt"); context.FileSystem.Returns(fileSystem); context.Environment.Returns(environment); // When var result = FileAliases.FileExists(context, "/Working/target/some file.txt"); // Then Assert.True(result); }
public ProjectParserFixture() { ProjFilePath = "/Working/Cake.Sample.csproj"; Pattern = "/Working/Cake.*.csproj"; var environment = FakeEnvironment.CreateUnixEnvironment(); Environment = environment; var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile(ProjFilePath.FullPath).SetContent(Resources.Csproj_ProjectFile); fileSystem.CreateFile("/Working/Cake.Incomplete.csproj").SetContent(Resources.Csproj_IncompleteFile); FileSystem = fileSystem; Globber = Substitute.For <IGlobber>(); Globber.GetFiles(Pattern).Returns(new FilePath[] { "/Working/Cake.Sample.csproj", "/Working/Cake.Incomplete.csproj" }); Log = Substitute.For <ICakeLog>(); }
public CsvHelpersFixture(bool csvFileExists = true, bool peopleExists = true) { Settings = new CsvHelperSettings(); ClassMap = new PersonMap(); DictionaryMap = new Dictionary <string, string>() { { "Id", "EmployeeId" }, { "Name", "GivenName" } }; var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateDirectory("/Working"); if (csvFileExists) { var content = Resources.CsvHelper_CsvFile; var csvFile = fileSystem.CreateFile("/Working/people.csv").SetContent(content); CsvFilePath = csvFile.Path; } ResultPath = "/Working/people.csv"; if (peopleExists) { People = new List <Person> { new Person { Id = 1, Name = "Jane" }, new Person { Id = 2, Name = "Mal" } }; } FileSystem = fileSystem; Context = Substitute.For <ICakeContext>(); Context.FileSystem.Returns(FileSystem); Context.Environment.Returns(environment); }
public void Process_Should_Return_Correct_Exit_Code() { var environment = FakeEnvironment.CreateWindowsEnvironment(); var log = new FakeLog(); var runner = new AdvProcessRunner(environment, log); var settings = new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3")) .UseWorkingDirectory(Environment.CurrentDirectory); using (var process = runner.Start(_appExe, settings)) { process.WaitForExit(); var exitCode = process.GetExitCode(); Console.WriteLine(string.Join("\r\n", log.Messages)); exitCode.Should().Be(3); } }
public void Should_List_All_Directories_In_Directory() { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); CreateFileStructure(fileSystem); context.FileSystem.Returns(fileSystem); var directoryPath = new DirectoryPath("/Temp"); // When var directories = DirectoryAliases.GetSubDirectories(context, directoryPath); // Then Assert.Contains(directories, d => d.GetDirectoryName() == "Stuff"); Assert.Contains(directories, d => d.GetDirectoryName() == "Things"); Assert.DoesNotContain(directories, d => d.GetDirectoryName() == "file1.txt"); }
public void Should_Return_Size_If_Path_Exist(string workingDirectory, string filePath) { // Given var context = Substitute.For <ICakeContext>(); var environment = FakeEnvironment.CreateUnixEnvironment(); environment.WorkingDirectory = workingDirectory; var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile(filePath, new byte[] { 1, 2, 3, 4 }); context.FileSystem.Returns(fileSystem); context.Environment.Returns(environment); // When var result = FileAliases.FileSize(context, filePath); // Then Assert.Equal(result, 4); }
public NuGetPackageInstallerFixture() { Environment = FakeEnvironment.CreateUnixEnvironment(); FileSystem = new FakeFileSystem(Environment); ContentResolver = Substitute.For <INuGetContentResolver>(); Log = Substitute.For <ICakeLog>(); Config = Substitute.For <ICakeConfiguration>(); ToolResolver = Substitute.For <INuGetToolResolver>(); ToolResolver.ResolvePath().Returns(new FilePath("/Working/tools/nuget.exe")); Package = new PackageReference("nuget:https://myget.org/temp/?package=Cake.Foo&prerelease&version=1.2.3"); PackageType = PackageType.Addin; InstallPath = new DirectoryPath("./nuget"); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.When(p => p.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>())) .Do(info => FileSystem.CreateDirectory(InstallPath.Combine(Package.Package.ToLowerInvariant()).Combine(Package.Package))); }
private void PrepareWindowsFixture() { Environment = FakeEnvironment.CreateWindowsEnvironment(); FileSystem = new FakeFileSystem(Environment); // Directories FileSystem.CreateDirectory("C://Working"); FileSystem.CreateDirectory("C://Working/Foo"); FileSystem.CreateDirectory("C://Working/Foo/Bar"); FileSystem.CreateDirectory("C:"); FileSystem.CreateDirectory("C:/Program Files (x86)"); // Files FileSystem.CreateFile("C:/Working/Foo/Bar/Qux.c"); FileSystem.CreateFile("C:/Program Files (x86)/Foo.c"); FileSystem.CreateFile("C:/Working/Project.A.Test.dll"); FileSystem.CreateFile("C:/Working/Project.B.Test.dll"); FileSystem.CreateFile("C:/Working/Project.IntegrationTest.dll"); }
public void Zipped_File_Should_Contain_Correct_Content() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Root/Stuff/file.txt").SetContent("HelloWorld"); var log = Substitute.For <ICakeLog>(); var zipper = new Zipper(fileSystem, environment, log); zipper.Zip("/Root", "/file.zip", new FilePath[] { "/Root/Stuff/file.txt" }); // When var archive = new ZipArchive(fileSystem.GetFile("/file.zip").Open(FileMode.Open, FileAccess.Read, FileShare.Read)); var entry = archive.GetEntry("Stuff/file.txt"); // Then Assert.NotNull(entry); Assert.True(entry.Length == 10); }
public ScriptProcessorFixture( string scriptPath = "./build.cake", bool scriptExist = true, string scriptSource = "Console.WriteLine();") { ScriptPath = new FilePath(scriptPath); Source = scriptSource; Log = Substitute.For <ICakeLog>(); Globber = Substitute.For <IGlobber>(); Environment = FakeEnvironment.CreateUnixEnvironment(); FileSystem = new FakeFileSystem(Environment); if (scriptExist) { FileSystem.CreateFile(ScriptPath.MakeAbsolute(Environment)).SetContent(Source); } NuGetToolResolver = new NuGetToolResolver(FileSystem, Environment, Globber); }
public FakeCakeContext() { testsDir = new DirectoryPath(System.IO.Path.GetFullPath(AppContext.BaseDirectory)); var fileSystem = new FileSystem(); var environment = new FakeEnvironment(PlatformFamily.Windows); var globber = new Globber(fileSystem, environment); log = new FakeLog(); var args = new FakeCakeArguments(); var processRunner = new ProcessRunner(environment, log); var registry = new WindowsRegistry(); var toolRepo = new ToolRepository(environment); var config = new Core.Configuration.CakeConfigurationProvider(fileSystem, environment).CreateConfiguration(testsDir, new Dictionary <string, string> ()); var toolResolutionStrategy = new ToolResolutionStrategy(fileSystem, environment, globber, config); var toolLocator = new ToolLocator(environment, toolRepo, toolResolutionStrategy); context = new CakeContext(fileSystem, environment, globber, log, args, processRunner, registry, toolLocator); context.Environment.WorkingDirectory = testsDir; }
public void Should_Create_Text_Transformation_From_Disc_Template() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateFile("/Working/template.txt").SetContent("Hello World"); var context = Substitute.For <ICakeContext>(); context.FileSystem.Returns(fileSystem); context.Environment.Returns(environment); // When var result = TextTransformationAliases.TransformTextFile( context, "./template.txt", "{", "}"); // Then Assert.Equal("Hello World", result.ToString()); }
public FtpClientFixture(bool fileToUploadExists = true) { var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); fileSystem.CreateDirectory("/Working"); if (fileToUploadExists) { var fileToUpload = fileSystem.CreateFile("/Working/upload.txt").SetContent("This file is for uploading."); FileToUpload = fileToUpload.Path; } Log = Substitute.For <ICakeLog>(); FtpService = Substitute.For <IFtpService>(); FileSystem = fileSystem; Environment = environment; Username = "******"; Password = "******"; ServerUri = new Uri("ftp://my.server.com/test.html"); }