Exemplo n.º 1
0
        public void ShouldNotCallHandleIfUserNotExist()
        {
            identityService.Setup(x => x.GetUserByUsernameAsync(user.UserName)).Returns(Task.FromResult((AppUser)null));

            DeleteUserCommandHandler deleteUserCommandHandler = new DeleteUserCommandHandler(identityService.Object, currentUserService, stringLocalizer.Object);
            DeleteUserCommand        deleteUserCommand        = new DeleteUserCommand(user.UserName);

            Func <Task> act = async() => await deleteUserCommandHandler.Handle(deleteUserCommand, new CancellationToken());

            act.Should().ThrowAsync <NotFoundException>();
        }
Exemplo n.º 2
0
        public async Task ShouldCallHandle()
        {
            identityService.Setup(x => x.GetUserByUsernameAsync(user.UserName)).Returns(Task.FromResult(user));
            identityService.Setup(x => x.DeleteUserAsync(user.UserName)).Returns(Task.FromResult(Result.Success()));

            DeleteUserCommandHandler deleteUserCommandHandler = new DeleteUserCommandHandler(identityService.Object, currentUserService, stringLocalizer.Object);
            DeleteUserCommand        deleteUserCommand        = new DeleteUserCommand(user.UserName);

            var result = await deleteUserCommandHandler.Handle(deleteUserCommand, new CancellationToken());

            result.Succeeded.Should().BeTrue();
        }
Exemplo n.º 3
0
        public async Task Handler_should_throw_exception_if_dependency_is_null()
        {
            //Arrage

            //Act
            void Act()
            {
                var command = new DeleteUserCommandHandler(null);
            }

            //Assert
            Assert.Throws <ArgumentNullException>(Act);
        }
Exemplo n.º 4
0
        public void ShouldNotCallHandleIfCurrentUserNotMatch()
        {
            user.UserName = It.IsAny <string>();
            identityService.Setup(x => x.GetUserByUsernameAsync(user.UserName)).Returns(Task.FromResult(user));
            identityService.Setup(x => x.DeleteUserAsync(user.UserName)).Returns(Task.FromResult(Result.Success()));

            DeleteUserCommandHandler deleteUserCommandHandler = new DeleteUserCommandHandler(identityService.Object, currentUserService, stringLocalizer.Object);
            DeleteUserCommand        deleteUserCommand        = new DeleteUserCommand(user.UserName);

            Func <Task> act = async() => await deleteUserCommandHandler.Handle(deleteUserCommand, new CancellationToken());

            act.Should().ThrowAsync <RestException>();
        }
        public void DeleteUser_CalluserRepositoryRemove(
            [Frozen] IUserRepository userRepository,
            DeleteUserCommand message,
            User user,
            DeleteUserCommandHandler deleteUserCommandHandler)
        {
            //Information
            A.CallTo(() => userRepository.GetById(message.UserId)).Returns(user);

            //Act
            deleteUserCommandHandler.ExecuteAsync(message);

            //Test
            A.CallTo(() => userRepository.Remove(user)).MustHaveHappened();
        }
Exemplo n.º 6
0
        public void Arrange()
        {
            _userRepository = new Mock <IUserRepository>();

            _auditService = new Mock <IAuditService>();

            _handler = new DeleteUserCommandHandler(_userRepository.Object, _auditService.Object);

            _command = new DeleteUserCommand
            {
                User = new User
                {
                    Id = UserId
                }
            };
        }
Exemplo n.º 7
0
        public async Task RemoveUserFromUserManager()
        {
            await LoadTestData();

            // arrange
            var handler = new DeleteUserCommandHandler(Context, UserManager);
            var userId  = "foo_id";

            // act
            await handler.Handle(new DeleteUserCommand { UserId = userId });

            // assert
            var user = await UserManager.FindByIdAsync(userId);

            Assert.Null(user);
        }
        public async Task RemoveUserFromUserManager()
        {
            await LoadTestData();
            
            // arrange
            var handler = new DeleteUserCommandHandler(Context, UserManager);
            var userId = "foo_id";

            // act
            await handler.Handle(new DeleteUserCommand { UserId = userId });

            // assert
            var user = await UserManager.FindByIdAsync(userId);
            Assert.Null(user);


        }
Exemplo n.º 9
0
 public UserController(
     CreateUserCommandHandler createCommand,
     GetAllUsersQuery getAllQuery,
     GetUserQuery getOneQuery,
     DownloadPhotoQuery getPhotoQuery,
     SessionQuery sessionQuery,
     UpdateUserCommandHandler updateCommand,
     DeleteUserCommandHandler deleteCommand)
 {
     this.createCommand = createCommand;
     this.getAllQuery   = getAllQuery;
     this.getOneQuery   = getOneQuery;
     this.getPhotoQuery = getPhotoQuery;
     this.sessionQuery  = sessionQuery;
     this.updateCommand = updateCommand;
     this.deleteCommand = deleteCommand;
 }
Exemplo n.º 10
0
        public async Task Handler_should_throw_not_found_exception_if_user_doesnt_exist()
        {
            //Arrange
            var userId = Guid.NewGuid().ToString();

            _userManagerMock.Setup(x => x.FindByIdAsync(userId)).Returns(Task.FromResult <User>(null));

            var cancellationToken = new CancellationToken();
            var command           = new DeleteUserCommand(userId);
            var handler           =
                new DeleteUserCommandHandler(_userManagerMock.Object);

            //Act
            Task Act() => handler.Handle(command, cancellationToken);

            //Assert
            await Assert.ThrowsAsync <UserNotFoundException>(Act);
        }
Exemplo n.º 11
0
        public void DeleteNonExistingUserTest()
        {
            Users.Add(new User()
            {
                Id       = 1,
                Name     = "john",
                Password = "******",
                Mail     = "*****@*****.**"
            });
            Context.SaveChanges();
            var command = new DeleteUserCommand()
            {
                Id = 2
            };
            var handler = new DeleteUserCommandHandler(Context, new ImageRepository());

            Assert.Single(Users);
        }
Exemplo n.º 12
0
        public async void DeleteExistingUserTest()
        {
            Users.Add(new User()
            {
                Id       = 1,
                Name     = "john",
                Password = "******",
                Mail     = "*****@*****.**"
            });
            var command = new DeleteUserCommand()
            {
                Id = 1
            };
            var handler = new DeleteUserCommandHandler(Context, new ImageRepository());

            await handler.Handle(command, CancellationToken.None);

            Assert.Empty(Users);
        }
        public async Task UserStatusIsActive_Executed_InactivateUser()
        {
            //Arrange
            var userRepositoryMock = new Mock <IUserRepository>();

            var user = new User("usuário de teste", "*****@*****.**", Convert.ToDateTime("15/12/1993"), "123456", "client");
            var id   = 4;

            var deleteUserCommand        = new DeleteUserCommand(id);
            var deleteUserCommandHandler = new DeleteUserCommandHandler(userRepositoryMock.Object);

            userRepositoryMock.Setup(u => u.GetByIdAsync(id).Result).Returns(user);


            //Act
            await deleteUserCommandHandler.Handle(deleteUserCommand, new CancellationToken());

            //Assert
            userRepositoryMock.Verify(u => u.SaveChangesAsync(), Times.Once);
        }
        public async Task DeleteUserHandler_Should_Delete_User()
        {
            // Arrange...
            var unitOfWork = GetUnitOfWork(out var inMemoryContext);
            var user       = _fixture.Create <User>();

            InMemoryContextHelper.AddUserToContext(inMemoryContext, user);
            var sut = new DeleteUserCommandHandler(unitOfWork);
            var deleteUserCommand = new DeleteUserCommand
            {
                Id = user.Id
            };
            var ct = new CancellationToken();

            // Act...
            await sut.Handle(deleteUserCommand, ct);

            // Assert...
            inMemoryContext.Users.Count().Should().Be(0);
        }
Exemplo n.º 15
0
        public async Task Handler_should_return_true()
        {
            //Arrange
            var fakeUser = new User
            {
                Id = Guid.NewGuid().ToString()
            };

            _userManagerMock.Setup(x => x.FindByIdAsync(fakeUser.Id)).Returns(Task.FromResult <User>(fakeUser));
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(false));

            var cancellationToken = new CancellationToken();
            var command           = new DeleteUserCommand(fakeUser.Id);
            var handler           =
                new DeleteUserCommandHandler(_userManagerMock.Object);

            //Act
            var result = await handler.Handle(command, cancellationToken);

            //Assert
            Assert.True(result);
        }
Exemplo n.º 16
0
        public async Task Handler_should_throw_unable_to_change_state_exception_if_user_is_supervisor()
        {
            //Arrange
            var fakeUser = new User
            {
                Id = Guid.NewGuid().ToString()
            };


            _userManagerMock.Setup(x => x.FindByIdAsync(fakeUser.Id)).Returns(Task.FromResult <User>(fakeUser));
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(true));

            var cancellationToken = new CancellationToken();
            var command           = new DeleteUserCommand(fakeUser.Id);
            var handler           =
                new DeleteUserCommandHandler(_userManagerMock.Object);

            //Act
            Task Act() => handler.Handle(command, cancellationToken);

            //Assert
            await Assert.ThrowsAsync <UserUnableToChangeStateException>(Act);
        }
Exemplo n.º 17
0
        public async Task Handler_should_delete_user_if_not_supervisor()
        {
            //Arrange
            var fakeUser = new User
            {
                Id = Guid.NewGuid().ToString(),
            };


            _userManagerMock.Setup(x => x.FindByIdAsync(fakeUser.Id)).Returns(Task.FromResult <User>(fakeUser));
            _userManagerMock.Setup(x => x.IsInRoleAsync(fakeUser, AuthSettings.Roles.Supervisor))
            .Returns(Task.FromResult(false));

            var cancellationToken = new CancellationToken();
            var command           = new DeleteUserCommand(fakeUser.Id);
            var handler           =
                new DeleteUserCommandHandler(_userManagerMock.Object);

            //Act
            var result = await handler.Handle(command, cancellationToken);

            //Assert
            _userManagerMock.Verify(x => x.DeleteAsync(It.Is <User>(it => it == fakeUser)), Times.Once);
        }
Exemplo n.º 18
0
 public DeleteUserCommandHandlerTests()
 {
     this.mediator = new Mock <IMediator>();
     this.sut      = new DeleteUserCommandHandler(this.Context, this.mediator.Object);
 }
Exemplo n.º 19
0
 public DeleteUserCommandHandlerTest()
 {
     UserRepository           = new Mock <IUserRepository>();
     DeleteUserCommandHandler = new DeleteUserCommandHandler(UserRepository.Object);
 }
 public DeleteUserController(DeleteUserCommandHandler deleteUserCommandHandler)
 {
     _deleteUserCommandHandler = deleteUserCommandHandler;
 }
 public DeleteUserCommantTest() : base()
 {
     deleteUserCommandHandler = new DeleteUserCommandHandler(usersContext);
 }
Exemplo n.º 22
0
 public DeleteUserCommandTests()
 {
     _sut = new DeleteUserCommandHandler(DbContext);
 }