public void TestCompareTo() { // Generate a memory snapshot. MemorySnapshot memorySnapshot = MemorySnapshot.FromProcess(notepad.Id); // Generate a second MemorySnapshot and get a diff. MemorySnapshot latestSnap = MemorySnapshot.FromProcess(notepad.Id); MemorySnapshot diff = latestSnap.CompareTo(memorySnapshot); // Manipulate the oracle to contain the same diff. Dictionary <string, long> diffOracle = GenerateDiffOracle(memorySnapshot, latestSnap); // Compare to verify data. VerifyProperties(diff, diffOracle); }
public void TestToFromFile() { string filePath = @"C:\testSnapCollection.xml"; MemorySnapshotCollection collection = new MemorySnapshotCollection(); // The following is for testing purposes and not representative use of the MemorySnapshotCollection class. MemorySnapshot ms1 = MemorySnapshot.FromProcess(notepad.Id); collection.Add(ms1); MemorySnapshot ms2 = MemorySnapshot.FromProcess(notepad.Id); collection.Add(ms2); MemorySnapshot ms3 = MemorySnapshot.FromProcess(notepad.Id); collection.Add(ms3); // Serialize MemorySnapshot to file. collection.ToFile(filePath); // Call from file to load data from file. MemorySnapshotCollection fileCollection = MemorySnapshotCollection.FromFile(filePath); // Verify Count. Assert.Equal(fileCollection.Count, collection.Count); // Generate Diffs for comparison. MemorySnapshot diff1 = ms1.CompareTo(fileCollection[0]); MemorySnapshot diff2 = ms2.CompareTo(fileCollection[1]); MemorySnapshot diff3 = ms3.CompareTo(fileCollection[2]); // Generate expected Diff results. Dictionary <string, long> diffOracle = GenerateDiffOracle(); // Verify Diffs are as expected. VerifyDiff(diff1, diffOracle); VerifyDiff(diff2, diffOracle); VerifyDiff(diff3, diffOracle); }