public async Task TestDeleteStockItemAsync() { // Arrange var postRequest = new { Url = "/api/v1/WebAPI/StockItem", Body = new { StockItemName = string.Format("Product to delete {0}", Guid.NewGuid()), SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 10.000m, UnitPrice = 10.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"USA\", \"Tags\": [\"Sample\"] }", Tags = "[\"Sample\"]", SearchDetails = "Product to delete", LastEditedBy = 1, ValidFrom = DateTime.Now, ValidTo = DateTime.Now.AddYears(5) } }; // Act var postResponse = await Client.PostAsync(postRequest.Url, ContentHelper.GetStringContent(postRequest.Body)); var jsonFromPostResponse = await postResponse.Content.ReadAsStringAsync(); var singleResponse = JsonConvert.DeserializeObject <SingleResponse <StockItem> >(jsonFromPostResponse); var deleteResponse = await Client.DeleteAsync(string.Format("/api/v1/WebAPI/StockItem/{0}", singleResponse.Model.StockItemID)); // Assert postResponse.EnsureSuccessStatusCode(); Assert.False(singleResponse.DidError); deleteResponse.EnsureSuccessStatusCode(); }
public async Task TestPutStockItemAsync() { // Arrange var request = new { Url = "/api/v1/WebAPI/StockItem/1", Body = new { StockItemName = string.Format("USB anime flash drive - Vegeta {0}", Guid.NewGuid()), SupplierID = 12, Color = 3, UnitPrice = 39.00m } }; // Act var response = await Client.PutAsync(request.Url, ContentHelper.GetStringContent(request.Body)); // Assert response.EnsureSuccessStatusCode(); }
public async Task Get_Orders_Authorized_ReturnSuccessAndCorrectContentType() { // Arrange string url = "api/orders"; var client = _factory.CreateClient(); var requestLogin = new { Url = "api/login", Body = new { Username = "******", Password = "******" } }; var responseLogin = await client.PostAsync(requestLogin.Url, ContentHelper.GetStringContent(requestLogin.Body)); var currentTokenString = await responseLogin.Content.ReadAsStringAsync(); var currentTokenJson = JObject.Parse(currentTokenString); var tokenKey = "token"; var currentToken = currentTokenJson.GetValue(tokenKey).ToString(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", currentToken); var expectedOrders = new List <Order>(); // Act var response = await client.GetAsync(url); var contentString = await response.Content.ReadAsStringAsync(); var existingOrders = JsonConvert.DeserializeObject <IList <Order> >(contentString); // Assert response.EnsureSuccessStatusCode(); Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString()); Assert.Equal(expectedOrders, existingOrders); }
public async Task TestPostStockItemAsync() { // Arrange var request = new { Url = "/Register", Body = new { password = "******", passwordCheck = "aaa", username = "******" } }; // Act var response = await Client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var value = await response.Content.ReadAsStringAsync(); // Assert response.EnsureSuccessStatusCode(); }
public async Task TestPostStockItemAsync() { // Arrange var request = new { Url = "/api/v1/WebAPI/StockItem", Body = new { StockItemName = string.Format("USB anime flash drive - Vegeta {0}", Guid.NewGuid()), SupplierID = 12, UnitPackageID = 7, OuterPackageID = 7, LeadTimeDays = 14, QuantityPerOuter = 1, IsChillerStock = false, TaxRate = 15.000m, UnitPrice = 32.00m, RecommendedRetailPrice = 47.84m, TypicalWeightPerUnit = 0.050m, CustomFields = "{ \"CountryOfManufacture\": \"Japan\", \"Tags\": [\"32GB\",\"USB Powered\"] }", Tags = "[\"32GB\",\"USB Powered\"]", SearchDetails = "USB anime flash drive - Vegeta", LastEditedBy = 1, ValidFrom = DateTime.Now, ValidTo = DateTime.Now.AddYears(5) } }; // Act var response = await Client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var value = await response.Content.ReadAsStringAsync(); // Assert response.EnsureSuccessStatusCode(); }
public async Task PostOrders_Authorized() { // Arrange // Set up the Http client and the authorization var client = _factory.CreateClient(); client.DefaultRequestHeaders.Add("X-API-Version", "2"); var requestLogin = new { Url = "api/login", Body = new { Username = "******", Password = "******" } }; var responseLogin = await client.PostAsync(requestLogin.Url, ContentHelper.GetStringContent(requestLogin.Body)); var currentTokenString = await responseLogin.Content.ReadAsStringAsync(); var currentTokenJson = JObject.Parse(currentTokenString); string tokenKey = "token"; var currentToken = currentTokenJson.GetValue(tokenKey).ToString(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", currentToken); // Post orders var currentOrder1 = new Order(1001, 50, 60, OrderType.Sell, 17); var request = new { Url = "api/orders/sell", Body = currentOrder1 }; await client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var currentOrder2 = new Order(1001, 50, 60, OrderType.Sell, 18); request = new { Url = "api/orders/sell", Body = currentOrder2 }; await client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var currentOrder3 = new Order(1001, 50, 60, OrderType.Sell, 1); request = new { Url = "api/orders/sell", Body = currentOrder3 }; await client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var currentOrder4 = new Order(1003, 50, 60, OrderType.Buy, 19); request = new { Url = "api/orders/buy", Body = currentOrder4 }; await client.PostAsync(request.Url, ContentHelper.GetStringContent(request.Body)); var expectedOrders = new List <Order>() { currentOrder1, currentOrder2 }; var currentTrade = new Trade(currentOrder4.AccountNumber, currentOrder4.Quantity, currentOrder4.Price, currentOrder4.Action); var expectedTrade = new List <Trade>() { currentTrade }; // Act // Get Existing Orders var responseGetOrders = await client.GetAsync("/api/orders"); var existingOrdersString = await responseGetOrders.Content.ReadAsStringAsync(); var existingOrders = JsonConvert.DeserializeObject <IList <Order> >(existingOrdersString); // Get Trade var responseGetTrades = await client.GetAsync("/api/trades"); var existingTradesString = await responseGetTrades.Content.ReadAsStringAsync(); var existingTrades = JsonConvert.DeserializeObject <IList <Trade> >(existingTradesString); // Assert responseGetOrders.EnsureSuccessStatusCode(); Assert.Equal(expectedTrade[0], existingTrades[0]); Assert.Equal(expectedOrders, existingOrders); }