Пример #1
0
        public void itShouldDeleteTargetZipOnUndoIfCommandSucceeded()
        {
            var zipExe        = "dummy7zip.exe";
            var targetZipFile = @"dummytargetZip.7z";
            var source1       = "file1.txt";
            var source2       = "file2.txt";
            var zip7FileCompressionCommand = new Zip7CompressCommand(zipExe, targetZipFile, source1, source2);

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy(0));
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            fakeFileSystem.AddFiles(source1);
            fakeFileSystem.AddFiles(source2);
            fakeFileSystem.AddFiles(zipExe);

            zip7FileCompressionCommand.Do();
            Assert.IsTrue(zip7FileCompressionCommand.DidCommandSucceed);

            fakeFileSystem.AddFiles(targetZipFile);

            zip7FileCompressionCommand.Undo();
            Assert.IsFalse(fakeFileSystem.FileExists(targetZipFile));
        }
Пример #2
0
        public void itShouldFailIfTargetZipAlreadyExists()
        {
            var targetZipFile = @"dummytargetZip.7z";
            var zip7FileCompressionCommand = new Zip7CompressCommand("dummy7zip.exe", targetZipFile, "file1.txt", "file2.txt");

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy());
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            fakeFileSystem.AddFiles(targetZipFile);

            zip7FileCompressionCommand.Do();

            Assert.IsFalse(zip7FileCompressionCommand.DidCommandSucceed);
        }
Пример #3
0
        public void itShouldInterpretNonZeroReturnValueFromFileCompressionStrategyAsFailure()
        {
            var targetZipFile = @"dummytargetZip.7z";
            var zip7FileCompressionCommand = new Zip7CompressCommand("dummy7zip.exe", targetZipFile, "file1.txt", "file2.txt");

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy(1));
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            zip7FileCompressionCommand.Do();

            Assert.IsFalse(zip7FileCompressionCommand.DidCommandSucceed);

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy(-1));
            Assert.IsFalse(zip7FileCompressionCommand.DidCommandSucceed);
        }
Пример #4
0
        public void itShouldFailIfOneOrMoreSourcesDoNotExist()
        {
            var zipExe        = "dummy7zip.exe";
            var targetZipFile = @"dummytargetZip.7z";
            var sourceFile1   = "file1.txt";
            var sourceFile2   = "file2.txt";
            var zip7FileCompressionCommand = new Zip7CompressCommand(zipExe, targetZipFile, sourceFile1, sourceFile2);

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy());
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            fakeFileSystem.AddFiles(zipExe);

            zip7FileCompressionCommand.Do();

            Assert.IsFalse(zip7FileCompressionCommand.DidCommandSucceed);
        }
Пример #5
0
        public void itShouldNotDeleteTargetZipOnUndoIfCommandFailed()
        {
            var targetZipFile = @"dummytargetZip.7z";
            var zip7FileCompressionCommand = new Zip7CompressCommand("dummy7zip.exe", targetZipFile, "file1.txt", "file2.txt");

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy(1));
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            zip7FileCompressionCommand.Do();
            Assert.IsFalse(zip7FileCompressionCommand.DidCommandSucceed);

            fakeFileSystem.AddFiles(targetZipFile);

            zip7FileCompressionCommand.Undo();

            Assert.IsTrue(fakeFileSystem.FileExists(targetZipFile));
        }
Пример #6
0
        public void itShouldInterpretZeroReturnValueFromFileCompressionStrategyAsSuccess()
        {
            var zipExe        = "dummy7zip.exe";
            var targetZipFile = @"dummytargetZip.7z";
            var source1       = "file1.txt";
            var source2       = "file2.txt";
            var zip7FileCompressionCommand = new Zip7CompressCommand(zipExe, targetZipFile, source1, source2);

            zip7FileCompressionCommand.setFileCompressionStrategy(new MockFileCompressionStrategy(0));
            var mockFileSysCommand = new MockFileSystemCommand();

            zip7FileCompressionCommand.setFileSystemCommandsStrategy(mockFileSysCommand);
            var fakeFileSystem = new FakeFileSystem(mockFileSysCommand);

            fakeFileSystem.AddFiles(zipExe);
            fakeFileSystem.AddFiles(source1);
            fakeFileSystem.AddFiles(source2);

            zip7FileCompressionCommand.Do();

            Assert.IsTrue(zip7FileCompressionCommand.DidCommandSucceed);
        }