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();
        }
예제 #3
0
 public MealsControllerTest()
 {
     _mockService          = new MockMealService();
     _controller           = GetMealsController(_mockService, true);
     _controllerWithNoRole = GetMealsController(_mockService, false);
     _testFood             = new Food {
         Id = 1, Name = "Test Food"
     };
     _testMealFoodViewModel = new MealFoodViewModel {
         Food = _testFood, MealId = 1, SesshinId = 1
     };
 }
예제 #4
0
        private MealsController GetMealsController(MockMealService mockService, bool addRole)
        {
            var authService = MockAuthorizationService.BuildAuthorizationService(services =>
            {
                services.AddScoped <IMealService>(sp => mockService.Object);
                services.AddScoped <IAuthorizationHandler, AdminAuthorizationHandler>();
            });

            var controller = new MealsController(mockService.Object, authService);

            if (addRole)
            {
                MockAuthorizationService.SetupUserWithRole(controller, Constants.UserAdministratorsRole);
            }

            return(controller);
        }