예제 #1
0
        public void TestNewerFileNotOverwritten()
        {
            // Arrange
            ILoggerFactory loggerFactory = new LoggerFactory();
            ILogger        logger        = loggerFactory.CreateConsoleLogger();

            var mockFileDataMap = new Dictionary <string, MockFileData>()
            {
                { @"C:\myfile.txt", new MockFileData("Old data") },
                { @"D:\myfile.txt", new MockFileData("New data") }
            };
            IFileSystem  mockFileSystem = new MockFileSystem(mockFileDataMap);
            FileInfoBase oldFileInfo    = mockFileSystem.FileInfo.FromFileName(@"C:\myfile.txt");

            oldFileInfo.LastWriteTimeUtc = DateTime.UtcNow;
            FileInfoBase newFileInfo = mockFileSystem.FileInfo.FromFileName(@"D:\myfile.txt");

            newFileInfo.LastWriteTimeUtc = DateTime.UtcNow + new TimeSpan(0, 0, 0, 1);

            var application = new DriveBackup.Application(mockFileSystem, logger);

            // Act
            application.Run(@"C:\", @"D:\");

            // Assert
            Assert.IsTrue(mockFileSystem.File.Exists(@"D:\myfile.txt"));
            Assert.AreNotEqual(
                mockFileSystem.FileInfo.FromFileName(@"C:\myfile.txt").LastWriteTimeUtc,
                mockFileSystem.FileInfo.FromFileName(@"D:\myfile.txt").LastWriteTimeUtc
                );
            Assert.AreNotEqual(
                mockFileSystem.File.ReadAllText(@"C:\myfile.txt"),
                mockFileSystem.File.ReadAllText(@"D:\myfile.txt")
                );
        }
예제 #2
0
        public void TestFileCopy()
        {
            // Arrange
            ILoggerFactory loggerFactory = new LoggerFactory();
            ILogger        logger        = loggerFactory.CreateConsoleLogger();

            var mockFileDataMap = new Dictionary <string, MockFileData>()
            {
                { @"C:\myfile.txt", new MockFileData("Test data") }
            };
            IFileSystem mockFileSystem = new MockFileSystem(mockFileDataMap);

            var application = new DriveBackup.Application(mockFileSystem, logger);

            // Act
            application.Run(@"C:\", @"D:\");

            // Assert
            Assert.IsTrue(mockFileSystem.File.Exists(@"D:\myfile.txt"));
            Assert.AreEqual(
                mockFileSystem.File.ReadAllText(@"C:\myfile.txt"),
                mockFileSystem.File.ReadAllText(@"D:\myfile.txt")
                );
        }