Exemple #1
0
        public void OneVegetarianDietWithSixMeals()
        {
            //Arrange
            DietService dietService = new DietService();;

            Dictionary <Diet, int> expectedDictionary = new Dictionary <Diet, int>();

            expectedDictionary.Add(Diet.VEGETARIAN, 6);

            List <Participant> participants = new List <Participant>();
            var bob = new Participant("Bob");

            bob.Diet = Diet.VEGETARIAN;
            participants.Add(bob);

            var participant2 = new ParticipantBuilder()
                               .WithName("BOB")
                               .WithDiet(Diet.VEGETARIAN)
                               .Build();

            //Act
            var result = dietService.AggregateToDictionary(participants);

            //Assert
            Assert.AreEqual(expectedDictionary[Diet.VEGETARIAN], result[Diet.VEGETARIAN]);
        }
        private DietService CreateDietService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new DietService(userId);

            return(service);
        }
        public IHttpActionResult GetId(int dietId)
        {
            DietService dietService = CreateDietService();
            var         diet        = dietService.GetDietById(dietId);

            return(Ok(diet));
        }
        public IHttpActionResult GetAll()
        {
            DietService dietService = CreateDietService();
            var         diets       = dietService.GetDiets();

            return(Ok(diets));
        }
Exemple #5
0
        private DietService DisplayDietService()
        {
            var userId      = User.Identity.GetUserId();
            var dietService = new DietService(userId);

            return(dietService);
        }
        // GET: Diet
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new DietService(userId);
            var model   = service.GetDiets();

            return(View(model));
        }
Exemple #7
0
        public void WhenNutritionistGoesToDietSection()
        {
            //Arrange
            dietRepositoryMock.Setup(r => r.ListAsync())
            .ReturnsAsync(new List <Diet> {
                diet
            });

            dietService = new DietService(dietRepositoryMock.Object, unitofworkMock.Object);
        }
Exemple #8
0
        public async Task GetByIdAsyncWhenInvalidIdReturnsDietNotFoundResponse()
        {
            // Arrange
            var mockDietRepository = GetDefaultIDietRepositoryInstance();
            var dietId             = 1;

            mockDietRepository.Setup(r => r.FindById(dietId))
            .Returns(Task.FromResult <Diet>(null));
            var mockUnitOfWork = GetDefaultIUnitOfWorkInstance();
            var service        = new DietService(mockDietRepository.Object, mockUnitOfWork.Object);
            // Act
            DietResponse result = await service.GetByIdAsync(dietId);

            var message = result.Message;

            // Assert
            message.Should().Be("Diet not found");
        }
Exemple #9
0
        public async Task ListAsyncWhenNoDietsReturnsEmptyCollection()
        {
            var mockDietRepository = GetDefaultIDietRepositoryInstance();

            mockDietRepository.Setup(r => r.ListAsync())
            .ReturnsAsync(new List <Diet>());
            var mockUnitOfWork = GetDefaultIUnitOfWorkInstance();
            var service        = new DietService(
                mockDietRepository.Object,
                mockUnitOfWork.Object);

            // Act
            List <Diet> result = (List <Diet>) await service.ListAsync();

            int dietsCount = result.Count;

            // Assert
            dietsCount.Should().Equals(0);
        }
Exemple #10
0
        public void GetDietAsycTest()
        {
            var dietParams            = GetDietParams();
            var profileRepositoryMock = new Mock <IProfileRepository>();
            var planRepositoryMock    = new Mock <IPlanRepository>();
            var foodRepositoryMock    = new Mock <IFoodRepository>();

            planRepositoryMock.Setup(p => p.GetAsync(dietParams.PlanId)).Returns(Task.FromResult(new Plan("P1", ActivityLevel.Sedentary, Goal.Maintain_Weight, 0, Pace.Normal, 0)));
            profileRepositoryMock.Setup(profile => profile.GetByUserIdAsync(dietParams.UserId)).Returns(Task.FromResult
                                                                                                            (new ProfileModel()
            {
                UserId     = 1,
                Age        = 28,
                Gender     = (int)Gender.Female,
                Height     = 160, //cm
                Weight     = 80,  //kg
                Id         = 1,
                IsPregnant = false,
                IsVeg      = true
            }));

            foodRepositoryMock.Setup(f => f.ListAsync()).Returns(Task.FromResult(
                                                                     new List <Food>()
            {
                new Food("Brown Rice (cooked)", (float)0.9, (float)2.6, (float)22.95, true, FoodCategory.Rice),
                new Food("Egg Noodles", (float)4.4, (float)14.2, (float)71.3, false, FoodCategory.Noodles),
                new Food("Rice Noodles(cooked)", (float)0.2, (float)0.9, (float)24.9, true, FoodCategory.Noodles),
                new Food("Roast Chicken", (float)7.75, (float)12.5, (float)0.5, false, FoodCategory.Meat),
                new Food("Fride Rice", 2, (float)4.7, 31, true, FoodCategory.Rice),
                new Food("Tuna Fish", 0, 25, 0, false, FoodCategory.Meat),
                new Food("Baked Fish", (float)2.6, (float)25.9, 0, false, FoodCategory.Meat),
                new Food("Fish Sandwich", (float)14.4, 19, 49, false, FoodCategory.Snack),
                new Food("Vegie Soup", (float)2.1, (float)1.1, (float)8.7, true, FoodCategory.Soup),
                new Food("String Hopper", 0, (float)3.6, (float)57.1, true, FoodCategory.Snack),
                new Food("Dhal Curry", (float)2.6, (float)2.5, (float)6.2, true, FoodCategory.Curry),
                new Food("Salad Leaves", (float)0.3, (float)1.5, (float)3.7, true, FoodCategory.Leaves),
                new Food("Baked Patatoes", (float)0.1, (float)2.5, (float)21.5, true, FoodCategory.Curry),
                new Food("Boiled Carrots", 0, (float)0.6, (float)8.2, true, FoodCategory.Curry),
                new Food("Carrot (cooked)", (float)0.1, (float)0.7, (float)6.7, true, FoodCategory.Curry),
                new Food("Carrot Salad", 11, 1, (float)9.4, true, FoodCategory.Leaves),
                new Food("Seafood pasta salad", 5, (float)3.9, (float)7.7, false, FoodCategory.Snack),
                new Food("Dried Mango Slices", 0, 0, 86, true, FoodCategory.Fruit),
                new Food("Avacado", 25, 5, 5, true, FoodCategory.Fruit),
                new Food("Avacado Ice Cream", 5, 0, 19, true, FoodCategory.Dissert),
                new Food("Garlic Bread", (float)16.6, (float)8.4, (float)41.7, true, FoodCategory.Snack),
                new Food("Banana Bread", (float)10.5, (float)5.4, (float)57.1, true, FoodCategory.Snack),
                new Food("Bread", (float)1.2, (float)7.7, 48, true, FoodCategory.Snack),
                new Food("Pumkin (cooked)", (float)1.8, (float)1.1, (float)7.9, true, FoodCategory.Curry),
                new Food("Beet (cooked)", (float)0.2, (float)1.7, 10, true, FoodCategory.Curry),
                new Food("Salmon", (float)13.4, (float)20.4, 0, false, FoodCategory.Meat),
                new Food("Banana", (float)0.3, (float)1.1, (float)22.8, true, FoodCategory.Fruit),
            }.AsEnumerable()));

            DietService service = new DietService(foodRepositoryMock.Object, planRepositoryMock.Object, profileRepositoryMock.Object);

            var output = service.GetDietAsyc(dietParams);

            Assert.NotNull(output.Result);
            Console.WriteLine("--------------BreakFirst--------------");
            foreach (var item in output.Result.FoodItems.Where(f => f.Type == DietType.Breakfast).Select(f => f.Name).ToList())
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("--------------Lunch--------------");
            foreach (var item in output.Result.FoodItems.Where(f => f.Type == DietType.Lunch).Select(f => f.Name).ToList())
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("--------------Dinner--------------");
            foreach (var item in output.Result.FoodItems.Where(f => f.Type == DietType.Dinner).Select(f => f.Name).ToList())
            {
                Console.WriteLine(item);
            }
        }
 public DietController(DietService dietService)
 {
     this.dietService = dietService;
 }
Exemple #12
0
 public void WhenNutritionistClicksToDeleteDiet()
 {
     dietRepositoryMock.Setup(r => r.Remove(diet));
     dietService = new DietService(dietRepositoryMock.Object, unitofworkMock.Object);
 }
Exemple #13
0
 public void WhenNutritionistFilledANewDietIncorrectly()
 {
     dietRepositoryMock.Setup(r => r.AddAsync(diet))
     .Throws(new ArgumentException("Error in data"));
     dietService = new DietService(dietRepositoryMock.Object, unitofworkMock.Object);
 }
Exemple #14
0
 public void WhenNutritionistFilledANewDiet()
 {
     dietRepositoryMock.Setup(r => r.AddAsync(diet));
     dietService = new DietService(dietRepositoryMock.Object, unitofworkMock.Object);
 }
 public DietController()
 {
     _dietService    = new DietService();
     _productService = new ProductService();
 }