public void ModifiedFilesTest() { var id = Guid.NewGuid(); using (var tc = new Toolchain(id)) { // write some content before setup rules File.WriteAllText(Path.Combine(tc.RootPath, "1.txt"), "content"); File.WriteAllText(Path.Combine(tc.RootPath, "2.txt"), "content"); tc.SetupRules(new[] { new ModifiedFilesRule() }); File.WriteAllBytes(Path.Combine(tc.RootPath, "1.bin"), new byte[] { 128 }); File.Move(Path.Combine(tc.RootPath, "2.txt"), Path.Combine(tc.RootPath, "3.txt")); var classes = new ExtensionClasses().Text("txt").Binary("bin"); var result = tc.LoadSnapshot(classes); Assert.AreEqual(2, result.Files.Count); Assert.AreEqual(1, result.Files.OfType <FSTextFile>().Count()); var textFile = result.Files.OfType <FSTextFile>().First(); Assert.AreEqual("3.txt", textFile.Name); Assert.AreEqual(1, result.Files.OfType <FSBinaryFile>().Count()); } }
public void RegexMatchFilesTest() { var id = Guid.NewGuid(); using (var tc = new Toolchain(id)) { tc.SetupRules(new[] { new RegexMatchFilesRule() { Patterns = new List <string>() { "bin" } } }); File.WriteAllText(Path.Combine(tc.RootPath, "1.txt"), "content"); File.WriteAllBytes(Path.Combine(tc.RootPath, "1.bin"), new byte[] { 128 }); var classes = new ExtensionClasses().Text("txt").Binary("bin"); var result = tc.LoadSnapshot(classes); Assert.AreEqual(1, result.Files.Count); Assert.AreEqual(0, result.Files.OfType <FSTextFile>().Count()); Assert.AreEqual(1, result.Files.OfType <FSBinaryFile>().Count()); } }
public void ExecuteCommandTest_Success() { using (var tc = new Toolchain(Guid.NewGuid())) { var fs = new FSSnapshot(); fs.Files.Add(new FSTextFile() { Name = "1.cmd", Content = "copy 1.txt 2.txt" }); fs.Files.Add(new FSTextFile() { Name = "1.txt", Content = "content" }); tc.SaveSnapshot(fs); tc.SetupRules(new[] { new ModifiedFilesRule() }); tc.Invoke(new[] { new CommandLineInfo() { FileName = "cmd.exe", Arguments = "/c 1.cmd" } }); var result = tc.LoadSnapshot(new ExtensionClasses().Text("txt")); Assert.AreEqual(1, result.Files.Count); var file = (FSTextFile)result.Files[0]; Assert.AreEqual("2.txt", file.Name); Assert.AreEqual("content", file.Content); } }