// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime) { applicationLifetime.ApplicationStopping.Register(Shutdown); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } var stats = app.ApplicationServices.GetService <Stats>(); var settings = app.ApplicationServices.GetService <ISettings>(); var voteCache = app.ApplicationServices.GetService <IVoteResultCache>(); timer = new VoteTimer(stats, settings, new RestClient("http://google.com"), voteCache, new Time()); timer.Start(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public void Setup() { stats = new Stats(); settings = new Settings { MobiRobiBaseUrl = "http://google.com/", }; restClientMock = new Mock <IRestClient>(); voteCache = new VoteResultCache(); timeMock = new TimeMock(); classUnderTest = new VoteTimer(stats, settings, restClientMock.Object, voteCache, timeMock); classUnderTest.Start(); }
public void ShouldWaitForTimeOnSettingsBeforeSendingCommand() { classUnderTest.Stop(); settings.SecondsBetweenVotes = 20; classUnderTest = new VoteTimer(stats, settings, restClientMock.Object, voteCache, timeMock); classUnderTest.Start(); stats.AddForwardVote(); timeMock.AddSeconds(11); Thread.Sleep(100); restClientMock.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Never); timeMock.AddSeconds(10); Thread.Sleep(100); restClientMock.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }