public HttpResponseMessage PostUser(UserRequestModel requestModel) {

            var createdUserResult = 
                _membershipService.CreateUser(
                    requestModel.Name, requestModel.Email, 
                    requestModel.Password, requestModel.Roles);

            if (!createdUserResult.IsSuccess) {

                return new HttpResponseMessage(HttpStatusCode.Conflict);
            }

            var response = Request.CreateResponse(HttpStatusCode.Created,
                createdUserResult.Entity.ToUserDto());

            response.Headers.Location = new Uri(Url.Link("DefaultHttpRoute",
                    new { key = createdUserResult.Entity.User.Key }));

            return response;
        }
                Returns_400_If_Request_Authorized_But_Invalid() {

                // Arrange
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(
                        GetInitialServices(GetMembershipService()));

                // This is not a valid user request to create new one
                var userRequestModel = new UserRequestModel {
                    Name = Constants.ValidAdminUserName,
                    Email = "FooBarexample.com",
                    Password = "******",
                    Roles = new string[0]
                };

                var request = HttpRequestMessageHelper
                    .ConstructRequest(
                        httpMethod: HttpMethod.Post,
                        uri: string.Format(
                            "https://localhost/{0}",
                            "api/users"),
                        mediaType: "application/json",
                        username: Constants.ValidAdminUserName,
                        password: Constants.ValidAdminPassword);

                request.Content = new ObjectContent<UserRequestModel>(
                    userRequestModel, new JsonMediaTypeFormatter());

                var httpError = await IntegrationTestHelper
                    .GetResponseMessageBodyAsync<HttpError>(
                        config, request, HttpStatusCode.BadRequest);

                var modelState = (HttpError)httpError["ModelState"];
                var passwordError = modelState["requestModel.Password"] as string[];
                var rolesError = modelState["requestModel.Roles"] as string[];
                var emailError = modelState["requestModel.Email"] as string[];

                // Assert
                Assert.NotNull(passwordError);
                Assert.NotNull(rolesError);
                Assert.NotNull(emailError);
            }
                Returns_409_If_Request_Authorized_But_Conflicted() {

                // Arrange
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(
                        GetInitialServices(GetMembershipService()));

                // This is not a valid user request to create new one
                var userRequestModel = new UserRequestModel {
                    Name = Constants.ValidAdminUserName,
                    Email = "*****@*****.**",
                    Password = "******",
                    Roles = new[] { "Admin", "Employee" }
                };

                var request = HttpRequestMessageHelper
                    .ConstructRequest(
                        httpMethod: HttpMethod.Post,
                        uri: string.Format(
                            "https://localhost/{0}",
                            "api/users"),
                        mediaType: "application/json",
                        username: Constants.ValidAdminUserName,
                        password: Constants.ValidAdminPassword);

                request.Content = new ObjectContent<UserRequestModel>(
                    userRequestModel, new JsonMediaTypeFormatter());

                var response = await IntegrationTestHelper
                    .GetResponseAsync(config, request);

                // Assert
                Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
            }
                Returns_201_And_User_If_Request_Authorized_And_Success() {

                // Arrange
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(
                        GetInitialServices(GetMembershipService()));

                // This is a valid user request to create new one
                var userRequestModel = new UserRequestModel {
                    Name = "FooBar",
                    Email = "*****@*****.**",
                    Password = "******",
                    Roles = new[] { "Admin", "Employee" }
                };

                var request = HttpRequestMessageHelper
                    .ConstructRequest(
                        httpMethod: HttpMethod.Post,
                        uri: string.Format(
                            "https://localhost/{0}",
                            "api/users"),
                        mediaType: "application/json",
                        username: Constants.ValidAdminUserName,
                        password: Constants.ValidAdminPassword);

                request.Content = new ObjectContent<UserRequestModel>(
                    userRequestModel, new JsonMediaTypeFormatter());

                var userDto = await IntegrationTestHelper
                    .GetResponseMessageBodyAsync<UserDto>(
                        config, request, HttpStatusCode.Created);

                // Assert
                Assert.Equal(userRequestModel.Name, userDto.Name);
                Assert.Equal(userRequestModel.Email, userDto.Email);
                Assert.True(userDto.Roles.Any(x => x.Name.Equals(userRequestModel.Roles[0], StringComparison.OrdinalIgnoreCase)));
                Assert.True(userDto.Roles.Any(x => x.Name.Equals(userRequestModel.Roles[1], StringComparison.OrdinalIgnoreCase)));
            }