コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }