public static async Task GivenACoupon(string couponCode, double percentOff, string itemTypeCode = null) { var itemTypeApi = new ItemTypeApi(ApiUrl); var itemType = await itemTypeApi.GetByCodeAsync(itemTypeCode); var couponDto = new { Code = couponCode, PercentOff = percentOff, ForItemTypeId = itemType?.Id }; var httpContent = new StringContent(JsonConvert.SerializeObject(couponDto), Encoding.UTF8, "application/json"); var postRequestMessage = new HttpRequestMessage( method: HttpMethod.Post, requestUri: new Uri("http://localhost:9050/coupons")) { Content = httpContent }; using (var httpClient = new HttpClient()) { var postResponse = await httpClient.SendAsync(postRequestMessage); Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode); await Task.Delay(2000); // try to get events through first } }
public static async Task GivenAShopWithItems(List <dynamic> items) { var itemTypeApi = new ItemTypeApi(ApiUrl); foreach (var item in items) { var itemType = await itemTypeApi.GetByCodeAsync(item.ItemTypeCode); Assert.NotNull(itemType); var itemDto = new { Code = item.Code, Price = item.Price, ItemTypeId = itemType.Id }; var httpContent = new StringContent(JsonConvert.SerializeObject(itemDto), Encoding.UTF8, "application/json"); var postRequestMessage = new HttpRequestMessage( method: HttpMethod.Post, requestUri: new Uri("http://localhost:9050/items")) { Content = httpContent }; using (var httpClient = new HttpClient()) { var postResponse = await httpClient.SendAsync(postRequestMessage); Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode); await Task.Delay(2000); // try to get events through first } } }