public async Task Test_Update_Product()
        {
            Product product = new Product
            {
                Name    = "UnitTestProduct000001",
                Cost    = 20.50f,
                Price   = 21.50f,
                BrandId = 1
            };
            string jsonResponse;

            using (var client = new TestClientProvider().Client)
            {
                string jsonRequestBody = JsonConvert.SerializeObject(product);
                var    response        = await client.PostAsync("/api/product", new StringContent(jsonRequestBody, Encoding.UTF8, "application/json"));

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

                response = await client.GetAsync("/api/product");

                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.OK);
                jsonResponse = await response.Content.ReadAsStringAsync();

                var products     = JsonConvert.DeserializeObject <List <ProductVM> >(jsonResponse);
                var productFound = products.Find(x => x.Name == product.Name);

                product.Name    = "PutIntegrationTest0000001";
                product.Price   = 10;
                product.Cost    = 5;
                product.BrandId = 3;
                jsonRequestBody = JsonConvert.SerializeObject(product);

                response = await client.PutAsync("/api/product/" + productFound.Id, new StringContent(jsonRequestBody, Encoding.UTF8, "application/json"));

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

                response = await client.GetAsync("/api/product/" + productFound.Id);

                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.OK);
                jsonResponse = await response.Content.ReadAsStringAsync();

                product.Id = productFound.Id;
                var updatedProduct = JsonConvert.DeserializeObject <ProductVM>(jsonResponse);

                Assert.True(CompareProducts(updatedProduct, product));
                await client.DeleteAsync("/api/product/" + updatedProduct.Id);
            }
        }
Пример #2
0
        public async Task Test_GetAll_Brands()
        {
            List <BrandVM> brands;
            string         jsonResponse;

            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/api/brand");

                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.OK);
                jsonResponse = await response.Content.ReadAsStringAsync();
            }

            brands = JsonConvert.DeserializeObject <List <BrandVM> >(jsonResponse);
            Assert.True(brands.Count > 0);
        }