public void TestFileCompare() { var FirstRunId = "TestFileCollector-1"; var SecondRunId = "TestFileCollector-2"; var testFolder = AsaHelpers.GetTempFolder(); Directory.CreateDirectory(testFolder); var opts = new CollectCommandOptions() { RunId = FirstRunId, EnableFileSystemCollector = true, GatherHashes = true, SelectedDirectories = testFolder, DownloadCloud = false, }; var fsc = new FileSystemCollector(opts); fsc.Execute(); using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterMZ"), FileMode.OpenOrCreate)) { file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2); file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2); file.Close(); } using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterJavaClass"), FileMode.OpenOrCreate)) { file.Write(FileSystemUtils.JavaMagicNumber, 0, 4); file.Close(); } opts.RunId = SecondRunId; var fsc2 = new FileSystemCollector(opts); fsc2.Execute(); Assert.IsTrue(fsc2.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterMZ") && FSO.IsExecutable == true)); Assert.IsTrue(fsc2.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterJavaClass") && FSO.IsExecutable == true)); BaseCompare bc = new BaseCompare(); bc.Compare(fsc.Results, fsc2.Results, FirstRunId, SecondRunId); var results = bc.Results; Assert.IsTrue(results.ContainsKey((RESULT_TYPE.FILE, CHANGE_TYPE.CREATED))); Log.Debug(JsonConvert.SerializeObject(results)); Assert.IsTrue(results[(RESULT_TYPE.FILE, CHANGE_TYPE.CREATED)].Any(x => x.Compare is FileSystemObject FSO && FSO.Identity.Contains("AsaLibTesterMZ") && FSO.IsExecutable == true));
public void TestListOfStringsCompare() { var FirstRunId = "TestFileCollector-1"; var SecondRunId = "TestFileCollector-2"; var NewItems = new List <CollectObject>() { new RegistryObject("UnchangedEntry", RegistryView.Default) { Subkeys = new List <string>() { "UnchangedKey" } }, new RegistryObject("ChangingEntry", RegistryView.Default) { Subkeys = new List <string>() { "KeyTwo" } } }; var OldItems = new List <CollectObject>() { new RegistryObject("UnchangedEntry", RegistryView.Default) { Subkeys = new List <string>() { "UnchangedKey" } }, new RegistryObject("ChangingEntry", RegistryView.Default) { Subkeys = new List <string>() { "KeyOne" } } }; BaseCompare bc = new BaseCompare(); bc.Compare(OldItems, NewItems, FirstRunId, SecondRunId); var results = bc.Results; Assert.IsTrue(results[(RESULT_TYPE.REGISTRY, CHANGE_TYPE.MODIFIED)].Any(x => x.Identity.Contains("ChangingEntry") && x.Base is RegistryObject FSO && x.Compare is RegistryObject FSO2 && FSO.Subkeys.Contains("KeyOne") && FSO2.Subkeys.Contains("KeyTwo")));
public void TestAddedInMemory() { var elo2 = new EventLogObject("Entry") { Timestamp = DateTime.Now.AddYears(1) }; BaseCompare bc = new BaseCompare(); bc.Compare(new List <CollectObject>() { }, new List <CollectObject>() { elo2 }, "FirstRun", "SecondRun"); var results = bc.Results; Assert.IsTrue(results[(RESULT_TYPE.LOG, CHANGE_TYPE.CREATED)].Any(x => x.Compare is EventLogObject));
public void TestAddedInDatabase() { var elo2 = new EventLogObject("Entry") { Timestamp = DateTime.Now.AddYears(1) }; DatabaseManager.Write(elo2, "SecondRun"); // Let Database Finish Writing Thread.Sleep(1); BaseCompare bc = new BaseCompare(); bc.Compare("FirstRun", "SecondRun"); var results = bc.Results; Assert.IsTrue(results[(RESULT_TYPE.LOG, CHANGE_TYPE.CREATED)].Any(x => x.Compare is EventLogObject));