public void Given_ServerIsPresentInExclusionList_Then_InactiveStateActivated()
        {
            string configContent  = File.ReadAllText(@"..\..\centralConfig.xml");
            var    serializer     = new Serialization <CustomerConfigurationsFile>();
            var    configInstance = serializer.GetObjectFromXml(configContent);

            configInstance.FirstOrDefault().ServerUpdateConfiguration.ExcludedServers[0] = CServerName;
            configContent = serializer.Serialize(configInstance);

            var httpClient = Mock.Of <IHttpClient>();

            Mock.Get(httpClient).Setup(c => c.GetResponse(It.IsAny <string>())).Returns(configContent);

            mController = createController(null, httpClient);

            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();

            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Assert.IsTrue(inactive);
        }
        public void Given_TwoCallsOnBeginUpdate_WhenFirstCallInactivates_Then_SecondCallStarts()
        {
            var updateClient = Mock.Of <IUpdateClient>();

            Mock.Get(updateClient).Setup(u => u.GetAvailableUpdates()).Callback(() => Thread.Sleep(500)).Returns(new UpdateCollectionClass());

            mController = createController(null, null, updateClient);

            int k = 0;

            mController.Inactivated += (s, e) =>
            {
                if (k == 0)
                {
                    Mock.Get(updateClient).Verify(u => u.GetAvailableUpdates(), Times.Once);
                    k++;
                }
                else if (k == 1)
                {
                    Mock.Get(updateClient).Verify(u => u.InstallUpdates(It.IsAny <IUpdateCollection>()), Times.Never);
                    k++;
                }
            };

            mController.BeginUpdate();

            Thread.Sleep(100);

            var localConfig = Mock.Of <ILocalConfiguration>();

            Mock.Get(localConfig).Setup(lc => lc.GroupName).Returns("Not_present");

            var updateClientProperty = mController.GetType().GetProperty("LocalConfig", BindingFlags.Public | BindingFlags.Instance);

            updateClientProperty.SetValue(mController, localConfig);

            mController.BeginUpdate();

            while (k != 2)
            {
                Thread.Sleep(100);
            }
        }
        public void Given_UpdatesInstalled_When_IsNotRebootNeeded_Then_RebootSystemIsNotCalled()
        {
            IUpdate update1 = Mock.Of <IUpdate>();
            IUpdate update2 = Mock.Of <IUpdate>();

            string updateId1 = "230b82d1-3abd-471a-a4f9-23f97fb857d9";
            string updateId2 = "8497fe19-9f28-4189-b671-b95d8ba8c2d9";

            Mock.Get(update1).Setup(u => u.Identity.UpdateID).Returns(updateId1);
            Mock.Get(update2).Setup(u => u.Identity.UpdateID).Returns(updateId2);

            var updateCollection = new UpdateCollectionClass();

            updateCollection.Add(update1);
            updateCollection.Add(update2);

            var updateClient = Mock.Of <IUpdateClient>();

            Mock.Get(updateClient).Setup(u => u.GetAvailableUpdates()).Returns(updateCollection);

            var installationResult = Mock.Of <IInstallationResult>();

            Mock.Get(installationResult).Setup(r => r.RebootRequired).Returns(false);
            Mock.Get(updateClient).Setup(u => u.InstallUpdates(updateCollection)).Returns(new Result()
            {
                InstallationResult    = installationResult,
                UpdateInstallationLog = new UpdateInstallationLog()
            });

            var taskHandler = Mock.Of <ITaskHandler>();

            var httpClient = getHttpClientWithNoExcludedUpdates();

            mController = createController(null, httpClient, updateClient, null, taskHandler);

            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();
            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Mock.Get(taskHandler).Verify(t => t.RebootSystem(), Times.Never);
        }
        public void Given_TwoUpdatesAvailable_When_UpdatesPresentInExclusionList_Then_InactiveStateActivated()
        {
            var updateClient = getUpdateClientWithUpdatesToInstall(new[] { "4269002", "2267602" });

            mController = createController(null, null, updateClient);
            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();

            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Assert.IsTrue(inactive);
        }
        public void Given_ServerIsNotPresentInExclusionListAndGroupIsInMaintenanceTimeFrame_Then_GetUpdatesIsCalled()
        {
            var updateClient = Mock.Of <IUpdateClient>();

            mController = createController(null, getHttpClient(), updateClient);

            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();

            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Mock.Get(updateClient).Verify(uc => uc.GetAvailableUpdates(), Times.Once);
        }
        public void Given_GroupIsNotInMaintenanceTimeFrame_Then_InactiveStateActivated()
        {
            string configContent  = File.ReadAllText(@"..\..\centralConfig.xml");
            var    serializer     = new Serialization <CustomerConfigurationsFile>();
            var    configInstance = serializer.GetObjectFromXml(configContent);
            var    timeFrame      = configInstance.FirstOrDefault().MaintenanceSchedule.FirstOrDefault(tf => tf.GroupName == CGroupName);

            if (timeFrame != null)
            {
                timeFrame.StartTime = DateTime.UtcNow.AddHours(1).ToString();
                timeFrame.EndTime   = DateTime.UtcNow.AddHours(2).ToString();
            }
            else
            {
                throw new Exception("Time frame does not contain the test group.");
            }

            if (configInstance.FirstOrDefault().ServerUpdateConfiguration.ExcludedServers.Contains(CServerName))
            {
                throw new Exception("Server is in the exclusion list.");
            }

            configContent = serializer.Serialize(configInstance);
            var httpClient = Mock.Of <IHttpClient>();

            Mock.Get(httpClient).Setup(c => c.GetResponse(It.IsAny <string>())).Returns(configContent);

            mController = createController(null, httpClient);

            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();

            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Assert.IsTrue(inactive);
        }
        public void Given_GetAvailableUpdatesReturnsEmpty_Then_InactiveStateActivated()
        {
            var updateClient = Mock.Of <IUpdateClient>();

            Mock.Get(updateClient).Setup(c => c.GetAvailableUpdates()).Returns(new UpdateCollectionClass());

            var httpClient = getHttpClient();

            mController = createController(null, httpClient, updateClient);

            bool inactive = false;

            mController.Inactivated += (s, e) => { inactive = true; };
            mController.BeginUpdate();

            while (!inactive)
            {
                Thread.Sleep(0);
            }

            Assert.IsTrue(inactive);
        }