コード例 #1
0
        public async Task Get_Invalid()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/user/[email protected]");

                response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            }
        }
コード例 #2
0
        public async Task Get_One()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/user/[email protected]");

                response.EnsureSuccessStatusCode();
                Assert.NotNull(response);
                var responseString = await response.Content.ReadAsStringAsync();

                var user = JsonConvert.DeserializeObject <UserDTO>(responseString);
                Assert.True(user != null);
                Assert.True(user.name == "Julie Ann Jeffries");
            }
        }
コード例 #3
0
        public async Task Get_All()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/user");

                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.OK);

                var responseString = await response.Content.ReadAsStringAsync();

                var users = JsonConvert.DeserializeObject <List <UserDTO> >(responseString);

                Assert.True(users.Any());
            }
        }
コード例 #4
0
        public async Task Create_Duplicate_Email()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.PostAsync("user",
                                                      new StringContent(
                                                          JsonConvert.SerializeObject(new User()
                {
                    firstName = "Julie",
                    middleName = "Marie",
                    lastName = "Jeffries",
                    phoneNumber = "123-456-7890",
                    emailAddress = "*****@*****.**"
                }),
                                                          Encoding.UTF8,
                                                          "application/json"));

                response.StatusCode.Should().Be(HttpStatusCode.Conflict);
            }
        }
コード例 #5
0
        public async Task Create_User_Invalid_Email()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.PostAsync("user",
                                                      new StringContent(
                                                          JsonConvert.SerializeObject(new User()
                {
                    firstName = "Bruce",
                    middleName = "James",
                    lastName = "White",
                    phoneNumber = "123-456-7890",
                    emailAddress = "bruce.james"
                }),
                                                          Encoding.UTF8,
                                                          "application/json"));

                response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            }
        }
コード例 #6
0
        public async Task Update_User_Same_Email()
        {
            using (var client = new TestClientProvider().Client)
            {
                var getResponse = await client.GetAsync("/user/[email protected]");

                getResponse.EnsureSuccessStatusCode();
                Assert.NotNull(getResponse);
                var responseString = await getResponse.Content.ReadAsStringAsync();

                var user = JsonConvert.DeserializeObject <UserDTO>(responseString);

                var response = await client.PutAsync($"/user/{user.userId}"
                                                     , new StringContent(
                                                         JsonConvert.SerializeObject(new User()
                {
                    id = user.userId,
                    firstName = "Bob",
                    middleName = "G",
                    lastName = "Smith",
                    phoneNumber = "123-456-7890",
                    emailAddress = "*****@*****.**"
                }),
                                                         Encoding.UTF8,
                                                         "application/json"));

                response.EnsureSuccessStatusCode();

                response.StatusCode.Should().Be(HttpStatusCode.OK);

                string resp = await response.Content.ReadAsStringAsync();

                var resultUser = JsonConvert.DeserializeObject <User>(resp);
                Assert.Equal("Bob", resultUser.firstName);
                Assert.Equal("G", resultUser.middleName);
                Assert.Equal("*****@*****.**", resultUser.emailAddress);
            }
        }