public void TestConnectionSuccessTest()
        {
            string machineName          = System.Environment.MachineName;
            TestConnectionResult result = RegistryCompare.TestConnection(machineName);

            Assert.IsTrue(result.Successful);
        }
        public async Task FindMatchingRegistryEntriesSZSuccessTest()
        {
            List <RegistryEntry> listA = new List <RegistryEntry>();
            List <RegistryEntry> listB = new List <RegistryEntry>();

            listA.Add(new RegistryEntry()
            {
                Data     = new SZRegistryKey("testing1"),
                FullPath = "a",
                Location = "a\\a",
                Name     = "testkey",
                Type     = RegistryValueKind.String
            });

            listB.Add(new RegistryEntry()
            {
                Data     = new SZRegistryKey("testing2"),
                FullPath = "a",
                Location = "a\\a",
                Name     = "testkey",
                Type     = RegistryValueKind.String
            });

            List <RegistryEntryDifference> matchingRegistryEntries = RegistryCompare.FindMatchingRegistryEntries(listA, listB);

            Assert.IsTrue(matchingRegistryEntries.Count > 0);
        }
        public async Task TestConnectionAsyncSuccessTest()
        {
            string machineName          = System.Environment.MachineName;
            TestConnectionResult result = await RegistryCompare.TestConnectionAsync(machineName);

            Assert.IsTrue(result.Successful);
        }
        public async Task FindMatchingRegistryEntriesQwordEmptyTest()
        {
            List <RegistryEntry> listA = new List <RegistryEntry>();
            List <RegistryEntry> listB = new List <RegistryEntry>();

            listA.Add(new RegistryEntry()
            {
                Data     = new QwordRegistryKey("a"),
                FullPath = "a",
                Location = "a\\a",
                Name     = "testkey",
                Type     = RegistryValueKind.Binary
            });

            listB.Add(new RegistryEntry()
            {
                Data     = new QwordRegistryKey("a"),
                FullPath = "a",
                Location = "a\\a",
                Name     = "testkey",
                Type     = RegistryValueKind.Binary
            });

            List <RegistryEntryDifference> matchingRegistryEntries = RegistryCompare.FindMatchingRegistryEntries(listA, listB);

            Assert.IsTrue(matchingRegistryEntries.Count == 0);
        }
        public async Task GetRegistryEntriesSuccessAsyncTest()
        {
            string                machineName = System.Environment.MachineName;
            string                rootKey     = "Console";
            RegistryHive          hive        = RegistryHive.CurrentUser;
            RegistryEntriesResult result      = await RegistryCompare.GetRegistryEntriesAsync(hive, rootKey, machineName);

            Assert.IsTrue(result.RegistryEntries.Count > 0, "That key does not have any entries.");
        }
        public void GetRegistryEntriesSuccessTest()
        {
            string                machineName = System.Environment.MachineName;
            string                rootKey     = "Console";
            RegistryHive          hive        = RegistryHive.CurrentUser;
            RegistryEntriesResult result      = RegistryCompare.GetRegistryEntries(RegistryHive.CurrentUser, rootKey, machineName);

            Assert.IsTrue(result.Successful);
        }
        public async Task TestConnectionAsyncTimeoutTest()
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;
            int    timeout              = 100000000;
            string machineName          = System.Environment.MachineName;
            TestConnectionResult result = await RegistryCompare.TestConnectionAsync(machineName, cancellationTokenSource, cancellationToken, timeout);

            Assert.IsTrue(result.Successful);
        }
        private async Task PopulateTabs()
        {
            _missingEntriesFromMachineB = RegistryCompare.FindMissingRegistryEntries(_machineARegistryEntries, _machineBRegistryEntries);
            PopulateTab(_missingEntriesFromMachineB, dataGridView3);

            _missingEntriesFromMachineA = RegistryCompare.FindMissingRegistryEntries(_machineBRegistryEntries, _machineARegistryEntries);
            PopulateTab(_missingEntriesFromMachineA, dataGridView4);

            _registryEntryDifferences = RegistryCompare.FindMatchingRegistryEntries(_machineARegistryEntries, _machineBRegistryEntries);
            PopulateTab(_registryEntryDifferences, dataGridView5);
        }
        private async Task <List <RegistryEntry> > GetRegisty(RegistryHive registryHive, string machineName, Label machineLabel, CancellationTokenSource tokenSource, CancellationToken token)
        {
            machineLabel.Text    = "Loading Registry";
            machineLabel.Visible = true;

            RegistryEntriesResult result = await RegistryCompare.GetRegistryEntriesAsync(registryHive, textbox_registryKeyRoot.Text, machineName, tokenSource, token, _testConnectionTimeout);

            if (!result.Successful)
            {
                if (result.ErrorCode == ErrorCodes.SECURITY_EXCEPTION ||
                    result.ErrorCode == ErrorCodes.UNAUTHORIZED_ACCESS_EXCEPTION)
                {
                    machineLabel.Text = "Access Denied";
                }
                else if (result.ErrorCode == ErrorCodes.IO_EXCEPTION)
                {
                    machineLabel.Text = "Invalid Machine Name.";
                }
                else if (result.ErrorCode == ErrorCodes.TIMEOUT)
                {
                    machineLabel.Text = "Connection Timeout.";
                }

                try
                {
                    tokenSource.Cancel();
                    token.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException)
                {
                    SetStatusStripText("Error");
                    return(new List <RegistryEntry>()
                    {
                    });
                }
            }
            SetStatusStripText("Success");
            machineLabel.Text = "Loaded";
            return(result.RegistryEntries);
        }
        private async Task TestConnection(string machineName, Label machineLabel, CancellationTokenSource tokenSource, CancellationToken token)
        {
            machineLabel.Text    = "Testing Connection";
            machineLabel.Visible = true;

            TestConnectionResult testConnection =
                await RegistryCompare.TestConnectionAsync(machineName, tokenSource, token, _testConnectionTimeout);

            if (!testConnection.Successful)
            {
                if (testConnection.ErrorCode == ErrorCodes.SECURITY_EXCEPTION ||
                    testConnection.ErrorCode == ErrorCodes.UNAUTHORIZED_ACCESS_EXCEPTION)
                {
                    machineLabel.Text = "Access Denied";
                }
                else if (testConnection.ErrorCode == ErrorCodes.IO_EXCEPTION)
                {
                    machineLabel.Text = "Invalid Machine Name.";
                }
                else if (testConnection.ErrorCode == ErrorCodes.TIMEOUT)
                {
                    machineLabel.Text = "Connection Timeout.";
                }
                try
                {
                    SetStatusStripText("Error");
                    tokenSource.Cancel();
                    token.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException) { }
            }
            else
            {
                machineLabel.Text = "Connection Successful";
            }
        }
        public async Task GetRegistryEntriesFailedAsyncTest()
        {
            RegistryEntriesResult result = await RegistryCompare.GetRegistryEntriesAsync(RegistryHive.CurrentUser, "somekey", "machinea");

            Assert.AreEqual(0, result.RegistryEntries.Count);
        }
        public async Task TestConnectionAsyncFailedTest()
        {
            TestConnectionResult result = await RegistryCompare.TestConnectionAsync("machinea");

            Assert.IsFalse(result.Successful);
        }
        public void TestConnectionFailedTest()
        {
            TestConnectionResult result = RegistryCompare.TestConnection("machinea");

            Assert.IsFalse(result.Successful);
        }
        public void GetRegistryEntriesFailTest()
        {
            RegistryEntriesResult result = RegistryCompare.GetRegistryEntries(RegistryHive.CurrentUser, "somekey", "machinea");

            Assert.IsFalse(result.Successful);
        }