public void Given_MaintenanceTimeFrame_When_IsWithinMaintenanceHours_Then_GetAvailableUpdatesIsCalled() { var cultureInfo = new CultureInfo("nl-NL"); string configContent = File.ReadAllText(@"..\..\centralConfig.xml"); var serializer = new Serialization <CustomerConfigurationsFile>(); var configInstance = serializer.GetObjectFromXml(configContent); configContent = serializer.Serialize(configInstance); var httpClient = Mock.Of <IHttpClient>(); Mock.Get(httpClient).Setup(c => c.GetResponse(It.IsAny <string>())).Returns(configContent); IUpdateClient updateClient = Mock.Of <IUpdateClient>(); mController = createController(null, httpClient, updateClient); var run = mController.GetType().GetMethod("runUpdateProcedure", BindingFlags.NonPublic | BindingFlags.Instance); bool inactive = false; mController.Inactivated += (s, e) => { inactive = true; }; run.Invoke(mController, new object[] { }); while (!inactive) { Thread.Sleep(0); } Mock.Get(updateClient).Verify(c => c.GetAvailableUpdates(), Times.Once); }
public UpdateController(ILocalConfiguration config, IHttpClient httpClient, IUpdateClient updateClient, ITaskHandler taskHandler, IStatusReporter reporter, IReportStorage reportStorage, ITimeFrameDecision timeFrameDecision) { mStopServiceEvent = new ManualResetEvent(false); LocalConfig = config; WebHttpClient = httpClient; WindowsUpdateClient = updateClient; WindowsTaskHandler = taskHandler; Reporter = reporter; ReportStorage = reportStorage; TimeFrameDecision = timeFrameDecision; Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); }
public void Init() { data = Substitute.For <IUpdateServerDataProvider>(); clientFactory = Substitute.For <IUpdateClientFactory>(); applicationVersion = Substitute.For <IApplicationVersion>(); application = Substitute.For <IApplication>(); fileSystem = Substitute.For <IFileSystem>(); standaloneUpdate = Substitute.For <IStandaloneUpdater>(); updateClient = Substitute.For <IUpdateClient>(); settings = Substitute.For <IUpdaterSettingsProvider>(); platformService = Substitute.For <IAutoUpdatePlatformService>(); clientFactory .Create(Arg.Any <Uri>(), Arg.Any <string>(), Arg.Any <string?>(), Arg.Any <Platforms>()) .Returns(updateClient); }
public void Given_TimeFrameMaintenanceThrowsException_Then_InactivatedIsRaised() { var cultureInfo = new CultureInfo("nl-NL"); 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); timeFrame.DayOfWeek = (int)DateTime.UtcNow.DayOfWeek; timeFrame.StartTime = DateTime.UtcNow.AddMinutes(10).ToString(cultureInfo); timeFrame.EndTime = DateTime.UtcNow.AddMinutes(30).ToString(cultureInfo); configContent = serializer.Serialize(configInstance); var httpClient = Mock.Of <IHttpClient>(); Mock.Get(httpClient).Setup(c => c.GetResponse(It.IsAny <string>())).Returns(configContent); var timeFrameDecision = Mock.Of <ITimeFrameDecision>(); Mock.Get(timeFrameDecision).Setup(t => t.IsWithinTimeFrame(It.IsAny <TimeFrame>())).Throws(new ConfigurationErrorsException()); IUpdateClient updateClient = Mock.Of <IUpdateClient>(); mController = createController(null, httpClient, updateClient, timeFrameDecision: timeFrameDecision); var run = mController.GetType().GetMethod("runUpdateProcedure", BindingFlags.NonPublic | BindingFlags.Instance); bool inactive = false; mController.Inactivated += (s, e) => { inactive = true; }; run.Invoke(mController, new object[] { }); while (!inactive) { Thread.Sleep(0); } Mock.Get(updateClient).Verify(c => c.GetAvailableUpdates(), Times.Never); }
public void Given_FailReadingCentralConfigAndCentralConfigNotInitialized_Then_InactivatedIsRaised() { var httpClient = Mock.Of <IHttpClient>(); Mock.Get(httpClient).Setup(c => c.GetResponse(It.IsAny <string>())).Throws <Exception>(); IUpdateClient updateClient = Mock.Of <IUpdateClient>(); mController = createController(null, httpClient, updateClient); var run = mController.GetType().GetMethod("runUpdateProcedure", BindingFlags.NonPublic | BindingFlags.Instance); bool inactive = false; mController.Inactivated += (s, e) => { inactive = true; }; run.Invoke(mController, new object[] { }); while (!inactive) { Thread.Sleep(0); } Mock.Get(updateClient).Verify(c => c.GetAvailableUpdates(), Times.Never); }
public void Initialize(IUpdateClient updateClient) { this.updateClient = updateClient; }
private UpdateController createController(ILocalConfiguration localConfig = null, IHttpClient httpClient = null, IUpdateClient updateClient = null, ILog logger = null, ITaskHandler taskHandler = null, IStatusReporter reporter = null, IReportStorage reportStorage = null, ITimeFrameDecision timeFrameDecision = null) { if (localConfig == null) { localConfig = getLocalConfig(); } if (httpClient == null) { httpClient = getHttpClient(); } if (updateClient == null) { updateClient = Mock.Of <IUpdateClient>(); } if (logger == null) { logger = Mock.Of <ILog>(); } if (taskHandler == null) { taskHandler = Mock.Of <ITaskHandler>(); Mock.Get(taskHandler).Setup(t => t.GetMachineName()).Returns(CServerName); } if (reporter == null) { reporter = Mock.Of <IStatusReporter>(); } if (reportStorage == null) { reportStorage = Mock.Of <IReportStorage>(); } if (timeFrameDecision == null) { timeFrameDecision = Mock.Of <ITimeFrameDecision>(); Mock.Get(timeFrameDecision).Setup(t => t.IsWithinTimeFrame(It.IsAny <TimeFrame>())).Returns(true); } var controller = new UpdateController(localConfig, httpClient, updateClient, taskHandler, reporter, reportStorage, timeFrameDecision); controller.Logger = Mock.Of <ILog>(); return(controller); }