Ejemplo n.º 1
0
        public IEnumerable <ProductDto> Invoke(BusinessKeyDto input)
        {
            _logger.Log($"Starting {GetType().FullName}");
            _logger.Log("Input model received: ", input, LogType.Debug);

            var businessKey = BusinessMapper.ToBusinessKey(input);
            var business    = _businessRepository.Find(businessKey);

            if (business == null)
            {
                var error = new BusinessDoesNotExists(businessKey);
                _logger.Log(error.Message, businessKey, LogType.Error);
                throw error;
            }

            var products = _productRepository.FindByBusiness(businessKey);

            var output = new List <ProductDto>(products.Select(product => new ProductDto()
            {
                BusinessCode       = business.Code,
                ProductCode        = product.Code,
                ProductName        = product.Name,
                ProductDescription = product.Description
            }));

            _logger.Log("Output model to return: ", output, LogType.Debug);
            return(output);
        }
Ejemplo n.º 2
0
        public void BusinessDoesNotExists()
        {
            var service = _serviceProvider.GetService <GetProductsByBusiness>();
            var input   = new BusinessKeyDto()
            {
                Code = "BUSINESS-3"
            };

            Assert.Throws <BusinessDoesNotExists>(() => service.Invoke(input));
        }
Ejemplo n.º 3
0
        public void ProductsIsNotEmpty()
        {
            var service = _serviceProvider.GetService <GetProductsByBusiness>();
            var input   = new BusinessKeyDto()
            {
                Code = "BUSINESS-1"
            };
            var output = service.Invoke(input);

            Assert.NotEmpty(output);
        }
Ejemplo n.º 4
0
 public static BusinessKey ToBusinessKey(BusinessKeyDto businessKeyDto) => new BusinessKey(businessKeyDto.Code);