public async Task E_Possivel_Invocar_a_Controller_Update() { var serviceMock = new Mock <IUserService>(); var nome = Faker.Name.FullName(); var email = Faker.Internet.Email(); serviceMock.Setup(m => m.Put(It.IsAny <UserDtoUpdate>())).ReturnsAsync( new UserDtoUpdateResult { Id = Guid.NewGuid(), Name = nome, Email = email, UpdateAt = DateTime.UtcNow } ); _controller = new UsersController(serviceMock.Object); var userDtoUpdate = new UserDtoUpdate { Id = Guid.NewGuid(), Name = nome, Email = email }; var result = await _controller.Put(userDtoUpdate); Assert.True(result is OkObjectResult); UserDtoUpdateResult resultValue = ((OkObjectResult)result).Value as UserDtoUpdateResult; Assert.NotNull(resultValue); Assert.Equal(userDtoUpdate.Name, resultValue.Name); Assert.Equal(userDtoUpdate.Email, resultValue.Email); }
public async Task <ActionResult> Put([FromBody] UserDtoUpdate user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UserDtoUpdateResult result = await _service.Put(user); if (result == null) { return(BadRequest()); } ResponseBase <UserDtoUpdateResult> responseBase = new ResponseBase <UserDtoUpdateResult>(); responseBase.Message = "Usuário alterado com sucesso!"; responseBase.Success = true; responseBase.Result = result; return(Ok(responseBase)); } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public TestUsers() { FakerId = Faker.RandomNumber.Next(); FakerName = Faker.Name.FullName(); FakerEmail = Faker.Internet.Email(); FakerNameUpdated = Faker.Name.FullName(); FakerEmailUpdated = Faker.Internet.Email(); for (int index = 0; index < 10; index++) { var dto = new UserDto() { Id = Faker.RandomNumber.Next(), Name = Faker.Name.FullName(), Email = Faker.Internet.Email() }; FakerUserDtoList.Add(dto); } FakerUserDto = new UserDto() { Id = FakerId, Name = FakerName, Email = FakerEmail }; FakerUserDtoCreate = new UserDtoCreate() { Name = FakerName, Email = FakerEmail }; FakerUserDtoCreateResult = new UserDtoCreateResult() { Id = FakerId, Name = FakerName, Email = FakerEmail, CreateAt = DateTime.UtcNow }; FakerUserDtoUpdate = new UserDtoUpdate() { Id = FakerId, Name = FakerName, Email = FakerEmail }; FakerUserDtoUpdateResult = new UserDtoUpdateResult() { Id = FakerId, Name = FakerName, Email = FakerEmail, UpdateAt = DateTime.UtcNow }; }
public UsuarioTestes() { IdUsuario = Guid.NewGuid(); NomeUsuario = Faker.Name.FullName(); EmailUsuario = Faker.Internet.Email(); NomeUsuarioAlterado = Faker.Name.FullName(); EmailUsuarioAlterado = Faker.Internet.Email(); for (int i = 0; i < 10; i++) { var dto = new UserDto() { Id = Guid.NewGuid(), Name = Faker.Name.FullName(), Email = Faker.Internet.Email() }; listaUserDto.Add(dto); } userDto = new UserDto { Id = IdUsuario, Name = NomeUsuario, Email = EmailUsuario }; userDtoCreate = new UserDtoCreate { Name = NomeUsuario, Email = EmailUsuario }; userDtoCreateResult = new UserDtoCreateResult { Id = IdUsuario, Name = NomeUsuario, Email = EmailUsuario, CreateAt = DateTime.UtcNow }; userDtoUpdate = new UserDtoUpdate { Id = IdUsuario, Name = NomeUsuarioAlterado, Email = EmailUsuarioAlterado }; userDtoUpdateResult = new UserDtoUpdateResult { Id = IdUsuario, Name = NomeUsuarioAlterado, Email = EmailUsuarioAlterado, UpdateAt = DateTime.UtcNow }; }
public UserTest() { UserId = Guid.NewGuid(); UserName = Faker.Name.FullName(); UserEmail = Faker.Internet.Email(); UserNameChanged = Faker.Name.FullName(); UserEmailChanged = Faker.Internet.Email(); for (int i = 0; i < 10; i++) { var dto = new UserDto() { Id = Guid.NewGuid(), Nome = Faker.Name.FullName(), Email = Faker.Internet.Email() }; UserList.Add(dto); } userDto = new UserDto { Id = UserId, Nome = UserName }; userDtoCreate = new UserDtoCreate { Nome = UserName, Email = UserEmail }; userDtoCreateResult = new UserDtoCreateResult { Id = UserId, Nome = UserName, Email = UserEmail, CreateAt = DateTime.UtcNow }; userDtoUpdate = new UserDtoUpdate { Id = UserId, Nome = UserName, Email = UserEmail }; userDtoUpdateResult = new UserDtoUpdateResult { Id = UserId, Nome = UserName, Email = UserEmail, CreateAt = DateTime.UtcNow }; }
public UserTest() { IdUser = Guid.NewGuid(); NomeUser = Faker.Name.FullName(); EmailUser = Faker.Internet.Email(); NomeUserUpdate = Faker.Name.FullName(); EmailUserUpdate = Faker.Internet.Email(); for (int i = 0; i < 10; i++) { var Dto = new UserDto() { Id = Guid.NewGuid(), Name = Faker.Name.FullName(), Email = Faker.Internet.Email(), }; listaDto.Add(Dto); } userDto = new UserDto { Id = IdUser, Name = NomeUser, Email = EmailUser }; userDtoCreate = new UserDtoCreate { Name = NomeUser, Email = EmailUser, }; userDtoCreateResult = new UserDtoCreateResult { Id = IdUser, Name = NomeUser, Email = EmailUser, CreateAt = DateTime.UtcNow }; userDtoUpdate = new UserDtoUpdate { Id = IdUser, Name = NomeUserUpdate, Email = EmailUserUpdate, }; userDtoUpdateResult = new UserDtoUpdateResult { Id = IdUser, Name = NomeUserUpdate, Email = EmailUserUpdate, UpdateAt = DateTime.UtcNow }; }
public UserTestes() { IdUser = Guid.NewGuid(); EmailUser = Faker.Internet.Email(); AlterEmailUser = Faker.Internet.Email(); NameUser = Faker.Name.FullName(); AlterNameUser = Faker.Name.FullName(); for (int i = 0; i < 10; i++) { var dto = new UserDto() { Id = Guid.NewGuid(), Name = Faker.Name.FullName(), Email = Faker.Internet.Email(), }; listUserDto.Add(dto); } userDto = new UserDto() { Id = IdUser, Name = NameUser, Email = EmailUser }; userDtoCreate = new UserDtoCreate() { Name = NameUser, Email = EmailUser }; userDtoCreateResult = new UserDtoCreateResult() { Id = IdUser, Name = NameUser, Email = EmailUser, CreateAt = DateTime.UtcNow }; userDtoUpdate = new UserDtoUpdate() { Name = NameUser, Email = EmailUser }; userDtoUpdateResult = new UserDtoUpdateResult() { Id = IdUser, Name = NameUser, Email = EmailUser, UpdateAt = DateTime.UtcNow }; }
public UserTests() { UserId = Guid.NewGuid(); UserName = Faker.Name.FullName(); UserEmail = Faker.Internet.Email(); UserNameUpdated = Faker.Name.FullName(); UserEmailUpdated = Faker.Internet.Email(); for (int i = 0; i < 10; i++) { userDtos.Add(new UserDto() { Id = Guid.NewGuid(), Name = Faker.Name.FullName(), Email = Faker.Internet.Email() }); } userDto = new UserDto() { Id = UserId, Name = UserName, Email = UserEmail }; userDtoCreate = new UserDtoCreate() { Name = UserName, Email = UserEmail }; userDtoCreateResult = new UserDtoCreateResult() { Id = UserId, Name = UserName, Email = UserEmail, CreatedAt = DateTime.Now }; userDtoUpdate = new UserDtoUpdate() { Id = UserId, Name = UserNameUpdated, Email = UserEmailUpdated }; userDtoUpdateResult = new UserDtoUpdateResult() { Id = UserId, Name = UserNameUpdated, Email = UserEmailUpdated, UpdatedAt = DateTime.Now }; }
public UserTests() { UserId = Guid.NewGuid(); Username = Faker.Name.FullName(); UserEmail = Faker.Internet.Email(); UpdatedUsername = Faker.Name.FullName(); UpdatedUserEmail = Faker.Internet.Email(); for (int i = 0; i < 10; i++) { var dto = new UserDto() { Name = Faker.Name.FullName(), Email = Faker.Internet.Email() }; listaUserDto.Add(dto); } userDto = new UserDto { Name = Username, Email = UserEmail }; userDtoCreateResult = new UserDtoCreateResult { Name = Username, Email = UserEmail, CreateAt = DateTime.UtcNow }; userDtoUpdateResult = new UserDtoUpdateResult { Name = UpdatedUsername, Email = UpdatedUserEmail, ModifiedAt = DateTime.UtcNow }; }
public async Task <ActionResult> Put([FromBody] UserDtoUpdate user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UserDtoUpdateResult result = await _service.Put(user); if (result != null) { return(Ok(result)); } else { return(BadRequest()); } } catch (ArgumentException ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }