AddUserIngredient() public method

public AddUserIngredient ( User user, string ingredientName, int measure, System.DateTime dateTime ) : UserIngredient
user CarbonFitness.Data.Model.User
ingredientName string
measure int
dateTime System.DateTime
return CarbonFitness.Data.Model.UserIngredient
コード例 #1
0
        public void shouldAddUserIngredient()
        {
            var measure = 100;
            var ingredientName = "Pannbiff";
            var ingredientMock = new Mock<Ingredient>();

            ingredientMock.Setup(x => x.Id).Returns(1);
            ingredientMock.Setup(x => x.Name).Returns(ingredientName);

            var userIngredientRepositoryMock = new Mock<IUserIngredientRepository>();
            var ingredientRepositoryMock = new Mock<IIngredientRepository>();
            userIngredientRepositoryMock.Setup(x => x.SaveOrUpdate(It.Is<UserIngredient>(y => y.Ingredient.Name == ingredientName && y.Ingredient.Id > 0 && y.Measure == measure && y.Date == todaysDate.AddSeconds(1)))).Returns(new UserIngredient());
            ingredientRepositoryMock.Setup(x => x.Get(ingredientName)).Returns(ingredientMock.Object);

            var userIngredientLogic = new UserIngredientBusinessLogic(userIngredientRepositoryMock.Object, ingredientRepositoryMock.Object, null);
            userIngredientLogic.AddUserIngredient(new User(), ingredientName, measure, todaysDate);

            userIngredientRepositoryMock.VerifyAll();
            ingredientRepositoryMock.VerifyAll();
        }
コード例 #2
0
        public void shouldNotBeAbleToAddAnIngredientThatDoesNotExistInTheDatabase()
        {
            const int measure = 100;
            const string ingredientName = "aaaabbbbbcccccddddd";

            var userIngredientRepositoryMock = new Mock<IUserIngredientRepository>(MockBehavior.Strict);
            var ingredientRepositoryMock = new Mock<IIngredientRepository>(MockBehavior.Strict);
            ingredientRepositoryMock.Setup(x => x.Get(ingredientName)).Returns((Ingredient) null);

            var userIngredientLogic = new UserIngredientBusinessLogic(userIngredientRepositoryMock.Object, ingredientRepositoryMock.Object, null);
            Assert.Throws<NoIngredientFoundException>(() => userIngredientLogic.AddUserIngredient(new User(), ingredientName, measure, DateTime.Now));

            userIngredientRepositoryMock.VerifyAll();
            ingredientRepositoryMock.VerifyAll();
        }