예제 #1
0
        public void shouldGetRDIOfNutrients()
        {
            var userContextMock = new Mock<IUserContext>();
            userContextMock.Setup(x => x.User).Returns(new User { Username = "******" });

            var rdiProxy = new Mock<IRDIProxy>();
            rdiProxy.Setup(x => x.getRDI(It.IsAny<User>(), It.IsAny<DateTime>(), It.Is<NutrientEntity>(y => y == NutrientEntity.ProteinInG))).Returns(12M);
            rdiProxy.Setup(x => x.getRDI(It.IsAny<User>(), It.IsAny<DateTime>(), It.Is<NutrientEntity>(y => y == NutrientEntity.FatInG))).Returns(12M);
            rdiProxy.Setup(x => x.getRDI(It.IsAny<User>(), It.IsAny<DateTime>(), It.Is<NutrientEntity>(y => y == NutrientEntity.CarbonHydrateInG))).Returns(12M);
            rdiProxy.Setup(x => x.getRDI(It.IsAny<User>(), It.IsAny<DateTime>(), It.Is<NutrientEntity>(y => y == NutrientEntity.FibresInG))).Returns(12M);
            rdiProxy.Setup(x => x.getRDI(It.IsAny<User>(), It.IsAny<DateTime>(), It.Is<NutrientEntity>(y => y == NutrientEntity.IronInmG))).Returns(12M);

            var controller = new CarbonFitness.App.Web.Controllers.FoodController(new Mock<IUserIngredientBusinessLogic>().Object, rdiProxy.Object, userContextMock.Object);
            var model = runMethodUnderTest(x => x.Input(), controller);

            rdiProxy.VerifyAll();
            Assert.That(model.RDIOfProtein, Is.EqualTo(12M));
            Assert.That(model.RDIOfFat, Is.EqualTo(12M));
            Assert.That(model.RDIOfCarbonHydrates, Is.EqualTo(12M));
            Assert.That(model.RDIOfFiber, Is.EqualTo(12M));
            Assert.That(model.RDIOfIron, Is.EqualTo(12M));
        }
예제 #2
0
        public void shouldReportErrorWhenInvalidDateEnteredOnPage()
        {
            var m = new InputFoodModel {Date = new DateTime(1234)};

            var userIngredientBusinessLogicMock = new Mock<IUserIngredientBusinessLogic>(MockBehavior.Loose);
            var userContextMock = new Mock<IUserContext>(MockBehavior.Strict);
            userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Throws(new InvalidDateException());
            userContextMock.Setup(x => x.User).Returns(new User());

            var foodController = new CarbonFitness.App.Web.Controllers.FoodController(userIngredientBusinessLogicMock.Object, new Mock<IRDIProxy>().Object, userContextMock.Object);
            foodController.Input(m);

            var errormessage = getErrormessage(foodController, "Date");
            Assert.That(errormessage, Is.EqualTo("Invalid date entered. Date should be in format YYYY-MM-DD"));
        }
예제 #3
0
        public void shouldReportErrorWhenNoIngredientFound()
        {
            var mockFactory = new MockFactory(MockBehavior.Loose);
            var userContextMock = GetSetuppedUserContextMock(mockFactory);

            var ingredientName = "afafafafafafafa";

            var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>();

            userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {new UserIngredient()});
            userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.IsAny<User>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>()))
                .Throws(new NoIngredientFoundException(ingredientName));

            var foodController = new CarbonFitness.App.Web.Controllers.FoodController(userIngredientBusinessLogicMock.Object, new Mock<IRDIProxy>().Object, userContextMock.Object);
            foodController.Input(new InputFoodModel {Ingredient = ingredientName, Measure = 10});

            //var model = testController(x => x.Input(new InputFoodModel()), userIngredientBusinessLogicMock, userContextMock);

            var errormessage = getErrormessage(foodController, "Ingredient");

            Assert.That(errormessage.Contains(ingredientName));
            Assert.That(errormessage, Is.EqualTo(FoodConstant.NoIngredientFoundMessage + ingredientName));
        }
예제 #4
0
        public void shouldRemoveUserIngredient()
        {
            var mockFactory = new MockFactory(MockBehavior.Loose);
            var userContextMock = GetSetuppedUserContextMock(mockFactory);
            var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>();
            userIngredientBusinessLogicMock.Setup(x => x.DeleteUserIngredient(It.IsAny<User>(), It.IsAny<int>(), It.IsAny<DateTime>()));
            var foodController = new CarbonFitness.App.Web.Controllers.FoodController(userIngredientBusinessLogicMock.Object, new Mock<IRDIProxy>().Object, userContextMock.Object);
            foodController.DeleteUserIngredient(3, DateTime.Now);

            userIngredientBusinessLogicMock.VerifyAll();
        }