Beispiel #1
0
        public async void AddClaimToRole_ReturnsOkResult()
        {
            var user = new ApplicationUser();

            this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(new ApplicationRole());

            this.roleManagerMock.Setup(r => r.AddClaimAsync(It.IsAny <ApplicationRole>(), It.IsAny <Claim>())).ReturnsAsync(IdentityResult.Success);

            var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object);

            var response = await controller.AddClaimToRole("menu", new RoleClaimPostRequest()
            {
                Name = "admin"
            }).ConfigureAwait(false);

            Assert.IsAssignableFrom <OkResult>(response);
        }
Beispiel #2
0
        public async void AddClaimToRole_ReturnsNotFoundResult()
        {
            var user = new ApplicationUser();

            this.roleManagerMock.Setup(r => r.FindByNameAsync(It.IsAny <string>())).ReturnsAsync((ApplicationRole)null);

            this.roleManagerMock.Setup(r => r.AddClaimAsync(It.IsAny <ApplicationRole>(), It.IsAny <Claim>())).ReturnsAsync(IdentityResult.Success);

            this.localizationMock.SetupGet(x => x.GetLocalizer <RoleController>()[Moq.It.IsAny <string>()]).Returns(new LocalizedString("sometext", "sometext"));

            var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object);

            var response = await controller.AddClaimToRole("menu", new RoleClaimPostRequest()
            {
                Name = "admin"
            }).ConfigureAwait(false);

            Assert.IsAssignableFrom <NotFoundObjectResult>(response);
        }