public void DataControllerShouldCallGetApiAddress()
        {
            var timeseriesRepo = new Mock<ISummarizer>();
            timeseriesRepo.Setup(t => t.GetTimeSeries("siteaddr", 123, null, null, Rollup.Weekly)).Returns((TimeseriesResult)null);
            var dataController = new DataController(new JsonConverter[] { }, timeseriesRepo.Object, m_SitesRepoMock.Object, null, null);
            var result = dataController.Index("siteaddr", 123);

            m_SitesRepoMock.Verify(s => s.GetApiAddress("siteaddr"), Times.Once());
        }
        public void DataControllerShouldCallTimeSeriesFormatter()
        {
            var tsr = new TimeseriesResult(Rollup.Weekly);

            tsr.Timeseries.Add("Label1", new Timeseries(Rollup.Weekly));

            var timeseriesRepo = new Mock<ISummarizer>();
            timeseriesRepo.Setup(t => t.GetTimeSeries("siteaddr", 123, null, null, Rollup.Weekly)).Returns(tsr);

            var converter = new Mock<JsonConverter>();
            converter.Setup(c=>c.CanConvert(It.IsAny<Type>())).Returns(false);
            converter.Setup(c => c.CanConvert(typeof(TimeseriesResult))).Returns(true);

            var dataController = new DataController(new[] { converter.Object }, timeseriesRepo.Object, m_SitesRepoMock.Object, null, null);
            var result = dataController.Index("siteaddr", 123) as ContentResult;

            Assert.AreEqual("application/json", result.ContentType);

            converter.Verify(c => c.WriteJson(It.IsAny<JsonWriter>(), It.IsAny<TimeseriesResult>(), It.IsAny<JsonSerializer>()), Times.Exactly(1));
        }
        public void GraphShouldDo404WhenNoSite()
        {
            var errorController = new Mock<IErrorController>();

            var timeseriesRepo = new Mock<ISummarizer>();
            timeseriesRepo.Setup(t => t.GetTimeSeries("siteaddr", 123, null, null, Rollup.Weekly)).Returns((TimeseriesResult)null);
            var dataController = new DataController(new JsonConverter[] { }, timeseriesRepo.Object, m_SitesRepoMock.Object, errorController.Object, null);
            m_SitesRepoMock.Setup(s => s.GetApiAddress("siteaddr")).Returns((string)null);

            var result = dataController.Index("siteaddr", 123);

            errorController.Verify(e => e.InvokeDataHttp404(It.IsAny<HttpContextBase>(), It.IsAny<string>()), Times.Once());
        }
        public void DataControllerShouldReturnContentResult()
        {
            var timeseriesRepo = new Mock<ISummarizer>();
            timeseriesRepo.Setup(t => t.GetTimeSeries("siteaddr", 123, null, null, Rollup.Weekly)).Returns((TimeseriesResult)null);
            var dataController = new DataController(new JsonConverter[] { }, timeseriesRepo.Object, m_SitesRepoMock.Object, null, null);
            var result = dataController.Index("siteaddr", 123);

            Assert.IsInstanceOfType(result, typeof(ContentResult));
        }