public void DeleteUser_NotFound(Guid id, string name, string email) { base.UsersRespositoryMock.Setup(x => x.FindSingle(It.IsAny <Expression <Func <User, bool> > >())).ReturnsAsync(value: default); var handler = new DeleteUserByIdCommandHandler(base.UnitOfWorkMock.Object); var result = handler.Handle(new DeleteUserByIdCommand(id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <bool> > >(result); Assert.AreEqual(StatusCodes.Status404NotFound, result.Result.StatusCode); }
public async Task GivenAnId_WhenDeleteUserByIdCommandHandler_ThenReturnTrue() { var user = UserFactory.ValidUser(); var command = new DeleteUserByIdCommand(user.Id); var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(db => db.DeleteAsync(command.Id).Result).Returns(true); var handler = new DeleteUserByIdCommandHandler(mockRepo.Object); var result = await handler.Handle(command, CancellationToken.None); result.Should().BeTrue(); }
public void DeleteUser_Successfully(Guid id, string name, string email) { base.UsersRespositoryMock.Setup(x => x.FindSingle(It.IsAny <Expression <Func <User, bool> > >())).ReturnsAsync(new User { Id = new Guid("f5d958ec-d760-4abe-bf3e-c8ba12c975e6"), Name = "", Email = "" }); base.UsersRespositoryMock.Setup(x => x.Remove(It.IsAny <Expression <Func <User, bool> > >())); var handler = new DeleteUserByIdCommandHandler(base.UnitOfWorkMock.Object); var result = handler.Handle(new DeleteUserByIdCommand(id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <bool> > >(result); Assert.AreEqual(StatusCodes.Status200OK, result.Result.StatusCode); }