public async Task _testSesshinIndexAsync()
        {
            // Arrange
            var sesshins = new Sesshin[] {
                new Sesshin {
                    Id = 1, Name = "Winter sesshin", Description = "Night sesshin in Yujio Nyusanji", StartDate = new DateTime(2019, 12, 27), EndDate = new DateTime(2020, 01, 01), AppUserId = "userId"
                },
                new Sesshin {
                    Id = 2, Name = "Autumn sesshin", Description = "Autumn sesshin in Yujio Nyusanji", StartDate = new DateTime(2019, 12, 27), EndDate = new DateTime(2020, 01, 01), AppUserId = "userId"
                },
                new Sesshin {
                    Id = 3, Name = "End of Winter sesshin", Description = "End of Winter sesshin in Yujio Nyusanji", StartDate = new DateTime(2019, 12, 27), EndDate = new DateTime(2020, 01, 01), AppUserId = "userId"
                },
                new Sesshin {
                    Id = 4, Name = "Summertime sesshin", Description = "Summertime sesshin in Yujio Nyusanji", StartDate = new DateTime(2019, 12, 27), EndDate = new DateTime(2020, 01, 01), AppUserId = "userId"
                },
                new Sesshin {
                    Id = 5, Name = "Summer camp", Description = "Ango in Yujio Nyusanji", StartDate = new DateTime(2019, 12, 27), EndDate = new DateTime(2020, 01, 01), AppUserId = "userId"
                }
            };

            _mockService.MockListAsync(sesshins);

            // Act
            var result = await _controller.Index();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Sesshin> >(viewResult.ViewData.Model);

            Assert.Equal(5, model.Count());
        }
Example #2
0
        internal MockSesshinService MockGetByIdAsync(int testSesshinId, Sesshin testSesshin)
        {
            Setup(service => service.GetByIdAsync(testSesshinId))
            .ReturnsAsync(testSesshin);

            return(this);
        }
Example #3
0
        internal MockSesshinService MockEditAsync(Sesshin testSesshin)
        {
            Setup(service => service.EditAsync(testSesshin))
            .Returns(Task.CompletedTask)
            .Verifiable();

            return(this);
        }
Example #4
0
        internal MockSesshinService MockCreateAsync(Sesshin testSesshin)
        {
            Setup(service => service.CreateAsync(It.IsAny <Sesshin>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            return(this);
        }
Example #5
0
        private static async Task CompleteSecondPreparationDay(Sesshin newYearSesshin, ProductContext productContext)
        {
            DayOfSesshin secondDayPreparation = newYearSesshin.Days.FirstOrDefault(d => d.Date == new DateTime(2019, 12, 29));
            Meal         lunch = CompleteSecondDayPreparationLunch(secondDayPreparation, productContext);
            Meal         diner = CompleteSecondDayPreparationDiner(secondDayPreparation, productContext);

            await productContext.SaveChangesAsync();
        }
Example #6
0
        private static async Task CompleteSesshinDay(Sesshin newYearSesshin, ProductContext productContext)
        {
            DayOfSesshin sesshinDay = newYearSesshin.Days.FirstOrDefault(d => d.Date == new DateTime(2019, 12, 30));
            Meal         lunch      = CompleteSesshinDayLunch(sesshinDay, productContext);
            Meal         diner      = CompleteSesshinDayDiner(sesshinDay, productContext);

            await productContext.SaveChangesAsync();
        }
Example #7
0
        private static async Task CompleteLastDay(Sesshin newYearSesshin, ProductContext productContext)
        {
            //First Meal: Split pea soup + potatoes
            DayOfSesshin lastDay   = newYearSesshin.Days.FirstOrDefault(d => d.Date == new DateTime(2020, 01, 01));
            Meal         breakfast = CompleteLastDayBreakfast(lastDay, productContext);
            Meal         lunch     = CompleteLastDayLunch(lastDay, productContext);

            await productContext.SaveChangesAsync();
        }
Example #8
0
 private static async Task CreateNewYearMeal(Sesshin newYearSesshin, ProductContext productContext)
 {
     await CompleteComingDayDiner(newYearSesshin, productContext);
     await CompleteFirstPreparationDay(newYearSesshin, productContext);
     await CompleteSecondPreparationDay(newYearSesshin, productContext);
     await CompleteSesshinDay(newYearSesshin, productContext);
     await CompleteRestDay(newYearSesshin, productContext);
     await CompleteLastDay(newYearSesshin, productContext);
 }
Example #9
0
        private static async Task CompleteFirstPreparationDay(Sesshin newYearSesshin, ProductContext productContext)
        {
            //First Meal: Split pea soup + potatoes
            DayOfSesshin firstDayPreparation = newYearSesshin.Days.FirstOrDefault(d => d.Date == new DateTime(2019, 12, 28));
            Meal         breakfast           = CompleteFirstDayPreparationBreakfast(firstDayPreparation, productContext);
            Meal         lunch = CompleteFirstDayPreparationLunch(firstDayPreparation, productContext);
            Meal         diner = CompleteFirstDayPreparationDiner(firstDayPreparation, productContext);

            await productContext.SaveChangesAsync();
        }
 public SesshinControllerTest()
 {
     _testSesshin = new Sesshin
     {
         Id          = _testSesshinId,
         Name        = "Winter sesshin",
         Description = "Night sesshin in Yujio Nyusanji",
         StartDate   = new DateTime(2019, 12, 27),
         EndDate     = new DateTime(2020, 01, 01),
         AppUserId   = "userId"
     };
     _mockService = new MockSesshinService();
     _controller  = GetSesshinsController(_mockService);
 }
Example #11
0
        private static async Task CreateSesshin(ProductContext productContext, AppIdentityContext identityContext)
        {
            AppUser chef    = identityContext.Users.FirstOrDefault(usr => usr.Email == "*****@*****.**");
            Sesshin newYear = new Sesshin {
                AppUserId = chef.Id, Name = "New Year 2019", Description = "Until the end of the night!!!", StartDate = new DateTime(2019, 12, 28), EndDate = new DateTime(2020, 01, 01), NumberOfPeople = 90
            };

            //Create the genmai food that will be used after
            await AddGenMaiFood(productContext);

            SesshinService sesshinService = new SesshinService(new EFSesshinRepository(productContext), new EFFoodRepository(productContext), new EFDayOfSesshinRepository(productContext), new UnitOfWork(productContext));
            await sesshinService.CreateAsync(newYear);

            //Add Food For Sesshins
            await CreateNewYearMeal(newYear, productContext);
        }
Example #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,NumberOfPeople,Description,StartDate,EndDate,AppUserId")] Sesshin sesshin, bool fromDetail)
        {
            if (id != sesshin.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var isAuthorized = await _authorizationService.AuthorizeAsync(User, sesshin, UserOperations.Update);

                    if (isAuthorized.Succeeded)
                    {
                        await _sesshinService.EditAsync(sesshin);
                    }
                    else
                    {
                        return(new ChallengeResult());
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    var exists = await SesshinExists(id);

                    if (!exists)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (fromDetail)
                {
                    return(RedirectToAction(nameof(Details), new { id = id }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(sesshin));
        }
Example #13
0
        private static async Task CompleteComingDayDiner(Sesshin newYearSesshin, ProductContext productContext)
        {
            //First Meal: Split pea soup + potatoes
            DayOfSesshin comingDay      = newYearSesshin.Days.FirstOrDefault(d => d.Date == new DateTime(2019, 12, 27));
            Meal         comingDayDiner = comingDay.Meals.FirstOrDefault(m => m.Type == MealType.Diner);

            comingDayDiner.MealFoods = new List <MealFood>();

            comingDayDiner.MealFoods.Add(new MealFood {
                Meal = comingDayDiner, Food = SplitPeaSoup(productContext)
            });
            comingDayDiner.MealFoods.Add(new MealFood {
                Meal = comingDayDiner, Food = RoastedPotatoes(productContext)
            });
            AddSimpleFoodToMeal("Banana", 90M, UnityType.Unity, comingDayDiner, productContext);

            await productContext.SaveChangesAsync();
        }
Example #14
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,StartDate,EndDate,AppUserId")] Sesshin sesshin)
        {
            if (ModelState.IsValid)
            {
                var isAuthorized = await _authorizationService.AuthorizeAsync(User, sesshin, UserOperations.Create);

                if (isAuthorized.Succeeded)
                {
                    await _sesshinService.CreateAsync(sesshin);

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(new ChallengeResult());
                }
            }
            return(View(sesshin));
        }
Example #15
0
        public string GetMealSesshinOwner(int mealId)
        {
            Sesshin sesshin = _context.Sesshin.FromSql("SESSHIN_FIND_BY_MEAL_ID @p0", mealId).FirstOrDefault();

            return(sesshin.AppUserId);
        }
 private bool IsAuthorizedSesshinOperation(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, Sesshin sesshin)
 {
     //Any chef can create sesshin
     if (requirement.Name == Constants.CreateOperationName || requirement.Name == Constants.ReadOperationName)
     {
         return(true);
     }
     //Otherwise you should be the sesshin chef
     else if (sesshin.AppUserId == _userManager.GetUserId(context.User))
     {
         return(true);
     }
     return(false);
 }