public async void UpdateUserAsNonAdminTest() { // create users await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(4, "*****@*****.**")); await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(2000, "*****@*****.**")); // create updated users User userAuthorized = UserFactory.CreateNormalUser(4); userAuthorized.Email = "*****@*****.**"; User userNotAuthorized = UserFactory.CreateNormalUser(2000); userNotAuthorized.Email = "*****@*****.**"; // create put requests HttpRequest requestAuthorized = HttpRequestFactory.CreatePutRequest <User>(userAuthorized); HttpRequest requestNotAuthorized = HttpRequestFactory.CreatePutRequest <User>(userNotAuthorized); ObjectResult resultAuthorized = (ObjectResult)await this.userController.UserUpdate(requestAuthorized, 4, this.userClaim); ObjectResult resultNotAuthorized = (ObjectResult)await this.userController.UserUpdate(requestNotAuthorized, 2000, this.userClaim); UserResponse resultUserAuthorized = (UserResponse)resultAuthorized.Value; // status code should be 200 OK Assert.Equal(200, resultAuthorized.StatusCode); // status code should be 403 FORBIDDEN Assert.Equal(403, resultNotAuthorized.StatusCode); // the email should be updated Assert.Equal("*****@*****.**", resultUserAuthorized.Email); // the email should not be updated Assert.Equal("*****@*****.**", (await this.userRepository.ReadAsync(2000)).Email); }
public async void UpdateUserAsAdminTest() { // create user await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(2000)); // create updated user User user = UserFactory.CreateNormalUser(2000); user.Email = "*****@*****.**"; // create put request HttpRequest request = HttpRequestFactory.CreatePutRequest <User>(user); ObjectResult result = (ObjectResult)await this.userController.UserUpdate(request, 2000, this.adminClaim); UserResponse resultUser = (UserResponse)result.Value; // status code should be 200 OK Assert.Equal(200, result.StatusCode); // the email should be updated Assert.Equal("*****@*****.**", resultUser.Email); }