public void SerializeSnapshotWithOneFile() { SnapshotJsonFile snapshotJsonFile = new SnapshotJsonFile(); snapshotJsonFile.Snapshot = new Snapshot { CreationTime = new DateTime(2019, 5, 8, 19, 17, 0, DateTimeKind.Utc), Name = "Snapshot 1", OriginalPath = @"c:\aaa" }; snapshotJsonFile.Snapshot.Files.Add(new HFile { Name = "file.extension", Hash = new byte[] { 0, 1, 2 } }); const string expected = @"{ ""serializer-id"": ""9e93055d-7bde-4f55-b340-dd5a4880d96e"", ""original-path"": ""c:\\aaa"", ""creation-time"": ""2019-05-08T19:17:00Z"", ""f"": [ { ""n"": ""file.extension"", ""h"": ""AAEC"" } ] }"; PerformTest(snapshotJsonFile, expected); }
public void SerializeSnapshotWithOneDirectory() { SnapshotJsonFile snapshotJsonFile = new SnapshotJsonFile(); snapshotJsonFile.Snapshot = new Snapshot { CreationTime = new DateTime(2019, 5, 8, 19, 17, 0, DateTimeKind.Utc), Name = "Snapshot 1", OriginalPath = @"c:\aaa" }; snapshotJsonFile.Snapshot.Directories.Add(new HDirectory { Name = "directory-name" }); const string expected = @"{ ""serializer-id"": ""9e93055d-7bde-4f55-b340-dd5a4880d96e"", ""original-path"": ""c:\\aaa"", ""creation-time"": ""2019-05-08T19:17:00Z"", ""d"": [ { ""n"": ""directory-name"" } ] }"; PerformTest(snapshotJsonFile, expected); }
private static void PerformTest(SnapshotJsonFile snapshotJsonFile, string expected) { using (MemoryStream memoryStream = new MemoryStream()) { StreamWriter streamWriter = new StreamWriter(memoryStream); snapshotJsonFile.Save(streamWriter); streamWriter.Flush(); memoryStream.Flush(); memoryStream.Position = 0; StreamReader streamReader = new StreamReader(memoryStream); string json = streamReader.ReadToEnd(); Assert.That(json, Is.EqualTo(expected)); } }
public void SerializeEmptySnapshot() { SnapshotJsonFile snapshotJsonFile = new SnapshotJsonFile(); snapshotJsonFile.Snapshot = new Snapshot { CreationTime = new DateTime(2019, 5, 8, 19, 17, 0, DateTimeKind.Utc), Name = "Snapshot 1", OriginalPath = @"c:\aaa" }; const string expected = @"{ ""serializer-id"": ""9e93055d-7bde-4f55-b340-dd5a4880d96e"", ""original-path"": ""c:\\aaa"", ""creation-time"": ""2019-05-08T19:17:00Z"" }"; PerformTest(snapshotJsonFile, expected); }
public Snapshot GetSnapshot(string path) { SnapshotJsonFile file = SnapshotJsonFile.Load(path); return(file.Snapshot); }