public void TestRegistryCollectorWindows()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Create a registry key
                var name   = Guid.NewGuid().ToString();
                var value  = Guid.NewGuid().ToString();
                var value2 = Guid.NewGuid().ToString();

                RegistryKey key;
                key = Registry.CurrentUser.CreateSubKey(name);
                key.SetValue(value, value2);
                key.Close();

                var rc = new RegistryCollector(new List <RegistryHive>()
                {
                    RegistryHive.CurrentUser
                }, true);
                rc.Execute();

                Registry.CurrentUser.DeleteSubKey(name);

                Assert.IsTrue(rc.Results.Any(x => x is RegistryObject RO && RO.Key.EndsWith(name)));
                Assert.IsTrue(rc.Results.Any(x => x is RegistryObject RO && RO.Key.EndsWith(name) && RO.Values.ContainsKey(value) && RO.Values[value] == value2));
            }
        }
Beispiel #2
0
        public void TestRegistryCollectorWindows()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Setup();

                var FirstRunId  = "TestRegistryCollector-1";
                var SecondRunId = "TestRegistryCollector-2";

                var rc = new RegistryCollector(FirstRunId, new List <RegistryHive>()
                {
                    RegistryHive.CurrentUser
                }, true);
                rc.Execute();

                // Create a registry key
                var name   = System.Guid.NewGuid().ToString().Substring(0, 10);
                var value  = System.Guid.NewGuid().ToString().Substring(0, 10);
                var value2 = System.Guid.NewGuid().ToString().Substring(0, 10);

                RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(name);
                key.SetValue(value, value2);
                key.Close();

                rc = new RegistryCollector(SecondRunId, new List <RegistryHive>()
                {
                    RegistryHive.CurrentUser
                }, true);
                rc.Execute();

                // Clean up
                Microsoft.Win32.Registry.CurrentUser.DeleteSubKey(name);

                BaseCompare bc = new BaseCompare();
                if (!bc.TryCompare(FirstRunId, SecondRunId))
                {
                    Assert.Fail();
                }

                var results = bc.Results;

                Assert.IsTrue(results.ContainsKey("REGISTRY_CREATED"));
                Assert.IsTrue(results["REGISTRY_CREATED"].Where(x => x.Identity.Contains(name)).Count() > 0);

                TearDown();
            }
        }