Ejemplo n.º 1
0
        public async Task RemoveFromRoleAsyncShould_ReturnsFalseWhen_UserIsNotInRole()
        {
            const string Role = "Manager";

            //Arrange
            var admin = UserCreator.Create();
            var user  = UserCreator.Create();

            await Db.Users.AddRangeAsync(admin, user);

            await Db.SaveChangesAsync();

            var userManagerMock = UserManagerMock.New;

            userManagerMock.Setup(u => u.FindByIdAsync(user.Id)).Returns(Task.FromResult(user));
            userManagerMock.Setup(u => u.IsInRoleAsync(user, Role)).Returns(Task.FromResult(false));

            //TODO: rewrite this test (now there is no need for userManager)
            var service = new AdminUserService(Db, null);

            //Act
            var result = await service.RemoveFromRoleAsync(admin.Id, user.Id, Role);

            //Assert
            result.Should().Be(false);
        }
Ejemplo n.º 2
0
        public async Task RemoveFromRoleAsyncShould_ReturnsTrueWhen_UserIsInRole()
        {
            const string Role = "Manager";

            //Arrange
            var admin = UserCreator.Create();
            var user  = UserCreator.Create();

            await Db.Users.AddRangeAsync(admin, user);

            await Db.SaveChangesAsync();

            var userManagerMock = UserManagerMock.New;

            userManagerMock.Setup(u => u.FindByIdAsync(user.Id)).Returns(Task.FromResult(user));
            userManagerMock.Setup(u => u.IsInRoleAsync(user, Role)).Returns(Task.FromResult(true));

            await userManagerMock.Object.AddToRoleAsync(user, Role);

            var activityService = new Mock <IAdminActivityService>();

            //TODO: rewrite this test (now there is no need for userManager)
            var service = new AdminUserService(Db, activityService.Object);

            //Act
            var result = await service.RemoveFromRoleAsync(admin.Id, user.Id, Role);

            //Assert
            result.Should().BeTrue();

            activityService.Verify(a =>
                                   a.WriteInfoAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), AdminActivityType.RemovedFromRole),
                                   Times.Once);
        }