Ejemplo n.º 1
0
        public void GetProductHandler_ShouldGetProduct()
        {
            IQueryable <Product> product = new List <Product>
            {
                new Product {
                    ProductCode = "P1", Price = 10, Stock = 10
                }
            }.AsQueryable();

            IQueryable <Campaigning> campaigning = new List <Campaigning>
            {
                new Campaigning {
                    CampaignName = "C1", ProductCode = "P1", Duration = 5, Limit = 10, TargetSalesCount = 10
                }
            }.AsQueryable();

            var repoMock = new Mock <IRepository <Product> >();

            repoMock.Setup(x => x.GetWhereAsync(It.IsAny <Expression <Func <Product, bool> > >())).Returns <Expression <Func <Product, bool> > >(predicate => Task.FromResult(product.Where(predicate).ToList().AsEnumerable()));
            IRepository <Product>       repository = repoMock.Object;
            ILogger <GetProductHandler> logger     = new Mock <ILogger <GetProductHandler> >().Object;
            IMediator mediator = new Mock <IMediator>().Object;

            GetProductHandler productHandler = new GetProductHandler(repository, logger, mediator);

            var result = productHandler.Handle(new Dtos.Requests.GetProductRequest("P1"), new System.Threading.CancellationToken()).Result;

            Assert.True(result.Data != null);
        }
Ejemplo n.º 2
0
        public async Task GetProductDetail()
        {
            var sut = new GetProductHandler(_context);

            var result = await sut.Handle(new GetProductQuery()
            {
                Id = 4
            }, CancellationToken.None);

            result.Name.Should().Contain("Intel");
        }