public void Deve_atualizar_usuario_valido() { SetupSchoolingRepository(1); SetupUserRepository(1); var command = new UpdateUserCommand("Antonio", "Cesar", "*****@*****.**", new DateTime(1996, 10, 19), 1); command.Id = 1; var result = (GenericCommandResult)_updateUserHandler.Handle(command); Assert.True(result.Success); }
public async Task ShouldUpdateUser() { // Arrange using var scope = Factory.Services.CreateScope(); var updateUserModel = new UpdateUserModel { FirstName = "updated first name", LastName = "updated last name", }; var sut = new UpdateUserHandler(unitOfWork, mediator, mapper, currentUserServiceMock.Object); // Act GetPrivateUserModel sutResult = await sut.Handle(new UpdateUserCommand(updateUserModel), new CancellationToken(false)); // Assert Assert.NotNull(sutResult); var updatedUser = await unitOfWork.Users.GetEntityAsync(sutResult.Id); Assert.NotNull(updatedUser); Assert.False(updatedUser.Deleted); Assert.Equal(updatedUser.UserName, user.UserName); Assert.Equal(updatedUser.FirstName, updateUserModel.FirstName); Assert.Equal(updatedUser.LastName, updateUserModel.LastName); }
public async Task UpdateUserHandlerInvokesUpdateUserWithTheCorrectUser() { var options = this.CreateNewContextOptions(); const string userId = "12345"; const string firstName = "changed"; var message = new UpdateUser { User = new ApplicationUser { Id = userId, FirstName = firstName } }; using (var context = new AllReadyContext(options)) { context.Users.Add(new ApplicationUser { Id = userId, FirstName = "notChanged" }); await context.SaveChangesAsync(); } using (var context = new AllReadyContext(options)) { var sut = new UpdateUserHandler(context); await sut.Handle(message); } using (var context = new AllReadyContext(options)) { var user = context.Users.FirstOrDefault(u => u.Id == userId); Assert.NotNull(user); Assert.Equal(user.FirstName, firstName); } }
public async void SouldReturnSuccess_WhenCommandUpdateUserIsInvalid() { // arrange var(repo, context) = GetRepository(); var entity = new UserEntity { Email = "*****@*****.**", Name = "test1", Password = "******" }; _ = await repo.Save(entity); context.Entry(entity).State = EntityState.Detached; var comando = new UpdateUserCommand { Id = 1, Email = "*****@*****.**", Nome = "test2" }; var handler = new UpdateUserHandler(repo); // act _ = await handler.Handle(comando, CancellationToken.None); // assert //var result = await repo.GetById(comando.Id); var result = context.UserEntityDb.Find(comando.Id); Assert.Equal(comando.Email, result.Email); }
public async Task Update_user_handler_scenarios(Scenarios scenario) { var(request, expectedResponse, dependencies) = Fixture.SetupForScenario(scenario); var(mediator, userStoreFactory, cdnCachePurge) = dependencies; var sut = new UpdateUserHandler(mediator, userStoreFactory, cdnCachePurge); var response = await sut.Handle(request, default); Assert.IsTrue(response.IsEquivalentTo(expectedResponse)); }
public async Task UpdateUserHandlerInvokesUpdateUserWithTheCorrectUser() { var message = new UpdateUser { User = new ApplicationUser() }; var dataAccess = new Mock<IAllReadyDataAccess>(); var sut = new UpdateUserHandler(dataAccess.Object); await sut.Handle(message); dataAccess.Verify(x => x.UpdateUser(message.User), Times.Once); }
public async Task UpdateUserHandlerInvokesUpdateUserWithTheCorrectUser() { var message = new UpdateUser { User = new ApplicationUser() }; var dataAccess = new Mock <IAllReadyDataAccess>(); var sut = new UpdateUserHandler(dataAccess.Object); await sut.Handle(message); dataAccess.Verify(x => x.UpdateUser(message.User), Times.Once); }
public void ThrowsExceptionWhenUserDoesntExist() { var mock = Mock; mock.Setup(r => r.Get(It.IsAny <Guid>())).Returns <User>(null); var handler = new UpdateUserHandler(mock.Object); Action a = () => handler.Handle(Request, new System.Threading.CancellationToken()); a.Should().Throw <EntityNotFoundException>(); }
public void ThrowsExceptionWhenUserIsInactive() { var mock = Mock; mock.Setup(r => r.Get(It.IsAny <Guid>())).Returns(new User { IsActive = false }); var handler = new UpdateUserHandler(mock.Object); Action a = () => handler.Handle(Request, new System.Threading.CancellationToken()); a.Should().Throw <EntityInactiveException>(); }
public async Task Return_failed_result_when_validation_fails() { // Arrange var validator = Substitute.For <IValidateRequest <UpdateUser> >(); validator .IsValidAsync(Arg.Any <UpdateUser>()) .Returns(Task.FromResult(false)); var sut = new UpdateUserHandler(validator, _dbContext); // Act var result = await sut.Handle(new UpdateUser("a-sub", new UserRequest()), CancellationToken.None); // Assert result.IsFailure.ShouldBeTrue(); }
public void HandlerUpdatesUser() { var mock = Mock; var user = User; user.IsActive = true; var request = Request; mock.Setup(r => r.Get(It.IsAny <Guid>())).Returns(user); var handler = new UpdateUserHandler(mock.Object); handler.Handle(Request, new System.Threading.CancellationToken()); user.FirstName.Should().BeSameAs(request.FirstName); user.LastName.Should().BeSameAs(request.LastName); user.Email.Should().BeSameAs(request.Email); user.Username.Should().BeSameAs(request.Username); mock.Verify(r => r.Get(It.IsAny <Guid>()), Times.Once); }
public HttpResponseMessage Update(User user, string ticket) //done, should i check if only id recieved? { var securityProvider = new SecurityProvider(_connectionString); var sessionInfo = securityProvider.GetSessionInfo(ticket); if (sessionInfo == null) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } var updateRequest = new UpdateUserRequest { UserToUpdate = user, UserOrigin = sessionInfo.User, }; var handler = new UpdateUserHandler(_connectionString); var response = handler.Handle(updateRequest); var statusCode = ResolveStatusCode(response); return(Request.CreateResponse(statusCode, response)); }