public async Task TestUpdateUserOkResponse() { // Arrange const string expectedUserId = "expectedUserId"; var request = new PutUserRequest { Email = "*****@*****.**" }; var user = new MeUser { UserId = expectedUserId, Email = "*****@*****.**" }; _userUpdateService.Setup(up => up.Handle(It.IsAny <UserUpdateQuery>())) .Returns(Task.FromResult(user)); Controller.ControllerContext = GetControllerContext(); // Act var response = await Controller.UpdateUser(It.IsAny <string>(), request); // Assert response.Result.Should().BeAssignableTo <OkObjectResult>(); var result = (OkObjectResult)response.Result; result.Value.Should().BeAssignableTo <PutUserResponse>(); var model = (PutUserResponse)result.Value; model.Errors.Count.Should().Be(0); model.Success.Should().BeTrue(); model.UserId.Should().Be(expectedUserId); }
static async Task RunUpdateUserCommandAsync() { Console.WriteLine("Fill in new user details"); Console.WriteLine("ID:"); int id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("First name:"); var firstName = Console.ReadLine(); Console.WriteLine("Last name:"); var lastName = Console.ReadLine(); Console.WriteLine("Age:"); var age = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Email:"); var email = Console.ReadLine(); var user = new PutUserRequest() { FirstName = firstName, LastName = lastName, Age = age, Email = email }; Console.WriteLine("Loading..."); await _httpService.UpdateUserAsync(id, user); Console.WriteLine("User successfully updated"); }
public async Task UpdateUserAsync(int id, PutUserRequest user) { var json = JsonConvert.SerializeObject(user); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PutAsync($"{baseUserAPIURL}/{id}", content); if (!response.IsSuccessStatusCode) { throw new HttpServiceException("Service error"); } }
public ActionResult <Models.User> Post([FromBody] PutUserRequest value) { var response = _mediator.Send(value).GetAwaiter().GetResult(); if (response != null) { return(Created(Request.QueryString.Value, response)); } else { return(BadRequest("Post Failed but no error raised")); } }
public void TestPutUserRequest() { var expectedEmail = "*****@*****.**"; var user = new PutUserRequest { Email = expectedEmail }; var response = _mapper.Map <MeUser>(user); response.Email.Should().Be(expectedEmail); }
public PutUserResponse Put(PutUserRequest request) { var model = request.Data.ToServiceModel(); if (request.Id.HasValue) { model.Id = request.Id.Value; } var user = userService.SaveUser(model, false, true); return(new PutUserResponse { Data = user.Id }); }
public async Task <ActionResult <IEnumerable <User> > > Put(PutUserRequest putUserRequest) { var putUserResponse = await _mediator.Send(new PutUserCommand(putUserRequest.Id, putUserRequest.Nome, putUserRequest.CPF, putUserRequest.Email, putUserRequest.Telefone, putUserRequest.Sexo, putUserRequest.DataNascimento, putUserRequest.UserGithub)); if (putUserResponse == null) { return(NotFound()); } return(Ok(putUserResponse)); }
public async Task TestUpdateUserVerificationFailure() { // Arrange Controller.ModelState.AddModelError("An", "Error"); // Act var request = new PutUserRequest(); var response = await Controller.UpdateUser(It.IsAny <string>(), request); // Assert response.Result.Should().BeAssignableTo <BadRequestObjectResult>(); var result = (BadRequestObjectResult)response.Result; result.Value.Should().BeAssignableTo <PutUserResponse>(); var model = (PutUserResponse)result.Value; model.Errors.Count.Should().Be(1); model.Success.Should().BeFalse(); }
public async Task TestUpdateUserDocumentClientException() { // Arrange var request = new PutUserRequest(); _userUpdateService.Setup(up => up.Handle(It.IsAny <UserUpdateQuery>())) .Throws(CreateDocumentClientExceptionForTesting()); Controller.ControllerContext = GetControllerContext(); // Act var response = await Controller.UpdateUser(It.IsAny <string>(), request); // Assert response.Result.Should().BeAssignableTo <NotFoundObjectResult>(); var result = (NotFoundObjectResult)response.Result; result.Value.Should().BeAssignableTo <PutUserResponse>(); var model = (PutUserResponse)result.Value; model.Errors.Count.Should().Be(0); model.Success.Should().BeTrue(); model.UserId.Should().Be(null); }
public async Task <ActionResult <PutUserResponse> > UpdateUser(string meUserId, [FromBody] PutUserRequest putUser) { if (!ModelState.IsValid) { return(BadRequest(new PutUserResponse())); } try { var userUpdateEmail = Mapper.Map <UserUpdateEmail>(putUser); userUpdateEmail.UserId = meUserId; var currentUser = await CurrentUser(); var updatedUser = await _userUpdateService.Handle(new UserUpdateQuery(userUpdateEmail, currentUser)); return(Ok(Mapper.Map <PutUserResponse>(updatedUser))); } catch (DocumentClientException) { return(NotFound(new PutUserResponse())); } catch (ArgumentException) { return(NotFound(new PutUserResponse())); } }
public PutUserResponse Put(PutUserRequest request) { throw new CmsException(UsersApiConstants.UsersApiHasNoImplementationMessage); }
public PutUserResponse Put(PutUserRequest request) { throw new CmsException(UsersApiConstants.UsersApiHasNoImplementationMessage); }
public PutUserResponse Put(PutUserRequest request) { var model = request.Data.ToServiceModel(); if (request.Id.HasValue) { model.Id = request.Id.Value; } var user = userService.SaveUser(model, false, true); return new PutUserResponse { Data = user.Id }; }