public async Task ChefAuthorization_ShowAllowStockCreateWhenChef()
        {
            //Arrange
            Meal meal = new Meal
            {
                Id             = 1,
                DayOfSesshinId = 1,
                Type           = MealType.Breakfast
            };
            var             userManager = MockIdentity.MockUserManager <AppUser>().Object;
            MockMealService mockMeal    = new MockMealService();

            mockMeal.MockGetById(meal);
            mockMeal.MockGetSesshinOwner("1");
            MockSesshinService mockSesshin = new MockSesshinService();
            var authorizationService       = MockAuthorizationService.BuildAuthorizationService(services =>
            {
                services.AddScoped <IMealService>(sp => mockMeal.Object);
                services.AddScoped <IAuthorizationHandler>(sp => new ChefAuthorizationHandler(userManager, mockMeal.Object, mockSesshin.Object));
            });
            var user = new ClaimsPrincipal(
                new ClaimsIdentity(
                    new Claim[] {
                new Claim(ClaimTypes.Name, "homer.simpson"),
                new Claim(ClaimTypes.Role, Constants.UserChefRole),
                new Claim("AccountStatus", "Approved")
            }));

            //Act
            var allowed = await authorizationService.AuthorizeAsync(user, new Stock(), UserOperations.Create);

            // Assert
            Assert.True(allowed.Succeeded);
        }
        public SesshinChefAuthorizationServiceTest()
        {
            _userManager    = new MockUserManager();
            _mealService    = new MockMealService();
            _sesshinService = new MockSesshinService();

            _authorizationService = MockAuthorizationService.BuildAuthorizationService(services =>
            {
                services.AddScoped <IAuthorizationHandler>(sp => new ChefAuthorizationHandler(_userManager.Object, _mealService.Object, _sesshinService.Object));
            });
            _user = new TestClaimsPrincipal();
        }
        private SesshinsController GetSesshinsController(MockSesshinService mockSesshin)
        {
            var authService = MockAuthorizationService.BuildAuthorizationService(services =>
            {
                services.AddScoped <ISesshinService>(sp => mockSesshin.Object);
                services.AddScoped <IAuthorizationHandler, AdminAuthorizationHandler>();
            });

            var controller = new SesshinsController(mockSesshin.Object, authService);

            MockAuthorizationService.SetupUserWithRole(controller, Constants.UserAdministratorsRole);

            return(controller);
        }
 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);
 }