Ejemplo n.º 1
0
        public void Handle_ShouldGetProducts()
        {
            var productEntities = new List <ProductEntity>
            {
                new ProductEntity {
                    Name = "1", Price = 1, Quantity = 1
                },
                new ProductEntity {
                    Name = "2", Price = 2, Quantity = 2
                },
                new ProductEntity {
                    Name = "3", Price = 3, Quantity = 3
                }
            };
            var request = new GetProductsRequest
            {
                SortOption = It.IsAny <SortOption>()
            };

            _mockProductsService.Setup(s => s.GetProducts(request.SortOption)).ReturnsAsync(productEntities);

            var result = _sut.Handle(request, It.IsAny <CancellationToken>()).Result;

            Assert.True(result.Count() == productEntities.Count());
            for (int i = 0; i < result.Count(); i++)
            {
                Assert.Equal(productEntities.ElementAt(i).Name, result.ElementAt(i).Name);
                Assert.Equal(productEntities.ElementAt(i).Price, result.ElementAt(i).Price);
                Assert.Equal(productEntities.ElementAt(i).Quantity, result.ElementAt(i).Quantity);
            }
        }
Ejemplo n.º 2
0
        public async Task Get_Product_List_Count_Test()
        {
            var handler = new GetProductsRequestHandler(_context, _mapper);
            var source  = await handler.Handle(new GetProductsRequest(),
                                               CancellationToken.None);

            Assert.Equal(3, source.Data.Count);
        }