Ejemplo n.º 1
0
        private static FakeFileSystem CreateFileSystem(ICakeEnvironment environment)
        {
            var fileSystem = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("/Temp");
            fileSystem.CreateDirectory("/Temp/HasDirectories");
            fileSystem.CreateDirectory("/Temp/HasDirectories/A");
            fileSystem.CreateDirectory("/Temp/HasFiles");
            fileSystem.CreateDirectory("/Temp/Hello");
            fileSystem.CreateDirectory("/Temp/Hello/Empty");
            fileSystem.CreateDirectory("/Temp/Hello/More/Empty");
            fileSystem.CreateDirectory("/Temp/Hello/World");
            fileSystem.CreateDirectory("/Temp/Goodbye");
            fileSystem.CreateDirectory("/Temp/Hello/Hidden").Hide();
            fileSystem.CreateFile("/Presentation.ppt");
            fileSystem.CreateFile("/Budget.xlsx");
            fileSystem.CreateFile("/Text.txt");
            fileSystem.CreateFile("/Temp");
            fileSystem.CreateFile("/Temp/Hello/Document.txt");
            fileSystem.CreateFile("/Temp/Hello/World/Text.txt");
            fileSystem.CreateFile("/Temp/Hello/World/Picture.png");
            fileSystem.CreateFile("/Temp/Hello/Hidden.txt").Hide();
            fileSystem.CreateFile("/Temp/Goodbye/OtherText.txt");
            fileSystem.CreateFile("/Temp/Goodbye/OtherPicture.png");
            fileSystem.CreateFile("/Temp/HasFiles/A.txt");
            return(fileSystem);
        }
Ejemplo n.º 2
0
        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");
            FileSystem.CreateFile("C:/Tools & Services/MyTool.dll");
            FileSystem.CreateFile("C:/Tools + Services/MyTool.dll");
            FileSystem.CreateFile("C:/Some %2F Directory/MyTool.dll");
            FileSystem.CreateFile("C:/Some ! Directory/MyTool.dll");
            FileSystem.CreateFile("C:/Some@Directory/MyTool.dll");

            FileSystem.CreateFile("C:/Working/foobar.rs");
            FileSystem.CreateFile("C:/Working/foobaz.rs");
            FileSystem.CreateFile("C:/Working/foobax.rs");
        }
Ejemplo n.º 3
0
        private void PrepareUnixFixture()
        {
            Environment = FakeEnvironment.CreateUnixEnvironment();
            FileSystem  = new FakeFileSystem(Environment);

            // Directories
            FileSystem.CreateDirectory("/Working");
            FileSystem.CreateDirectory("/Working/Foo");
            FileSystem.CreateDirectory("/Working/Foo/Bar");
            FileSystem.CreateDirectory("/Working/Bar");
            FileSystem.CreateDirectory("/Foo/Bar");
            FileSystem.CreateDirectory("/Foo (Bar)");
            FileSystem.CreateDirectory("/Foo@Bar/");
            FileSystem.CreateDirectory("/嵌套");
            FileSystem.CreateDirectory("/嵌套/目录");

            // Files
            FileSystem.CreateFile("/Working/Foo/Bar/Qux.c");
            FileSystem.CreateFile("/Working/Foo/Bar/Qex.c");
            FileSystem.CreateFile("/Working/Foo/Bar/Qux.h");
            FileSystem.CreateFile("/Working/Foo/Baz/Qux.c");
            FileSystem.CreateFile("/Working/Foo/Bar/Baz/Qux.c");
            FileSystem.CreateFile("/Working/Bar/Qux.c");
            FileSystem.CreateFile("/Working/Bar/Qux.h");
            FileSystem.CreateFile("/Working/Foo.Bar.Test.dll");
            FileSystem.CreateFile("/Working/Bar.Qux.Test.dll");
            FileSystem.CreateFile("/Working/Quz.FooTest.dll");
            FileSystem.CreateFile("/Foo/Bar.baz");
            FileSystem.CreateFile("/Foo (Bar)/Baz.c");
            FileSystem.CreateFile("/Foo@Bar/Baz.c");
            FileSystem.CreateFile("/嵌套/目录/文件.延期");
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        public XmlPeekAliasesFixture(bool xmlExists = true, bool xmlWithDtd = false, bool suppressWarning = false)
        {
            Settings = new XmlPeekSettings {
                SuppressWarning = suppressWarning
            };

            var environment = FakeEnvironment.CreateUnixEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("/Working");

            if (xmlExists)
            {
                string content = xmlWithDtd ? Resources.XmlPeek_Xml_Dtd : Resources.XmlPeek_Xml;
                var    xmlFile = fileSystem.CreateFile("/Working/web.config").SetContent(content);
                XmlPath = xmlFile.Path;
            }

            FileSystem = fileSystem;
            FakeLog    = new FakeLog();

            Context = Substitute.For <ICakeContext>();
            Context.FileSystem.Returns(FileSystem);
            Context.Environment.Returns(environment);
            Context.Log.Returns(FakeLog);
        }
            public void Should_Return_Empty_If_No_Package_Assemblies_Are_Found()
            {
                // Given
                var targetFramework = new FrameworkName(".NETFramework,Version=v4.5");
                var environment     = FakeEnvironment.CreateUnixEnvironment();

                environment.SetTargetFramework(targetFramework);

                var log = Substitute.For <ICakeLog>();

                var fileSystem = new FakeFileSystem(environment);

                var packageDirectory = fileSystem.CreateDirectory("/Working/addins/MyPackage");

                var assemblyCompatibilityFilter = Substitute.For <INuGetAssemblyCompatibilityFilter>();

                assemblyCompatibilityFilter.FilterCompatibleAssemblies(targetFramework, Arg.Any <IEnumerable <FilePath> >())
                .Returns(ci => ci[1]);

                var locator = new NuGetPackageAssembliesLocator(fileSystem, log, assemblyCompatibilityFilter, environment);

                // When
                var result = locator.FindAssemblies(packageDirectory.Path);

                // Then
                Assert.Empty(result);
                log.Received()
                .Write(Verbosity.Minimal, LogLevel.Warning, "Unable to locate any assemblies under {0}",
                       packageDirectory.Path.FullPath);
            }
Ejemplo n.º 7
0
        public XmlTransformationFixture(bool xmlExists = true, bool xslExists = true, bool resultExist = false)
        {
            Settings = new XmlTransformationSettings();

            var environment = FakeEnvironment.CreateUnixEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("/Working");

            if (xmlExists)
            {
                var xmlFile = fileSystem.CreateFile("/Working/breakfast_menu.xml").SetContent(Resources.XmlTransformation_Xml);
                XmlPath = xmlFile.Path;
            }

            if (xslExists)
            {
                var xslFile = fileSystem.CreateFile("/Working/breakfast_menu.xsl").SetContent(Resources.XmlTransformation_Xsl);
                XslPath = xslFile.Path;
            }

            if (resultExist)
            {
                var resultFile = fileSystem.CreateFile("/Working/breakfast_menu.htm").SetContent(Resources.XmlTransformation_Htm);
                ResultPath = resultFile.Path;
            }
            else
            {
                ResultPath = "/Working/breakfast_menu.htm";
            }

            FileSystem = fileSystem;
        }
Ejemplo n.º 8
0
        public AssemblyInfoParserFixture(string version              = "1.2.3.4",
                                         string fileVersion          = "4.3.2.1",
                                         string informationalVersion = "4.2.3.1",
                                         bool createAssemblyInfo     = true)
        {
            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory(Environment.WorkingDirectory);

            if (createAssemblyInfo)
            {
                // Set the versions.
                var settings = new AssemblyInfoSettings();
                if (version != null)
                {
                    settings.Version = version;
                }
                if (fileVersion != null)
                {
                    settings.FileVersion = fileVersion;
                }
                if (informationalVersion != null)
                {
                    settings.InformationalVersion = informationalVersion;
                }

                // Create the assembly info.
                var creator = new AssemblyInfoCreator(FileSystem, Environment, Substitute.For <ICakeLog>());
                creator.Create("./output.cs", settings);
            }
        }
        public XdtTransformationFixture(bool sourceFileExists = true, bool transformFileExists = true, bool targetFileExists = false)
        {
            var environment = FakeEnvironment.CreateUnixEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("/Working");

            if (sourceFileExists)
            {
                var sourceFile = fileSystem.CreateFile("/Working/web.config").SetContent(Resources.XdtTransformation_SourceFile);
                SourceFile = sourceFile.Path;
            }

            if (transformFileExists)
            {
                var transformFile = fileSystem.CreateFile("/Working/web.release.config").SetContent(Resources.XdtTramsformation_TransformFile);
                TransformFile = transformFile.Path;
            }

            if (targetFileExists)
            {
                var targetFile = fileSystem.CreateFile("/Working/transformed.config").SetContent(Resources.XdtTransformation_TargetFile);
                TargetFile = targetFile.Path;
            }
            else
            {
                TargetFile = "/Working/transformed.config";
            }

            FileSystem = fileSystem;
        }
 public GitHubActionsCommandsFixture()
 {
     GitHubActionsInfoFixture = new GitHubActionsInfoFixture();
     FileSystem = new FakeFileSystem(GitHubActionsInfoFixture.Environment);
     FileSystem.CreateDirectory("/opt");
     Environment = GitHubActionsInfoFixture.Environment;
 }
Ejemplo n.º 11
0
        public TextTransformationFixture()
        {
            Enviroment = Substitute.For <ICakeEnvironment>();
            Enviroment.WorkingDirectory.Returns("/Working");

            FileSystem = new FakeFileSystem(Enviroment);
            FileSystem.CreateDirectory(Enviroment.WorkingDirectory);

            TransformationTemplate = Substitute.For <ITextTransformationTemplate>();
        }
Ejemplo n.º 12
0
        public AssemblyInfoManagerFixture()
        {
            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");
            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory(Environment.WorkingDirectory);

            // Set fixture values.
            Path = new FilePath("./output.cs");
            CreateAssemblyInfo = true;
        }
Ejemplo n.º 13
0
        public CakeHostFixture()
        {
            Host        = new CakeHost();
            Environment = FakeEnvironment.CreateUnixEnvironment();
            Console     = new FakeConsole();
            Log         = Substitute.For <ICakeLog>();
            Installer   = Substitute.For <IToolInstaller>();

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory("/Working");
        }
Ejemplo n.º 14
0
            private static void CreateFileStructure(FakeFileSystem ffs)
            {
                Action <string> dir  = path => ffs.CreateDirectory(path);
                Action <string> file = path => ffs.CreateFile(path);

                dir("/Temp");
                {
                    file("/Temp/file1.txt");
                    dir("/Temp/Stuff");
                    dir("/Temp/Things");
                }
            }
Ejemplo n.º 15
0
        public ClickTwiceFixture(ITestOutputHelper output)
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();

            Environment = environment;
            var fileSystem = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("./artifacts");
            //fileSystem.CreateFile(PackageFilePath.FullPath).SetContent(SamplePackageJson);
            FileSystem = fileSystem;
            Logger     = new UnitTestLogger(output);
        }
Ejemplo n.º 16
0
        internal void GivenDirectoryExistsInToolsPath(string name)
        {
            var toolsFolder = FileSystem.GetDirectory(
                Configuration.GetToolPath(Environment.WorkingDirectory, Environment));

            var target = toolsFolder.Path.Combine(name);

            if (!FileSystem.Exist(target))
            {
                FileSystem.CreateDirectory(target);
            }
        }
Ejemplo n.º 17
0
        public AssemblyInfoFixture()
        {
            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns(new DirectoryPath("/Working"));

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory(Environment.WorkingDirectory);

            Log      = Substitute.For <ICakeLog>();
            Settings = new AssemblyInfoSettings();
            Path     = "AssemblyInfo.cs";
        }
Ejemplo n.º 18
0
        public GlobberFixture(bool isFileSystemCaseSensitive)
        {
            Environment = Substitute.For <ICakeEnvironment>();
            Environment.IsUnix().Returns(isFileSystemCaseSensitive);
            Environment.WorkingDirectory.Returns("/Temp");

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory("/Temp");
            FileSystem.CreateDirectory("/Temp/Hello");
            FileSystem.CreateDirectory("/Temp/Hello/World");
            FileSystem.CreateDirectory("/Temp/Goodbye");
            FileSystem.CreateFile("/Presentation.ppt");
            FileSystem.CreateFile("/Budget.xlsx");
            FileSystem.CreateFile("/Text.txt");
            FileSystem.CreateFile("/Temp");
            FileSystem.CreateFile("/Temp/Hello/World/Text.txt");
            FileSystem.CreateFile("/Temp/Hello/World/Picture.png");
            FileSystem.CreateFile("/Temp/Goodbye/OtherText.txt");
            FileSystem.CreateFile("/Temp/Goodbye/OtherPicture.png");
            FileSystem.CreateFile("/Working/Text.txt");
            FileSystem.CreateFile("C:/Temp/Hello/World/Text.txt");
        }
Ejemplo n.º 19
0
        public static GlobberFixture UnixLike()
        {
            var environment = FakeEnvironment.CreateUnixEnvironment();
            var filesystem  = new FakeFileSystem(environment);

            // Directories
            filesystem.CreateDirectory("/RootDir");
            filesystem.CreateDirectory("/Working");
            filesystem.CreateDirectory("/Working/Foo");
            filesystem.CreateDirectory("/Working/Foo/Bar");
            filesystem.CreateDirectory("/Working/Bar");
            filesystem.CreateDirectory("/Foo/Bar");
            filesystem.CreateDirectory("/Foo (Bar)");
            filesystem.CreateDirectory("/Foo@Bar/");
            filesystem.CreateDirectory("/嵌套");
            filesystem.CreateDirectory("/嵌套/目录");

            // Files
            filesystem.CreateFile("/RootFile.sh");
            filesystem.CreateFile("/Working/Foo/Bar/Qux.c");
            filesystem.CreateFile("/Working/Foo/Bar/Qex.c");
            filesystem.CreateFile("/Working/Foo/Bar/Qux.h");
            filesystem.CreateFile("/Working/Foo/Baz/Qux.c");
            filesystem.CreateFile("/Working/Foo/Bar/Baz/Qux.c");
            filesystem.CreateFile("/Working/Bar/Qux.c");
            filesystem.CreateFile("/Working/Bar/Qux.h");
            filesystem.CreateFile("/Working/Foo.Bar.Test.dll");
            filesystem.CreateFile("/Working/Bar.Qux.Test.dll");
            filesystem.CreateFile("/Working/Quz.FooTest.dll");
            filesystem.CreateFile("/Foo/Bar.baz");
            filesystem.CreateFile("/Foo (Bar)/Baz.c");
            filesystem.CreateFile("/Foo@Bar/Baz.c");
            filesystem.CreateFile("/嵌套/目录/文件.延期");
            filesystem.CreateFile("/Working/foobar.rs");
            filesystem.CreateFile("/Working/foobaz.rs");
            filesystem.CreateFile("/Working/foobax.rs");

            return(new GlobberFixture(filesystem, environment));
        }
        public ProcessRunnerFixture(bool windows = false)
        {
            var environment = windows
                ? FakeEnvironment.CreateWindowsEnvironment()
                : FakeEnvironment.CreateUnixEnvironment();

            environment.WorkingDirectory = "/Working";

            Environment     = environment;
            FileSystem      = new FakeFileSystem(Environment);
            Log             = Substitute.For <ICakeLog>();
            Tools           = Substitute.For <IToolLocator>();
            Configuration   = Substitute.For <ICakeConfiguration>();
            ProcessFilePath = "/Program Files/Cake.exe";
            ProcessSettings = new ProcessSettings();

            FileSystem.CreateDirectory("/Working");
            FileSystem.CreateDirectory("/Program Files");
            FileSystem.CreateFile("/Program Files/Cake.exe", ClrAssemblyData);
            MonoFile = FileSystem.CreateFile("/Program Files/mono.exe", NonClrAssemblyData);

            Tools.Resolve("mono").Returns(file => MonoFile.Exists ? MonoFile.Path : null);
        }
        public CakeHostBuilderFixture()
        {
            Builder     = new CakeHostBuilder();
            Environment = FakeEnvironment.CreateUnixEnvironment();

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory("/Working");

            Log       = Substitute.For <ICakeLog>();
            Data      = Substitute.For <ICakeDataService>();
            Engine    = new CakeEngine(Data, Log);
            Installer = Substitute.For <IToolInstaller>();
            Options   = new CakeHostOptions();
        }
Ejemplo n.º 22
0
            public void Should_Return_True_If_Directory_Exist()
            {
                // Given
                var context = Substitute.For<ICakeContext>();
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var fileSystem = new FakeFileSystem(environment);
                fileSystem.CreateDirectory("some path");
                context.FileSystem.Returns(fileSystem);

                // When
                var result = DirectoryAliases.DirectoryExists(context, "some path");

                // Then
                Assert.True(result);
            }
Ejemplo n.º 23
0
        private MSBuildRunnerFixture(bool is64BitOperativeSystem, bool msBuildFileExist, IEnumerable <DirectoryPath> existingMSBuildPaths)
        {
            Process = Substitute.For <IProcess>();

            ProcessRunner = Substitute.For <IProcessRunner>();
            ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process);

            Globber = Substitute.For <IGlobber>();

            Environment = Substitute.For <ICakeEnvironment>();
            Environment.Is64BitOperativeSystem().Returns(is64BitOperativeSystem);
            Environment.GetSpecialPath(SpecialPath.ProgramFilesX86).Returns("/Program86");
            Environment.GetSpecialPath(SpecialPath.Windows).Returns("/Windows");
            Environment.IsUnix().Returns(true);
            Environment.WorkingDirectory.Returns("/Working");

            Solution             = new FilePath("./src/Solution.sln");
            Settings             = new MSBuildSettings();
            Settings.ToolVersion = MSBuildToolVersion.VS2013;

            if (existingMSBuildPaths != null)
            {
                // Add all existing MSBuild tool paths.
                var fileSystem = new FakeFileSystem(Environment);
                FileSystem = fileSystem;
                foreach (var existingPath in existingMSBuildPaths)
                {
                    fileSystem.CreateDirectory(existingPath);
                    fileSystem.CreateFile(existingPath.GetFilePath("MSBuild.exe"));
                }
            }
            else
            {
                FileSystem = Substitute.For <IFileSystem>();
                FileSystem.GetFile(
                    Arg.Is <FilePath>(p => p.FullPath.EndsWith("MSBuild.exe", System.StringComparison.Ordinal)))
                .Returns(c =>
                {
                    // All requested files exist.
                    var file = Substitute.For <IFile>();
                    file.Exists.Returns(msBuildFileExist);
                    file.Path.Returns(c.Arg <FilePath>());
                    return(file);
                });
            }
        }
        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)));
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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");
        }
Ejemplo n.º 27
0
        public XmlPeekAliasesFixture(bool xmlExists = true)
        {
            Settings = new XmlPeekSettings();

            var environment = FakeEnvironment.CreateUnixEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("/Working");

            if (xmlExists)
            {
                var xmlFile = fileSystem.CreateFile("/Working/web.config").SetContent(Resources.XmlPeek_Xml);
                XmlPath = xmlFile.Path;
            }

            FileSystem = fileSystem;

            Context = Substitute.For <ICakeContext>();
            Context.FileSystem.Returns(FileSystem);
            Context.Environment.Returns(environment);
        }
Ejemplo n.º 28
0
            public void Should_Be_Able_To_Resolve_Path_Via_Environment_Path_Variable()
            {
                // Given
                var globber     = Substitute.For <IGlobber>();
                var environment = Substitute.For <ICakeEnvironment>();

                environment.WorkingDirectory.Returns("/Working");
                environment.IsUnix().Returns(false);
                environment.GetEnvironmentVariable("path").Returns("/temp;stuff/programs;/programs");
                var fileSystem = new FakeFileSystem(environment);

                fileSystem.CreateDirectory("stuff/programs");
                fileSystem.CreateFile("stuff/programs/nuget.exe");
                var resolver = new NuGetToolResolver(fileSystem, environment, globber);

                // When
                var result = resolver.ResolvePath();

                // Then
                Assert.Equal("stuff/programs/nuget.exe", result.FullPath);
            }
            public void Should_Return_Compatible_Packages_For_NuGet_Compliant_Package()
            {
                // Given
                var targetFramework = new FrameworkName(".NETFramework,Version=v4.5");
                var environment     = FakeEnvironment.CreateUnixEnvironment();

                environment.SetTargetFramework(targetFramework);

                var log = Substitute.For <ICakeLog>();

                var fileSystem = new FakeFileSystem(environment);

                var packageDirectory = fileSystem.CreateDirectory("/Working/addins/MyPackage");

                fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net40/myassembly1.dll"));
                fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net40/myassembly2.dll"));
                var compatibleDll1 = fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net45/myassembly1.dll"));
                var compatibleDll2 = fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net45/myassembly2.dll"));

                fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net452/myassembly1.dll"));
                fileSystem.CreateFile(packageDirectory.Path.CombineWithFilePath("lib/net452/myassembly2.dll"));

                var assemblyCompatibilityFilter = Substitute.For <INuGetAssemblyCompatibilityFilter>();

                assemblyCompatibilityFilter.FilterCompatibleAssemblies(targetFramework, Arg.Any <IEnumerable <FilePath> >())
                .Returns(ci => new FilePath[] { "lib/net45/myassembly1.dll", "lib/net45/myassembly2.dll" });

                var locator = new NuGetPackageAssembliesLocator(fileSystem, log, assemblyCompatibilityFilter, environment);

                // When
                var result = locator.FindAssemblies(packageDirectory.Path);

                // Then
                Assert.Equal(new List <IFile> {
                    compatibleDll1, compatibleDll2
                }.AsReadOnly(), result);
            }
Ejemplo n.º 30
0
            public void Should_Zip_Provided_Directory()
            {
                // Given
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var fileSystem = new FakeFileSystem(environment);
                var globber = new Globber(fileSystem, environment);
                var context = new CakeContextFixture {
                    Environment = environment, FileSystem = fileSystem, Globber = globber
                }.CreateContext();

                fileSystem.CreateDirectory("/Dir0"); // empty directory
                fileSystem.CreateFile("/File1.txt").SetContent("1");
                fileSystem.CreateFile("/Dir1/File2.txt").SetContent("22");
                fileSystem.CreateFile("/Dir2/File3.txt").SetContent("333");
                fileSystem.CreateFile("/Dir2/Dir3/File4.txt").SetContent("4444");
                fileSystem.CreateFile("/Dir2/Dir3/File5.txt").SetContent("55555");
                var log    = Substitute.For <ICakeLog>();
                var zipper = new Zipper(fileSystem, environment, log);

                // When
                zipper.Zip("/", "/Root.zip", context.GetPaths("/**/*"));

                // Then
                var archive = new ZipArchive(fileSystem.GetFile("/Root.zip").Open(FileMode.Open, FileAccess.Read, FileShare.Read));

                Assert.True(archive.Entries.Count == 9);
                Assert.True(archive.GetEntry("Dir0/")?.Length == 0); // directory entries; includes empty directories
                Assert.True(archive.GetEntry("Dir1/")?.Length == 0);
                Assert.True(archive.GetEntry("Dir2/")?.Length == 0);
                Assert.True(archive.GetEntry("Dir2/Dir3/")?.Length == 0);
                Assert.True(archive.GetEntry("File1.txt")?.Length == 1); // file entries
                Assert.True(archive.GetEntry("Dir1/File2.txt")?.Length == 2);
                Assert.True(archive.GetEntry("Dir2/File3.txt")?.Length == 3);
                Assert.True(archive.GetEntry("Dir2/Dir3/File4.txt")?.Length == 4);
                Assert.True(archive.GetEntry("Dir2/Dir3/File5.txt")?.Length == 5);
            }