public void shouldReturnWeightPrognosisXml()
        {
            AutoMappingsBootStrapper.MapHistoryGraphToAmChartData();

            var user = new User("Min user");
            var userContextMock = new Mock<IUserContext>(MockBehavior.Strict);
            userContextMock.Setup(x => x.User).Returns(user);

            var graphBuilderMock = new Mock<IGraphBuilder>(MockBehavior.Strict);

            ILine line = new Line(1, new Dictionary<DateTime, decimal> { { DateTime.Now.AddDays(1), 35M } }, "MyTitle");
            var graph = new Graph { Labels = new[] { new Label { Value = "val1", Index = "1" } }, LinesContainer = new LinesContainer { Lines = new[] { line } } };
            var userWeightBusinessLogicMock = new Mock<IUserWeightBusinessLogic>();
            userWeightBusinessLogicMock.Setup(x => x.GetProjectionList(It.Is<User>(y => y == user))).Returns(line);
            graphBuilderMock.Setup(x => x.GetGraph(It.Is<ILine[]>(y => y[0] == line))).Returns(graph);

            var resultController = new CarbonFitness.App.Web.Controllers.ResultController(null, null, userContextMock.Object, graphBuilderMock.Object, userWeightBusinessLogicMock.Object, null);

            var result = resultController.ShowWeightPrognosisXml();
            Assert.That(result.ObjectToSerialize, Is.AssignableTo(typeof(AmChartData)));

            var amChartData = (AmChartData) result.ObjectToSerialize;
            var dataPoints = amChartData.DataPoints;
            Assert.That(dataPoints, Is.Not.Null);

            var firstPoint = dataPoints.First();
            Assert.That(firstPoint.Value, Is.EqualTo("val1"));

            Assert.That(amChartData.GraphRoot.Graphs[0].values[0].Value, Is.EqualTo("35"));
            userWeightBusinessLogicMock.Verify();
        }
        public void shouldInitializeLabelsAndAddHistoryValuesWhenAddingFirstHisoryValue()
        {
            Line line = new Line(new Dictionary<DateTime, decimal> {{ DateTime.Now, 123  }} );
            Graph graph = new Graph(line);

            Assert.That(graph.Labels, Is.Not.Null);
            Assert.That(graph.Labels.Length, Is.EqualTo(line.Count()));

            Assert.That(graph.LinesContainer.Lines.Count(), Is.EqualTo(1));
            Assert.That(graph.LinesContainer.Lines[0].Count(), Is.EqualTo(line.Count()));
        }
Exemplo n.º 3
0
        public void shouldGetCalorieHistoryAsAmChartDataXml()
        {
            AutoMappingsBootStrapper.MapHistoryGraphToAmChartData();

            ILine line = new Line(new Dictionary<DateTime, decimal> {{DateTime.Now, 35M}});
            var graph = new Graph {Labels = new[] {new Label {Value = "val1", Index = "1"}}, LinesContainer = new LinesContainer {Lines = new[] {line}}};
            userIngredientBusinessLogicMock.Setup(x => x.GetNutrientHistory(NutrientEntity.EnergyInKcal, It.IsAny<User>())).Returns(line);
            graphBuilderMock.Setup(x => x.GetGraph(It.Is<ILine[]>(y => y[0] == line))).Returns(graph);
            graphLineOptionViewTypeConverterMock.Setup(x => x.GetNutrientEntitys(It.IsAny<string[]>())).Returns(new[] {NutrientEntity.EnergyInKcal});
            var actionResult = (ContentResult)RunMethodUnderTest(x => x.ShowXml(NutrientEntity.EnergyInKcal.ToString()));

            var serializer = new XmlSerializer(typeof(AmChartData));
            var stringReader = new StringReader(actionResult.Content);
            var deserialized = (AmChartData) serializer.Deserialize(stringReader);

            graphBuilderMock.VerifyAll();
            userIngredientBusinessLogicMock.VerifyAll();
            Assert.That(deserialized.DataPoints.Length, Is.EqualTo(1));
            Assert.That(deserialized.DataPoints.Length, Is.EqualTo(graph.Labels.Length));
            Assert.That(deserialized.DataPoints[0].Value, Is.EqualTo(graph.Labels[0].Value));
            Assert.That(decimal.Parse(deserialized.GraphRoot.Graphs[0].values[0].Value), Is.EqualTo(graph.LinesContainer.Lines[0].GetValuePoints()[0].Value));
        }
Exemplo n.º 4
0
        public void shouldGetUserWeightHistoryForGraph()
        {
            ILine line = new Line(new Dictionary<DateTime, decimal> { { DateTime.Now, 35M } });
            var graph = new Graph { Labels = new[] { new Label { Value = "val1", Index = "1" } }, LinesContainer = new LinesContainer { Lines = new[] { line } } };
            userWeightBusinessLogicMock.Setup(x => x.GetHistoryLine(It.IsAny<User>())).Returns(line);
            graphBuilderMock.Setup(x => x.GetGraph(It.Is<ILine[]>(y => y[0] == line))).Returns(graph);
            graphLineOptionViewTypeConverterMock.Setup(x => x.GetNutrientEntitys(It.IsAny<string[]>())).Returns(null as NutrientEntity[]);
            graphLineOptionViewTypeConverterMock.Setup(x => x.shouldShowWeight(It.IsAny<string[]>())).Returns(true);
            RunMethodUnderTest(x => x.ShowXml("Weight"));

            userWeightBusinessLogicMock.VerifyAll();
            userIngredientBusinessLogicMock.Verify(x => x.GetNutrientHistory(NutrientEntity.EnergyInKcal, It.IsAny<User>()), Times.Never());
        }