public void ComparerShouldReportDifferences() { //Arrange var beforeData = new[] { new { Name = "Test 1", A = 5, B = 6, C = 7 }, new { Name = "Test 2", A = 5, B = 6, C = 7 }, new { Name = "Test 3", A = 5, B = 6, C = 7 }, }; var afterData = new[] { new { Name = "Test 1", A = 6, B = 6, C = 6 }, new { Name = "Test 2", A = 5, B = 6, C = 7 }, new { Name = "Test 3", A = 5, B = 7, C = 6 }, }; var beforeBuilder = _collection.NewSnapshot("before"); beforeData.ToSnapshotTable(beforeBuilder, "Table", "Name"); var afterBuilder = _collection.NewSnapshot("after"); afterData.ToSnapshotTable(afterBuilder, "Table"); var output = new Output(); //Act SnapshotComparer.ReportDifferences(_collection, _collection.GetSnapshot("before"), _collection.GetSnapshot("after"), output); //Assert output.Report.Verify(); }
public void OnlyInSnapshot1_is_empty_if_both_snapshotss_contain_one_identical_file_in_same_dir() { Snapshot snapshot1 = new Snapshot(); HDirectory hDirectory1 = new HDirectory("Dir1"); hDirectory1.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); snapshot1.Directories.AddRange(new[] { hDirectory1 }); Snapshot snapshot2 = new Snapshot(); HDirectory hDirectory2 = new HDirectory("Dir1"); hDirectory2.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); snapshot2.Directories.AddRange(new[] { hDirectory2 }); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new string[0])); }
public void SubstitutionsCanBeDisabled() { //Arrange var beforeData = new[] { new { Name = "Test 1", A = 5, B = 6, C = 7 }, new { Name = "Test 2", A = 5, B = 6, C = 7 }, new { Name = "Test 3", A = 3, B = 7, C = 6 }, }; var afterData = new[] { new { Name = "Test 1", A = 5, B = 6, C = 7 }, new { Name = "Test 2", A = 8, B = 6, C = 3 }, new { Name = "Test 4", A = 10, B = 7, C = 6 }, }; var beforeBuilder = _collection.NewSnapshot("before"); beforeData.ToSnapshotTable(beforeBuilder, "Table", "Name"); var afterBuilder = _collection.NewSnapshot("after"); afterData.ToSnapshotTable(afterBuilder, "Table"); _collection.DefineTable("Table").IsUnpredictable("A").IsUnpredictable("B").IsUnpredictable("C"); var output = new Output(); //Act SnapshotComparer.ReportDifferences(_collection, _collection.GetSnapshot("before"), _collection.GetSnapshot("after"), output, ChangeReportOptions.NoSubs); //Assert output.Report.Verify(); }
public void OnlyInSnapshot1_is_empty_if_both_snapshots_contain_one_identical_file() { Snapshot snapshot1 = new Snapshot(); snapshot1.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); Snapshot snapshot2 = new Snapshot(); snapshot2.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new string[0])); }
public void DateDiagnosticsCanBeAdded() { //Arrange _collection.SetTimeSource(new FakeTimeSource("2020-10-18 10:28", "2020-10-18 10:29", "2020-10-18 10:30", "2020-10-18 10:31", "2020-10-18 10:32")); var beforeData = new[] { new { Name = "Test 1", A = 5, B = 6, C = 7 }, new { Name = "Test 2", A = 5, B = 6, C = 7 }, new { Name = "Test 3", A = 3, B = 7, C = 6 }, }; var afterData = new[] { new { Name = "Test 1", A = 5, B = 6, C = 7 }, new { Name = "Test 2", A = 8, B = 6, C = 3 }, new { Name = "Test 4", A = 10, B = 7, C = 6 }, }; var beforeBuilder = _collection.NewSnapshot("before"); beforeData.ToSnapshotTable(beforeBuilder, "Table", "Name"); var afterBuilder = _collection.NewSnapshot("after"); afterData.ToSnapshotTable(afterBuilder, "Table"); _collection.DefineTable("Table").IsUnpredictable("A").IsUnpredictable("B").IsUnpredictable("C"); var output = new Output(); //Act SnapshotComparer.ReportDifferences(_collection, _collection.GetSnapshot("before"), _collection.GetSnapshot("after"), output, ChangeReportOptions.NoSubs | ChangeReportOptions.ReportDateDiagnostics); //Assert output.Report.Verify(); }
private string CalculateExportDirectoryPath(SnapshotComparer comparer, string exportName) { string exportDirectoryNameBase = $"{exportName} - {executionTime:yyyy MM dd HHmmss}"; string exportDirectoryName = $"{comparer.Snapshot1.CreationTime:yyyy MM dd HHmmss}"; string exportDirectoryPath = Path.Combine(exportDirectoryNameBase, exportDirectoryName); return(exportDirectoryPath); }
public void Execute(Arguments arguments) { VerifyDiskRequest request = CreateRequest(arguments); SnapshotComparer snapshotComparer = mediator.Send(request).Result; ConsoleComparisonExporter exporter = new ConsoleComparisonExporter(); exporter.Export(snapshotComparer); }
private void ExportToDisk(SnapshotComparer comparer, string exportName) { FileComparisonExporter exporter = new() { ExportName = CalculateExportDirectoryPath(comparer, exportName) }; exporter.Export(comparer); }
private static void ExportInfoFile(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "info.txt"); using StreamWriter streamWriter = new(filePath); WriteFileHeader(streamWriter, comparer); streamWriter.WriteLine("StartTime (UTC) : {0}", comparer.StartTimeUtc); streamWriter.WriteLine("EndTime (UTC) : {0}", comparer.EndTimeUtc); streamWriter.WriteLine("TotalTime : {0}", comparer.TotalTime); }
private static string ExportToDisk(SnapshotComparer comparer, string exportFileName) { FileComparisonExporter exporter = new() { ExportName = exportFileName, AddTimeStamp = true }; exporter.Export(comparer); return(exporter.ExportDirectoryPath); } }
private static void WriteFileHeader(TextWriter streamWriter, SnapshotComparer comparer) { string snapshot1OriginalPath = comparer.Snapshot1.OriginalPath; DateTime snapshot1CreationTime = comparer.Snapshot1.CreationTime; streamWriter.WriteLine("Snapshot 1: {0} [{1:yyyy MM dd HHmmss}]", snapshot1OriginalPath, snapshot1CreationTime); string snapshot2OriginalPath = comparer.Snapshot2.OriginalPath; DateTime snapshot2CreationTime = comparer.Snapshot2.CreationTime; streamWriter.WriteLine("Snapshot 2: {0} [{1:yyyy MM dd HHmmss}]", snapshot2OriginalPath, snapshot2CreationTime); streamWriter.WriteLine(); }
private static void ExportSameNameDifferentContent(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "same-name-different-content.txt"); using StreamWriter streamWriter = new(filePath); WriteFileHeader(streamWriter, comparer); streamWriter.WriteLine("Different content:"); foreach (ItemComparison itemComparison in comparer.DifferentContent) { streamWriter.WriteLine(itemComparison.FullName1); } }
private static void ExportOnlyInSnapshot1(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "only-in-snapshot1.txt"); using StreamWriter streamWriter = new(filePath); WriteFileHeader(streamWriter, comparer); streamWriter.WriteLine("Files only in snapshot 1:"); foreach (string path in comparer.OnlyInSnapshot1) { streamWriter.WriteLine(path); } }
public void ReportChanges(string beforeSnapshot, string afterSnapshot, Output output, ChangeReportOptions compareOptions = ChangeReportOptions.Default) { if (!_snapshots.TryGetValue(beforeSnapshot, out var before)) { throw new SnapshotNotFoundException(beforeSnapshot); } if (!_snapshots.TryGetValue(afterSnapshot, out var after)) { throw new SnapshotNotFoundException(afterSnapshot); } SnapshotComparer.ReportDifferences(this, before, after, output, compareOptions); }
private static void ExportContentDifferentName(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "same-content-different-name.txt"); using StreamWriter streamWriter = new(filePath); WriteFileHeader(streamWriter, comparer); streamWriter.WriteLine("Different names:"); foreach (ItemComparison itemComparison in comparer.DifferentNames) { streamWriter.WriteLine("1 - " + itemComparison.FullName1); streamWriter.WriteLine("2 - " + itemComparison.FullName2); } }
public void Export(SnapshotComparer comparer) { if (string.IsNullOrWhiteSpace(ExportName)) { throw new Exception("Cannot export comparison result. No export name was provided."); } ExportDirectoryPath = CreateExportDirectory(); ExportInfoFile(comparer, ExportDirectoryPath); ExportOnlyInSnapshot1(comparer, ExportDirectoryPath); ExportOnlyInSnapshot2(comparer, ExportDirectoryPath); ExportContentDifferentName(comparer, ExportDirectoryPath); ExportSameNameDifferentContent(comparer, ExportDirectoryPath); }
protected override CompareSnapshotsResponse Handle(CompareSnapshotsRequest request) { Snapshot snapshot1 = snapshotFactory.RetrieveSnapshot(request.Snapshot1); Snapshot snapshot2 = snapshotFactory.RetrieveSnapshot(request.Snapshot2); SnapshotComparer comparer = CompareSnapshots(snapshot1, snapshot2); string exportDirectoryPath = ExportToDiskIfRequested(comparer, request); return(new CompareSnapshotsResponse { OnlyInSnapshot1 = comparer.OnlyInSnapshot1, OnlyInSnapshot2 = comparer.OnlyInSnapshot2, DifferentNames = comparer.DifferentNames, DifferentContent = comparer.DifferentContent, ExportDirectoryPath = exportDirectoryPath }); }
private static void ExportInfoFile(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "info.txt"); using (StreamWriter streamWriter = new StreamWriter(filePath)) { streamWriter.WriteLine("Snapshot 1: {0}", comparer.Snapshot1.OriginalPath); streamWriter.WriteLine("Snapshot 2: {0}", comparer.Snapshot2.OriginalPath); streamWriter.WriteLine(); streamWriter.WriteLine("StartTime (UTC) : {0}", comparer.StartTimeUtc); streamWriter.WriteLine("EndTime (UTC) : {0}", comparer.EndTimeUtc); streamWriter.WriteLine("TotalTime : {0}", comparer.TotalTime); } }
public void Export(SnapshotComparer comparer) { if (string.IsNullOrWhiteSpace(ResultsDirectory)) { throw new Exception("Cannot export comparison result. No file name was provided."); } string exportDirectoryPath = CreateExportDirectory(); ExportInfoFile(comparer, exportDirectoryPath); ExportOnlyInSnapshot1(comparer, exportDirectoryPath); ExportOnlyInSnapshot2(comparer, exportDirectoryPath); ExportContentDifferentName(comparer, exportDirectoryPath); ExportSameNameDifferentContent(comparer, exportDirectoryPath); CustomConsole.WriteLine("Results exported into directory: {0}", exportDirectoryPath); }
public void OnlyInSnapshot1_is_empty_if_only_snapshot2_has_one_subdir() { Snapshot snapshot1 = new Snapshot(); Snapshot snapshot2 = new Snapshot(); snapshot2.Directories.AddRange(new[] { new HDirectory("Dir1") }); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new string[0])); }
public void OnlyInSnapshot1_contains_the_name_of_the_subdir_if_only_snapshot1_has_one_subdir() { Snapshot snapshot1 = new Snapshot(); snapshot1.Directories.AddRange(new[] { new HDirectory("Dir1") }); Snapshot snapshot2 = new Snapshot(); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new[] { "/Dir1/" })); }
private static void ExportSameNameDifferentContent(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "same-name-different-content.txt"); using (StreamWriter streamWriter = new StreamWriter(filePath)) { streamWriter.WriteLine("Snapshot 1: {0}", comparer.Snapshot1.OriginalPath); streamWriter.WriteLine("Snapshot 2: {0}", comparer.Snapshot2.OriginalPath); streamWriter.WriteLine(); streamWriter.WriteLine("Different content:"); foreach (ItemComparison itemComparison in comparer.DifferentContent) { streamWriter.WriteLine(itemComparison.FullName1); } } }
private static void ExportOnlyInSnapshot1(SnapshotComparer comparer, string exportDirectoryPath) { string filePath = Path.Combine(exportDirectoryPath, "only-in-snapshot1.txt"); using (StreamWriter streamWriter = new StreamWriter(filePath)) { streamWriter.WriteLine("Snapshot 1: {0}", comparer.Snapshot1.OriginalPath); streamWriter.WriteLine("Snapshot 2: {0}", comparer.Snapshot2.OriginalPath); streamWriter.WriteLine(); streamWriter.WriteLine("Files only in snapshot 1:"); foreach (string path in comparer.OnlyInSnapshot1) { streamWriter.WriteLine(path); } } }
public Task <CompareAllSnapshotsResponse> Handle(CompareAllSnapshotsRequest request, CancellationToken cancellationToken) { Snapshot[] snapshots = RetrieveAllSnapshots(request); for (int i = 0; i < snapshots.Length - 1; i++) { Snapshot currentSnapshot = snapshots[i]; Snapshot previousSnapshot = snapshots[i + 1]; SnapshotComparer comparer = CompareSnapshots(currentSnapshot, previousSnapshot); ExportToDisk(comparer, request.ExportName); } CompareAllSnapshotsResponse response = new(); return(Task.FromResult(response)); }
public void OnlyInSnapshot1_contains_the_name_of_the_file_if_only_snapshot1_has_one_file() { Snapshot snapshot1 = new Snapshot(); snapshot1.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); Snapshot snapshot2 = new Snapshot(); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new[] { "/File1" })); }
public void Execute(Arguments arguments) { CompareSnapshotsRequest request = CreateRequest(arguments); SnapshotComparer snapshotComparer = mediator.Send(request).Result; bool exportToFile = arguments.Count >= 3; if (exportToFile) { FileComparisonExporter exporter = new FileComparisonExporter { ResultsDirectory = arguments[2] }; exporter.Export(snapshotComparer); } else { ConsoleComparisonExporter exporter = new ConsoleComparisonExporter(); exporter.Export(snapshotComparer); } }
public void OnlyInSnapshot2_is_empty_if_both_snapshots_contain_one_identical_subdir() { Snapshot snapshot1 = new Snapshot(); snapshot1.Directories.AddRange(new[] { new HDirectory("Dir1") }); Snapshot snapshot2 = new Snapshot(); snapshot2.Directories.AddRange(new[] { new HDirectory("Dir1") }); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot2, Is.EqualTo(new string[0])); }
public static void DisplayResults(SnapshotComparer comparer) { Console.WriteLine(); Console.WriteLine("Files only in snapshot 1:"); foreach (string path in comparer.OnlyInSnapshot1) { Console.WriteLine(path); } Console.WriteLine(); Console.WriteLine("Files only in snapshot 2:"); foreach (string path in comparer.OnlyInSnapshot2) { Console.WriteLine(path); } Console.WriteLine(); Console.WriteLine("Different names:"); foreach (ItemComparison itemComparison in comparer.DifferentNames) { Console.WriteLine("1 - " + itemComparison.FullName1); Console.WriteLine("2 - " + itemComparison.FullName2); } Console.WriteLine(); Console.WriteLine("Different content:"); foreach (ItemComparison itemComparison in comparer.DifferentContent) { Console.WriteLine("1 - " + itemComparison.FullName1); Console.WriteLine("2 - " + itemComparison.FullName2); } }
public void SetUp() { snapshot1 = new Snapshot(); snapshot1.Files.AddRange(new[] { new HFile { Name = "File1.txt", Hash = new byte[] { 1, 2, 3 } }, new HFile { Name = "File2.txt", Hash = new byte[] { 1, 2, 3 } } }); snapshot2 = new Snapshot(); snapshot2.Files.AddRange(new[] { new HFile { Name = "File1.txt", Hash = new byte[] { 1, 2, 3 } }, new HFile { Name = "File2.txt", Hash = new byte[] { 1, 2, 3 } } }); snapshotComparer = new SnapshotComparer(snapshot1, snapshot2); }
public void OnlyInSnapshot1_contains_the_name_of_the_file_if_only_snapshot1_has_one_file_in_dir() { Snapshot snapshot1 = new Snapshot(); HDirectory hDirectory1 = new HDirectory("Dir1"); hDirectory1.Files.AddRange(new[] { new HFile { Name = "File1", Hash = new byte[] { 0x01, 0x02, 0x03 } } }); snapshot1.Directories.AddRange(new[] { hDirectory1 }); Snapshot snapshot2 = new Snapshot(); HDirectory hDirectory2 = new HDirectory("Dir1"); snapshot2.Directories.AddRange(new[] { hDirectory2 }); SnapshotComparer comparer = new SnapshotComparer(snapshot1, snapshot2); comparer.Compare(); Assert.That(comparer.OnlyInSnapshot1, Is.EqualTo(new[] { "/Dir1/File1" })); }