public void TestCleanByPattern() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddDirectory(@"C:\Source"); fileSystem.AddFile(@"C:\Target\File.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File.doc", new MockFileData("Data")); // Run the test. Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source", "*.txt"); // Check the clean has worked properly. Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\File.txt")); Assert.IsTrue(fileSystem.File.Exists(@"C:\Target\File.doc")); }
public void TestPushDirectoryByPattern() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Source\File.doc", new MockFileData("Data")); // Run the test. Pusher.PushDirectoryResult result = Pusher.PushDirectory(fileSystem, @"C:\Source", @"C:\Target", "*.txt"); // Check the results Assert.AreEqual("Data", fileSystem.File.ReadAllText(@"C:\Target\File.txt")); Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\File.doc")); }
public void ParsePropertiesFile_RealFile_Parsed() { var resource = new EmbeddedResourceReader().GetResource("PropertiesFile.txt"); // Arrange var mockFileSystem = new MockFileSystem(); var propertiesFile = @"C:\BuildAgent\temp\buildTmp\teamcity.build322130465402584030.properties"; mockFileSystem.AddFile(propertiesFile, resource); var propertiesFileParser = new PropertiesFileParser(mockFileSystem); // Act var dictionary = propertiesFileParser.ParsePropertiesFile(propertiesFile); // Assert dictionary["agent.home.dir"].Should().Be(@"C:\BuildAgent"); dictionary["agent.name"].Should().Be(@"BUILDS8"); dictionary["agent.ownPort"].Should().Be(@"9090"); dictionary["agent.work.dir"].Should().Be(@"C:\BuildAgent\work"); dictionary["build.number"].Should().Be(@"4"); dictionary["FxCopRoot"].Should() .Be(@"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop"); dictionary["teamcity.agent.dotnet.agent_url"].Should().Be(@"http://*****:*****@"TeamCityBuildId=781682"); }
public void Setup() { _mocker = new AutoMoqer(); var mockFileSystem = new MockFileSystem(); _mocker.SetInstance<IFileSystem>(mockFileSystem); // GetMock of the abstract class before create to prevent automoq bugs _mocker.GetMock<FileSystemWatcherBase>(); _instance = _mocker.Create<DirectoryWatcher>(); // Mocked files var content = new byte[] {1, 1, 1}; _expectedFileLength = content.Length; _expectedWriteDate = DateTime.Now.ToUniversalTime(); var nameWithPath = mockFileSystem.Path.Combine(Path, FileName); mockFileSystem.AddFile(nameWithPath, new MockFileData(content) { LastWriteTime = _expectedWriteDate }); _trackedFile = new TrackedFile(); _mocker.GetMock<ITrackedFileStore>() .Setup(x => x.GetTrackedFileByFullPath(nameWithPath)) .Returns(_trackedFile); }
public void TestCleanByAttributes() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddDirectory(@"C:\Source"); fileSystem.AddFile(@"C:\Target\File1.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File2.txt", new MockFileData("Data")); fileSystem.File.SetAttributes(@"C:\Target\File1.txt", FileAttributes.Normal); fileSystem.File.SetAttributes(@"C:\Target\File2.txt", FileAttributes.Hidden); // Run the test. Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source", "*.*", FileAttributes.Normal); // Check the results Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\File1.txt")); Assert.IsTrue(fileSystem.File.Exists(@"C:\Target\File2.txt")); }
public ConfigurationTests() { var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"C:\WebSite\_config.yml", new MockFileData(SampleConfig)); _sut = new Configuration(fileSystem, @"C:\WebSite"); _sut.ReadFromFile(); }
public void ParseChangedFiles_FileWithUnknownStatus_ExceptionThrown() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile("changes.txt", new MockFileData(@"VCE Drivers/Cisco NxOS/Debug.tsdrv:UNKNOWN:136346")); var changedFilesParser = new ChangedFilesParser(fileSystem); // Act Action action = () => changedFilesParser.ParseChangedFiles("changes.txt"); // Assert action.ShouldThrow<ArgumentException>().WithMessage("Could not parse FileStatusChange: UNKNOWN"); }
public void TestCleanRecursive() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddDirectory(@"C:\Source\SubDirectory"); fileSystem.AddFile(@"C:\Target\SubDirectory\File.txt", new MockFileData("Data")); // Run the test. Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source"); // Check the results Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\SubDirectory\File.txt")); }
public void ParseChangedFiles_FileWithOneFileRemoved_Parsed() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile("changes.txt", new MockFileData(@"VCE Drivers/Cisco NxOS/Debug.tsdrv:REMOVED:136346")); var changedFilesParser = new ChangedFilesParser(fileSystem); // Act var changedFiles = changedFilesParser.ParseChangedFiles("changes.txt"); // Assert var changedFile = changedFiles.Single(); changedFile.RelativeFilePath.Should().Be(@"VCE Drivers\Cisco NxOS\Debug.tsdrv"); changedFile.ChangeStatus.Should().Be(FileChangeStatus.Removed); changedFile.ChangesetNumber.Should().Be("136346"); }
public void ParsePropertiesFile_File_Parsed() { // Arrange var mockFileSystem = new MockFileSystem(); var propertiesFile = @"C:\BuildAgent\temp\buildTmp\teamcity.build322130465402584030.properties"; mockFileSystem.AddFile(propertiesFile, @"#TeamCity build properties without 'system.' prefix #Sun Nov 01 14:40:00 IST 2015 agent.home.dir=C\:\\BuildAgent "); var fileParser = new PropertiesFileParser(mockFileSystem); // Act var dictionary = fileParser.ParsePropertiesFile(propertiesFile); // Assert dictionary["agent.home.dir"].Should().Be(@"C:\BuildAgent"); }
public void TestPushResult() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File1.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Source\File2.txt", new MockFileData("NewData")); fileSystem.AddFile(@"C:\Source\File3.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File2.txt", new MockFileData("OldData")); fileSystem.AddFile(@"C:\Target\File3.txt", new MockFileData("Data")); //fileSystem.AddDirectory(@"C:\Source\SubDirectory"); //fileSystem.AddDirectory(@"C:\Target\SubDirectory"); // Run the test. var result = Pusher.PushDirectory(fileSystem, @"C:\Source", @"C:\Target"); // Check the result. Assert.AreEqual(1, result.CreatedFiles.Count); Assert.AreEqual("File1.txt", result.CreatedFiles[0]); Assert.AreEqual(1, result.UpdatedFiles.Count); Assert.AreEqual("File2.txt", result.UpdatedFiles[0]); Assert.AreEqual(1, result.VerifiedFiles.Count); Assert.AreEqual("File3.txt", result.VerifiedFiles[0]); Assert.AreEqual(0, result.FailedEntries.Count); // TODO:: figure out how to spoof a fail an entry? //Assert.AreEqual(1, result.DirectoryResults.Count); }
public void TestPushNewFile() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File.txt", new MockFileData("Data")); fileSystem.File.SetAttributes(@"C:\Source\File.txt", FileAttributes.Archive); Pusher.PushEntryResult result = Pusher.PushFile(fileSystem, @"C:\Source\File.txt", @"C:\Target\File.txt"); Assert.AreEqual("Data", fileSystem.File.ReadAllText(@"C:\Target\File.txt")); Assert.AreEqual(FileAttributes.Archive, fileSystem.File.GetAttributes(@"C:\Target\File.txt")); }
public void TestPushFileWhenTargetIsNull() { var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File.txt", new MockFileData("Data")); try { Pusher.PushFile(fileSystem, @"C:\Source\File.txt", null); Assert.Fail("Exception not raised."); } catch (ArgumentNullException) { } catch { Assert.Fail("Wrong exception raised."); } }
public void TestPushFileWhenAttributesNotEqual() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File.txt", new MockFileData("Data")); fileSystem.File.SetAttributes(@"C:\Source\File.txt", FileAttributes.Hidden); fileSystem.File.SetAttributes(@"C:\Target\File.txt", FileAttributes.Normal); Pusher.PushEntryResult result = Pusher.PushFile(fileSystem, @"C:\Source\File.txt", @"C:\Target\File.txt"); Assert.AreEqual(FileAttributes.Hidden, fileSystem.File.GetAttributes(@"C:\Target\File.txt")); }
private static void UpdateFileSystem(string path, string fileContent, MockFileSystem fileSystem) { if(!fileSystem.FileExists(path)) fileSystem.AddFile(path, new MockFileData(fileContent)); Assert.True(fileSystem.FileExists(path), "File {0} doesn't exist but it should.", path); }
public void TestCleanResult() { // Prepare the source and target directories and files. var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(); fileSystem.AddFile(@"C:\Source\File1.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File1.txt", new MockFileData("Data")); fileSystem.AddFile(@"C:\Target\File2.txt", new MockFileData("Data")); fileSystem.AddDirectory(@"C:\Source\SubDirectory"); fileSystem.AddDirectory(@"C:\Target\SubDirectory"); // Run the test. var result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source"); // Check the result. Assert.AreEqual(1, result.MatchedFiles.Count); Assert.AreEqual("File1.txt", result.MatchedFiles[0]); Assert.AreEqual(1, result.DeletedEntries.Count); Assert.AreEqual("File2.txt", result.DeletedEntries[0]); Assert.AreEqual(0, result.FailedEntries.Count); // TODO:: figure out how to spoof a fail an entry? Assert.AreEqual(1, result.DirectoryResults.Count); }
public void Setup() { var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>()); fileSystem.AddFile("/Input/ShowName1 - S01E01.mp4", null); fileSystem.AddFile("/Input/ShowName1 - S01E02.avi", null); fileSystem.AddFile("/Input/ShowName1 - S01E03.mkv", null); fileSystem.AddFile("/Input/ShowName1 - S01E04.m4v", null); fileSystem.AddFile("/Input/ShowName1 - S01E05.MP4", null); fileSystem.AddFile("/Input/ShowName1 - S01E06.AVI", null); fileSystem.AddFile("/Input/ShowName1 - S01E07.MKV", null); fileSystem.AddFile("/Input/ShowName1 - S01E08.M4V", null); fileSystem.AddFile("/Input/ShowName1 - S01E09.mP4", null); fileSystem.AddFile("/Input/ShowName1 - S01E10.aVi", null); fileSystem.AddFile("/Input/ShowName1 - S01E11.mKV", null); fileSystem.AddFile("/Input/ShowName1 - S01E12.m4V", null); fileSystem.AddFile("/Input/ShowName1 - S01E13.other", null); fileSystem.AddFile("/Input/ShowName1 - S01E14.OTHER", null); fileSystem.AddFile("/Input/ShowName1 - S01E15.OtHeR", null); fileSystem.AddFile("/Input/ShowName1 - S01E16.OtHeR$", null); fileSystem.AddFile("/Input/Subfolder1/ShowName2 - S01E01.mp4", null); fileSystem.AddFile("/Input/Subfolder1/ShowName2 - S01E02.avi", null); fileSystem.AddFile("/Input/Subfolder1/ShowName2 - S01E03.mkv", null); fileSystem.AddFile("/Input/Subfolder1/ShowName2 - S01E04.m4v", null); fileSystem.AddFile("/Input/ShowName3 - S01E01.mp4", null); fileSystem.AddFile("/Input/ShowName3 - S01E02.avi", null); fileSystem.AddFile("/Input/ShowName3 - S01E03.mkv", null); fileSystem.AddFile("/Input/ShowName3 - S01E04.m4v", null); fileSystem.AddFile("/Exclude/ShowName3 - S01E01.mp4", null); fileSystem.AddFile("/Exclude/ShowName3 - S01E02.mp4", null); fileSystem.AddFile("/Exclude/ShowName3 - S01E03.mp4", null); fileSystem.AddFile("/Exclude/ShowName3 - S01E04.mp4", null); _fileSystem = fileSystem; }