private static void LogBannerHit(Identity id, BannerDataHolder bdh) { Banner b = new Banner(bdh.K); b.RegisterHit(id); }
public void BannersAreServedAndCappedOnceTheyHaveReachedTheLimitForTheirTimeslot() { Caching.Instances.Main.FlushAll(); Caching.Instances.LocalCache.FlushAll(); using (new Context<Clock>(() => Time.Clock, (c) => Time.Clock = c, new ShiftedClock(Time.Today))) using (new Context<bool>(() => Common.Settings.SpreadBannerHits, (b) => Common.Settings.SpreadBannerHits = b, false)) using (new Context<TrafficShape>(() => Static.TrafficShape, (t) => Static.TrafficShape = t, new ConstantTrafficShape())) { int numberOfHitsPerTimeslot = 5; UnitTestUtilities.Sql.SqlHelper.Execute(Common.Properties.ConnectionString, "DELETE FROM Banner"); Banner b = AddValidBanner(numberOfHitsPerTimeslot); Server server = new Server(); int counter = 0; BannerDataHolder bdh = null; while (true) { Identity id = new BrowserGuidIdentity(Guid.NewGuid()); bdh = server.GetBanner(b.Position, false, id, new Bobs.BannerServer.Rules.RequestRules()); if (bdh == null) { break; } Banner banner = new Banner(bdh.K); banner.RegisterHit(id); counter++; } Assert.AreEqual((int)Math.Ceiling(numberOfHitsPerTimeslot * Server.ServiceMultiplier), counter); } }