|
| 1 | +using Microsoft.eShopOnContainers.Services.Catalog.API.Model; |
| 2 | +using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel; |
| 3 | +using Newtonsoft.Json; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Net.Http; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace FunctionalTests.Services.Catalog |
| 13 | +{ |
| 14 | + public class CatalogScenarios : CatalogScenariosBase |
| 15 | + { |
| 16 | + [Fact] |
| 17 | + public async Task Post_update_a_catalogitem_price_and_catalogitem_is_returned_modified() |
| 18 | + { |
| 19 | + using (var server = CreateServer()) |
| 20 | + { |
| 21 | + var client = server.CreateClient(); |
| 22 | + |
| 23 | + // Arrange |
| 24 | + var itemToModify = GetCatalogItem(); |
| 25 | + var newPrice = new Random().Next(1, 200); |
| 26 | + itemToModify.Price = newPrice; |
| 27 | + |
| 28 | + // Act |
| 29 | + var postRes = await client.PostAsync(Post.UpdateCatalogProduct, |
| 30 | + new StringContent(JsonConvert.SerializeObject(itemToModify), |
| 31 | + UTF8Encoding.UTF8, "application/json")); |
| 32 | + var response = await client.GetAsync(Get.ProductByName(itemToModify.Name)); |
| 33 | + var result = JsonConvert.DeserializeObject<PaginatedItemsViewModel<CatalogItem>>(await response.Content.ReadAsStringAsync()); |
| 34 | + var item = result.Data.First(); |
| 35 | + |
| 36 | + // Assert |
| 37 | + Assert.Equal(result.Count, 1); |
| 38 | + Assert.Equal(itemToModify.Id, item.Id); |
| 39 | + Assert.Equal(newPrice, item.Price); |
| 40 | + } |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + private CatalogItem GetCatalogItem() |
| 45 | + { |
| 46 | + return new CatalogItem() |
| 47 | + { |
| 48 | + Id = 1, |
| 49 | + Price = 12.5M, |
| 50 | + Name = ".NET Bot Black Sweatshirt" |
| 51 | + }; |
| 52 | + } |
| 53 | + |
| 54 | + } |
| 55 | +} |
0 commit comments