public UserCreatedDTO AddUser(UserCreationDTO userCreationDTO) { User user = Mapper.Map <User>(userCreationDTO); user.Id = GetNextId(); User result = userRepository.CreateUser(user); UserCreatedDTO returnValue = Mapper.Map <UserCreatedDTO>(result); return(returnValue); }
async Task GetUserCreatedAsync() { var response = await client.GetAsync("users/" + userID); string tmp = await response.Content.ReadAsStringAsync(); Console.WriteLine(response.StatusCode); try { UserCreatedDTO userRecived = JsonConvert.DeserializeObject <UserCreatedDTO>(tmp); Console.WriteLine(userRecived.password + "\n" + userRecived.id + "\n" + userRecived.email); } catch (Exception e) { } client.CancelPendingRequests(); }
public void AddUser_ShouldReturn201_WhenCalledWithValidUserCreationDTO() { UserCreationDTO userCreationDTO = new UserCreationDTO() { FirstName = "Matthew", LastName = "Roberts", Password = "******" }; var result = userController.AddUser(userCreationDTO); var response = result as CreatedAtRouteResult; Assert.IsNotNull(response); Assert.AreEqual(201, response.StatusCode); Assert.AreEqual("GetUserById", response.RouteName); Assert.IsTrue(response.Value is UserCreatedDTO); UserCreatedDTO userCreatedDTO = response.Value as UserCreatedDTO; Assert.AreEqual(userCreationDTO.FirstName, userCreatedDTO.FirstName); Assert.AreEqual(userCreationDTO.LastName, userCreatedDTO.LastName); }