상속: System.Entity
예제 #1
0
        public void shouldAddIngredientToCurrentUser()
        {
            var mockFactory = new MockFactory(MockBehavior.Loose);
            var userContextMock = GetSetuppedUserContextMock(mockFactory);

            var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>();
            var userIngredient = new UserIngredient {
                User = new User {Username = "******"},
                Ingredient = new Ingredient {Name = "Pannbiff"},
                Measure = 100
            };

            userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {userIngredient});
            userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.Is<User>(u => u.Username == "myUser"), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>())).Returns(userIngredient);

            var inputFoodModel = new InputFoodModel {Ingredient = "Pannbiff", Measure = 100, Date = DateTime.Now};
            var model = testController(x => x.Input(inputFoodModel), userIngredientBusinessLogicMock, userContextMock);

            Assert.That(model, Is.Not.Null);
            Assert.That(model.UserIngredients, Is.Not.Null);
            Assert.That(model.UserIngredients.Any(x => x.Ingredient.Name == "Pannbiff"));
            Assert.That(model.UserIngredients.Any(x => x.Measure == 100));

            userIngredientBusinessLogicMock.VerifyAll();
        }
 public UserIngredient AddUserIngredient(User user, string ingredientName, int measure, DateTime dateTime)
 {
     var userIngredient = new UserIngredient();
     userIngredient.User = user;
     userIngredient.Ingredient = GetExistingIngredient(ingredientName);
     userIngredient.Measure = measure;
     userIngredient.Date = dateTime.AddSeconds(1); // Otherwise it will show up on both today and yesterday
     return userIngredientRepository.SaveOrUpdate(userIngredient);
 }
 public IEnumerable<DateTime> getDatesfromuserIngredient(UserIngredient[] userIngredients)
 {
     var result = new List<DateTime>();
     foreach (var userIngredient in userIngredients) {
         var date = userIngredient.Date.Date;
         if (!result.Contains(date)) {
             result.Add(date);
         }
     }
     return result;
 }
        public void shouldGetCaloriesForActualMeasure()
        {
            var expectedKcal = 99;

            var ingredientSetup = new IngredientSetup();
            var ingredient = ingredientSetup.GetNewIngredient("Ärtor", NutrientEntity.EnergyInKcal, 33, 100);
            var userIngredient = new UserIngredient {Measure = 300, Ingredient = ingredient};

            var kcal = userIngredient.GetActualCalorieCount(x => x.GetNutrient(NutrientEntity.EnergyInKcal).Value);

            Assert.That(kcal, Is.EqualTo(expectedKcal));
        }
        private UserIngredient[] GetExpectedUserIngredients(DateTime date)
        {
            var ingredientSetup = new IngredientSetup();

            var userIngredients = new UserIngredient[4];
            userIngredients[0] = new UserIngredient { Ingredient = ingredientSetup.GetNewIngredient("Pannbiff", NutrientEntity.EnergyInKcal, 28, 100), Measure = 100, Date = date };
            userIngredients[1] = new UserIngredient {Ingredient = ingredientSetup.GetNewIngredient("Lök", NutrientEntity.EnergyInKcal, 25, 100), Measure = 150, Date = date};

            userIngredients[2] = new UserIngredient {Ingredient = ingredientSetup.GetNewIngredient("Lök", NutrientEntity.EnergyInKcal, 25, 100), Measure = 150, Date = date.AddDays(-100)};
            userIngredients[3] = new UserIngredient {Ingredient =  ingredientSetup.GetNewIngredient("Lök", NutrientEntity.EnergyInKcal, 27, 100), Measure = 150, Date = date.AddDays(-100)};
            return userIngredients;
        }