public void call_on_each_test() { var target1 = MockRepository.GenerateMock<ITypeTarget>(); var target2 = MockRepository.GenerateMock<ITypeTarget>(); var target3 = MockRepository.GenerateMock<ITypeTarget>(); var target4 = MockRepository.GenerateMock<ITypeTarget>(); var cache = new InstanceCache(); cache.Set(typeof (int), new SmartInstance<int>(), target1); cache.Set(typeof (int), new SmartInstance<int>(), new object()); cache.Set(typeof (int), new SmartInstance<int>(), new object()); cache.Set(typeof (bool), new SmartInstance<int>(), target2); cache.Set(typeof (bool), new SmartInstance<int>(), new object()); cache.Set(typeof (string), new SmartInstance<int>(), target3); cache.Set(typeof (string), new SmartInstance<int>(), new object()); cache.Set(typeof (string), new SmartInstance<int>(), new object()); cache.Set(typeof (string), new SmartInstance<int>(), target4); cache.Each<ITypeTarget>(x => x.Go()); target1.AssertWasCalled(x => x.Go()); target2.AssertWasCalled(x => x.Go()); target3.AssertWasCalled(x => x.Go()); target4.AssertWasCalled(x => x.Go()); }
public void call_on_each_test() { var target1 = MockRepository.GenerateMock <ITypeTarget>(); var target2 = MockRepository.GenerateMock <ITypeTarget>(); var target3 = MockRepository.GenerateMock <ITypeTarget>(); var target4 = MockRepository.GenerateMock <ITypeTarget>(); var cache = new InstanceCache(); cache.Set(typeof(int), new SmartInstance <int>(), target1); cache.Set(typeof(int), new SmartInstance <int>(), new object()); cache.Set(typeof(int), new SmartInstance <int>(), new object()); cache.Set(typeof(bool), new SmartInstance <int>(), target2); cache.Set(typeof(bool), new SmartInstance <int>(), new object()); cache.Set(typeof(string), new SmartInstance <int>(), target3); cache.Set(typeof(string), new SmartInstance <int>(), new object()); cache.Set(typeof(string), new SmartInstance <int>(), new object()); cache.Set(typeof(string), new SmartInstance <int>(), target4); cache.Each <ITypeTarget>(x => x.Go()); target1.AssertWasCalled(x => x.Go()); target2.AssertWasCalled(x => x.Go()); target3.AssertWasCalled(x => x.Go()); target4.AssertWasCalled(x => x.Go()); }
public void TestCache() { var cache = new InstanceCache(); cache.Clear(); var summary = new HtmlSummary(HttpStatusCode.OK, "http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4", RawHtml, "text/html"); cache.Set("first", summary); cache.Set("second", summary); var first = cache.Get<HtmlSummary>("first"); var second = cache.Get<HtmlSummary>("second"); first.Should().NotBeNull(); second.Should().NotBeNull(); first.CreatedAt.Should().Be(second.CreatedAt); cache.Unset("first"); var none = cache.Get<HtmlSummary>("first"); none.Should().BeNull(); }