예제 #1
0
        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();
        }
예제 #2
0
        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);
        }