public void CtorSetsStatisticsService() { // arrange IStatisticsService service = new Mock<IStatisticsService>().Object; ISubtextContext subtextContext = new Mock<ISubtextContext>().Object; // act var controller = new StatisticsController(subtextContext, service); // assert Assert.AreSame(service, controller.StatisticsService); }
public void RequestForInvalidEntryIdNotRecordedAsAnAggregatorVisit() { // arrange var service = new Mock<IStatisticsService>(); service.Setup(s => s.RecordAggregatorView(It.IsAny<EntryView>())).Throws( new InvalidOperationException("RecordAggregatorView should not be called")); var headers = new NameValueCollection(); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 99 }); subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers); var controller = new StatisticsController(subtextContext.Object, service.Object); // act, no assert controller.RecordAggregatorView(-1); }
public void RequestForEntryRecordedAsAnAggregatorVisit() { // arrange EntryView entryView = null; var service = new Mock<IStatisticsService>(); service.Setup(s => s.RecordAggregatorView(It.IsAny<EntryView>())).Callback<EntryView>( view => entryView = view); var headers = new NameValueCollection(); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 99 }); subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers); var controller = new StatisticsController(subtextContext.Object, service.Object); // act controller.RecordAggregatorView(123); // assert Assert.IsNotNull(entryView); Assert.AreEqual(PageViewType.AggView, entryView.PageViewType); Assert.AreEqual(99, entryView.BlogId); Assert.AreEqual(123, entryView.EntryId); }
public void TwoRequestsWithinTimeoutGetsNotModifiedResult() { // arrange IStatisticsService service = new Mock<IStatisticsService>().Object; var subtextContext = new Mock<ISubtextContext>(); var headers = new NameValueCollection(); headers.Add("If-Modified-Since", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)); subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers); var controller = new StatisticsController(subtextContext.Object, service); // act var result = controller.RecordAggregatorView(123) as NotModifiedResult; // assert Assert.IsNotNull(result); }
public void RequestReturnsFileResultContainingSinglePixelImage() { // arrange var service = new Mock<IStatisticsService>(); var headers = new NameValueCollection(); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 99 }); subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers); var controller = new StatisticsController(subtextContext.Object, service.Object); // act var result = controller.RecordAggregatorView(-1) as CacheableFileContentResult; // assert Assert.IsNotNull(result); Assert.AreEqual(HttpCacheability.Public, result.Cacheability); Assert.AreEqual("image/gif", result.ContentType); }