Beispiel #1
0
 private void clearUserIngredients()
 {
     var repository = new UserIngredientRepository();
     var userIngredients = new UserIngredientRepository().GetAll();
     foreach (var userIngredient in userIngredients) {
         repository.Delete(userIngredient);
     }
     NHibernateSession.Current.Flush();
 }
        public void shouldHaveFatHistory()
        {
            Browser.GoTo(Url + "/?graphlines=" + NutrientEntity.FatInG);

            var userIngredients = new UserIngredientRepository().GetUserIngredientsByUser(UserId, Now, Now.AddDays(1));
            decimal sum = userIngredients.Sum(u => u.GetActualCalorieCount(x => x.GetNutrient(NutrientEntity.FatInG).Value));

            var chartSumOfFatValue = ">" + String.Format("{0:0.00000}", sum) + "</VALUE>";
            chartSumOfFatValue = chartSumOfFatValue.Replace(",", ".");

            Assert.That(Browser.Html, Contains.Substring(chartSumOfFatValue));
        }
        public void shouldGetUserIngredientsFromUserId()
        {
            var repository = new UserIngredientRepository();

            var userIngredients = repository.GetUserIngredientsByUser(user.Id, now, now.AddDays(1));

            Assert.That(userIngredients, Is.Not.Null);
            Assert.That(userIngredients.Length, Is.EqualTo(2));
            Assert.That(userIngredients[0].Ingredient, Is.Not.Null);
            Assert.That(userIngredients[0].Ingredient.Name, Is.EqualTo("Pannbiff"));
            Assert.That(userIngredients[0].Date, Is.EqualTo(now));
            Assert.That(userIngredients[0].User.Id, Is.EqualTo(user.Id));
        }
        public void shouldHaveCalorieHistory()
        {
            Browser.GoTo(Url + "/?graphlines=" + NutrientEntity.EnergyInKcal);

            var userIngredients = new UserIngredientRepository().GetUserIngredientsByUser(UserId, Now, Now.AddDays(1));
            decimal sum = userIngredients.Sum(u => u.Ingredient.GetNutrient(NutrientEntity.EnergyInKcal).Value * (u.Measure / u.Ingredient.WeightInG));

            var chartSumOfCalorieValue = ">" + String.Format("{0:0.00000}", sum) + "</VALUE>";
            chartSumOfCalorieValue = chartSumOfCalorieValue.Replace(",", ".");

            Assert.That(Browser.Html, Contains.Substring(chartSumOfCalorieValue));
            Assert.That(Browser.Html, Contains.Substring(Now.ToShortDateString() + "</VALUE>"));
            Assert.That(Browser.Html, !Contains.Substring(","));
        }
        protected override void LoadTestData()
        {
            var ingredientRepository = new IngredientRepository();
            ingredient = ingredientRepository.SaveOrUpdate(new Ingredient {Name = "Pannbiff"});

            user = new UserRepository().Save(new User { Username = "******" });
            user2 = new UserRepository().Save(new User { Username = "******" });
            var user3 = new UserRepository().Save(new User { Username = "******" });
            NHibernateSession.Current.Flush();

            var userIngredientRepository = new UserIngredientRepository();

            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 10, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 100, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 200, User = user, Date = now.AddDays(-1)});

            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 10, User = user2, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 100, User = user3, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 200, User = user2, Date = now.AddDays(-1) });

            NHibernateSession.Current.Flush();
        }
 public void shouldSaveUserIngredient()
 {
     var repository = new UserIngredientRepository();
     var userIngredient = repository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 100, User = user, Date = now.AddDays(-1)});
     Assert.That(userIngredient.Id, Is.GreaterThan(0));
 }