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 InsuranceController()
 {
     _claimHandler            = new ClaimHandler(_logger);
     _addPolicyHandler        = new AddPolicyHandler(_logger);
     _getPolicyHandler        = new GetPolicyHandler(_logger);
     _calculatePremiumHandler = new CalculatePremiumHandler(_logger);
     _validateDataHandler     = new ValidateDataHandler(_logger);
     _isClaimableHandler      = new IsClaimableHandler(_logger);
     _getProductHandler       = new GetProductHandler(_logger);
     _getProductStatsHandler  = new GetProductStatsHandler(_logger);
 }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        public async Task return_null_when_not_found_document()
        {
            //Arrange
            _productRepository.Setup(r => r.GetAsync(_guid)).Returns(Task.FromResult((Product)null));
            var query = new GetProduct();

            //Act
            var handler = new GetProductHandler(_productRepository.Object, _logger.Object);
            var result  = await handler.HandleAsync(query);

            //Assert
            Assert.Null(result);
        }
Ejemplo n.º 5
0
        public async Task return_expected_result()
        {
            //Arrange
            var product = new Product(_guid, "", "", 1, _guid);

            _productRepository.Setup(r => r.GetAsync(_guid)).ReturnsAsync(product);
            var query = new GetProduct();

            query.Id = _guid;

            //Act
            var handler = new GetProductHandler(_productRepository.Object, _logger.Object);
            var result  = await handler.HandleAsync(query);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(product.Id, result.Id);
            Assert.Equal(product.CategoryId, result.CategoryId);
        }
Ejemplo n.º 6
0
        public string[] parseInput(String input)
        {
            CommandHandler commandHandler;
            List <string>  list = input.Split(' ').ToList();

            if (list.Contains(createProduct))
            {
                commandHandler = new CreateProductHandler();
            }
            else if (list.Contains(getProduct))
            {
                commandHandler = new GetProductHandler();
            }
            else if (list.Contains(createOrder))
            {
                commandHandler = new CreateOrderHandler();
            }
            else if (list.Contains(createCampaign))
            {
                commandHandler = new CreateCampaignHandler();
            }
            else if (list.Contains(getCampaign))
            {
                commandHandler = new GetCampaignHandler();
            }
            else if (list.Contains(increaseTime))
            {
                commandHandler = new IncreaseTimeHandler();
            }
            else
            {
                return(null);
            }
            Console.WriteLine(commandHandler.Execute(list));
            return(null);
        }
Ejemplo n.º 7
0
 public GetProductTest()
 {
     _getProductHandler    = new GetProductHandler();
     _createProductHandler = new CreateProductHandler();
 }