コード例 #1
0
        public async Task <HttpResponseMessage> AddProductAsync([FromBody] IEnumerable <Product> products)
        {
            try
            {
                var isFullyAdded = await _shopRepository.AddProductsAsync(products);

                return(isFullyAdded ?
                       new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject("products added"))
                }
                                 :
                       new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(JsonConvert.SerializeObject("products not fully added. Some of them is already exists!"))
                });
            }
            catch (Exception e)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(e.Message))
                });
            }
        }
コード例 #2
0
ファイル: OrderedTests.cs プロジェクト: VitaliyNazarets/Store
        public async Task AddDataTest()
        {
            AddDataCalled = true;

            List <Product> list = new List <Product>();

            for (int i = 0; i < 7; i++)
            {
                list.Add(new Product()
                {
                    Name = $"Product {i}", Price = (i % 5) * 20 + 100
                });
            }


            await shopRepository.AddProductsAsync(list).ConfigureAwait(false);

            Assert.Equal(7, shopRepository.Count());
            //verification of the order
            Assert.False(CalculatePriceCalled);
            Assert.False(UpdatePricesCalled);
            Assert.False(PricesUpdatedCorrectlyCalled);
        }