Beispiel #1
0
            public void Should_Recursively_Copy_Files_And_Directory()
            {
                // 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
                // Directories should exist
                Assert.True(fileSystem.GetDirectory("/Temp2/Stuff").Exists);
                Assert.True(fileSystem.GetDirectory("/Temp2/Things").Exists);

                // Files should exist
                Assert.True(fileSystem.GetFile("/Temp2/Stuff/file1.txt").Exists);
                Assert.True(fileSystem.GetFile("/Temp2/Stuff/file2.txt").Exists);
                Assert.True(fileSystem.GetFile("/Temp2/Things/file1.txt").Exists);
            }
            public void WritesExpectedContentsToTheFile()
            {
                var sut = new TestListWriter(_fileSystem, _environment);

                sut.Write(_testListFile, _tests);

                var fileLines = _fileSystem.GetFile(_testListFile).ReadLines(Encoding.UTF8).ToList();

                Assert.AreEqual(_tests.Count, fileLines.Count, "Unexpected amount of lines in file");

                for (int i = 0; i < _tests.Count; i++)
                {
                    Assert.AreEqual(_tests[i], fileLines[i], "Unexpected test file content");
                }
            }
Beispiel #3
0
            public void Should_Zip_Provided_Files()
            {
                // 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.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.GetFiles("/**/*.txt"));

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

                Assert.True(archive.Entries.Count == 8);
                Assert.True(archive.GetEntry("Dir1/")?.Length == 0); // directory entries
                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);
            }
Beispiel #4
0
        private static string GetNuSpecContent(FakeFileSystem fileSystem, ProcessSettings process)
        {
            var args  = process.Arguments.Render();
            var parts = args.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var last  = parts.Last();
            var file  = fileSystem.GetFile(last.UnQuote());

            return(file.Exists ? file.GetTextContent() : null);
        }
Beispiel #5
0
            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("C:/Temp");
                var destinationPath = new DirectoryPath("C:/Temp2");

                // When
                DirectoryAliases.CopyDirectory(context, sourcePath, destinationPath);

                // Then
                Assert.True(fileSystem.GetFile("C:/Temp/file1.txt").Exists);
                Assert.True(fileSystem.GetFile("C:/Temp/file2.txt").Exists);
            }
        public void One_old_file_exist()
        {
            CreateLogFile(new DateTime(2008, 9, 10), "The content 1");
            CreateLogFile(new DateTime(2008, 9, 9), "The content 2");
            CreateLogFile(new DateTime(2008, 9, 8), "The content 3");
            CreateLogFile(new DateTime(2008, 9, 7), "The content 4");

            _trigger.Trig();

            _fileSystem.AssertFileList(
                LOG_DIR + "20080908-MyApp-MyLog.MyExt",
                LOG_DIR + "20080909-MyApp-MyLog.MyExt",
                LOG_DIR + "20080910-MyApp-MyLog.MyExt",
                LOG_DIR + "Archived_20080907.zip");

            _fileSystem.GetFile(LOG_DIR + "Archived_20080907.zip").ContentAsBase64
            .ShouldBe("UEsDBBQAAAAIAAAAJzkcxUfmEgAAABAAAAAaAAAAMjAwODA5MDctTXlBcHAtTXlMb2cuTXlFeHR7v3" +
                      "t/SEaqQnJ+XklqXomCCQBQSwECMwAUAAAACAAAACc5HMVH5hIAAAAQAAAAGgAAAAAAAAAAAAAAAA" +
                      "AAAAAAMjAwODA5MDctTXlBcHAtTXlMb2cuTXlFeHRQSwUGAAAAAAEAAQBIAAAASgAAAAAA");
        }
        public void Initialize_LogWriting_When_There_Is_A_Rolled_File_On_Disk()
        {
            var activeLogfilePath  = Path.Combine(LOG_DIR, $"{_currentTime:yyyyMMdd}-App-Log.txt");
            var rolled1LogfilePath = Path.Combine(LOG_DIR, $"{_currentTime:yyyyMMdd}-App-Log.txt.1");
            var rolled2LogfilePath = Path.Combine(LOG_DIR, $"{_currentTime:yyyyMMdd}-App-Log.txt.2");

            var activeLogfileContent = new string('1', ROLL_FILE_SIZE_THRESHOLD);
            var rolledLogfileContent = new string('2', ROLL_FILE_SIZE_THRESHOLD);

            _fileSystem.SetFileFromUtf8String(activeLogfilePath, activeLogfileContent);
            _fileSystem.SetFileFromUtf8String(rolled1LogfilePath, rolledLogfileContent);


            _fileWriterLogItemHandler.Add(new TestLogItem(_currentTime, "Hello, Log!"));


            _fileSystem.GetFile(activeLogfilePath).ContentAsUtf8String.ShouldContain("Hello, Log!");
            _fileSystem.GetFile(rolled1LogfilePath).ContentAsUtf8String.ShouldBe(activeLogfileContent);
            _fileSystem.GetFile(rolled2LogfilePath).ContentAsUtf8String.ShouldBe(rolledLogfileContent);
        }
Beispiel #8
0
        public void Write()
        {
            var fileSystem = new FakeFileSystem(DateTimeProvider.Singleton);
            var path       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.xml");

            fileSystem.SetFileFromUtf8String(path, ExpectedSettingsFile1);

            var settingsInternal = new SettingsInternal(fileSystem, DateTimeProvider.Singleton);

            settingsInternal.SetSetting("key", "value2");

            XmlTestSupport.GetComparableXml(fileSystem.GetFile(path).ContentAsUtf8String)
            .ShouldBe("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><node key=\"key\" value=\"value2\" /></root>");
        }
Beispiel #9
0
            public void Should_Zip_Provided_Files()
            {
                // Given
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var fileSystem  = new FakeFileSystem(environment);

                fileSystem.CreateFile("/Root/file.txt").SetContent("HelloWorld");
                var log    = Substitute.For <ICakeLog>();
                var zipper = new Zipper(fileSystem, environment, log);

                // When
                zipper.Zip("/Root", "/file.zip", new FilePath[] { "/Root/file.txt" });

                // Then
                Assert.True(fileSystem.GetFile("/file.zip").Exists);
            }
Beispiel #10
0
            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);
            }
Beispiel #11
0
        public bool ExistsFile(FilePath path)
        {
            var file = _fileSystem.GetFile(path.MakeAbsolute(Context.Environment));

            return(file != null);
        }