Exemplo n.º 1
0
        public async Task OnGetAsync_ReturnsPageResult_WhenUserUnAuthorized()
        {
            //Arrange
            var authorizationService = new Mock <IAuthorizationService>();

            authorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .ReturnsAsync(AuthorizationResult.Failed());

            var store = new Mock <IUserStore <IdentityUser> >();
            var mgr   = new Mock <UserManager <IdentityUser> >(store.Object, null, null, null, null, null, null, null, null);

            var pageModel = new CreateModel(AppDbContext, authorizationService.Object, mgr.Object);

            //Act
            var result = await pageModel.OnGetAsync();

            // Assert
            Assert.IsType <ForbidResult>(result);
        }