コード例 #1
0
        public void GetLaboriousCustomers()
        {
            CustomerResponseTest responseCustomer = new CustomerResponseTest();
            HttpResponseMessage  responseMessage  = _client.PostAsync("/api/customer/Filter", new StringContent(JsonSerializer.Serialize(new FilterCustomerDTO {
                Type = 3, PageSize = 20, PageNumber = 3
            }), Encoding.UTF8, "application/json")).Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                string response = responseMessage.Content.ReadAsStringAsync().Result;
                responseCustomer = JsonSerializer.Deserialize <CustomerResponseTest>(response, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true
                });
            }

            Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);
            Assert.NotEqual(HttpStatusCode.BadRequest, responseMessage.StatusCode);
            Assert.NotNull(responseCustomer);
            Assert.Equal(CustomerTypeEnum.Laborious.ToString(), responseCustomer.users.FirstOrDefault().type);
            Assert.NotEqual(CustomerTypeEnum.Special.ToString(), responseCustomer.users.LastOrDefault().type);
            Assert.True(responseCustomer.users.Any());
            Assert.Equal(20, responseCustomer.pageSize);
            Assert.Equal(3, responseCustomer.pageNumber);
            Assert.NotEqual(0, responseCustomer.pageNumber);
            Assert.Equal(20, responseCustomer.users.Count);
        }
コード例 #2
0
        public void BadRequestCustomers()
        {
            CustomerResponseTest responseCustomer = null;
            HttpResponseMessage  responseMessage  = _client.PostAsync("/api/customer/Filter", new StringContent(JsonSerializer.Serialize(new FilterCustomerDTO()), Encoding.UTF8, "application/json")).Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                string response = responseMessage.Content.ReadAsStringAsync().Result;
                responseCustomer = JsonSerializer.Deserialize <CustomerResponseTest>(response, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true
                });
            }

            Assert.NotEqual(HttpStatusCode.OK, responseMessage.StatusCode);
            Assert.Equal(HttpStatusCode.BadRequest, responseMessage.StatusCode);
            Assert.Null(responseCustomer);
        }
コード例 #3
0
        public void FilterCustomersByEmail()
        {
            CustomerResponseTest responseCustomer = new CustomerResponseTest();
            HttpResponseMessage  responseMessage  = _client.PostAsync("/api/customer/Filter", new StringContent(JsonSerializer.Serialize(new FilterCustomerDTO {
                Email = "aes@exa", PageSize = 12, PageNumber = 1
            }), Encoding.UTF8, "application/json")).Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                string response = responseMessage.Content.ReadAsStringAsync().Result;
                responseCustomer = JsonSerializer.Deserialize <CustomerResponseTest>(response, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true
                });
            }

            Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);
            Assert.NotEqual(HttpStatusCode.BadRequest, responseMessage.StatusCode);
            Assert.True(responseCustomer.users.Exists(x => x.email.Contains("aes@exa")));
        }
コード例 #4
0
        public void FilterCustomersByGender()
        {
            CustomerResponseTest responseCustomer = new CustomerResponseTest();
            HttpResponseMessage  responseMessage  = _client.PostAsync("/api/customer/Filter", new StringContent(JsonSerializer.Serialize(new FilterCustomerDTO {
                Gender = "F", PageSize = 20, PageNumber = 0
            }), Encoding.UTF8, "application/json")).Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                string response = responseMessage.Content.ReadAsStringAsync().Result;
                responseCustomer = JsonSerializer.Deserialize <CustomerResponseTest>(response, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true
                });
            }

            Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);
            Assert.NotEqual(HttpStatusCode.BadRequest, responseMessage.StatusCode);
            Assert.Equal("F", responseCustomer.users.FirstOrDefault().gender);
            Assert.Equal("F", responseCustomer.users.LastOrDefault().gender);
            Assert.NotEqual("M", responseCustomer.users.LastOrDefault().type);
        }