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)); }
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")); }