Example #1
0
        IEnumerable <ParseResultItem> GetParsedItem(ParsingConfiguration config)
        {
            IParserStategy strategy;//Use strategy pattern

            switch (config.Stategy)
            {
            case ParseStategyEnum.CitrusParserStategy:
                strategy = new CitrusParserStategy();
                break;

            case ParseStategyEnum.Other:
                strategy = new CitrusParserStategy();
                break;

            default:
                strategy = new CitrusParserStategy();
                break;
            }

            _parser.SetStrategy(strategy);

            var items = _parser.GetAllItems(config.Path, config.AmountItems);//3) Polimorfism

            return(items);
        }
Example #2
0
        public async Task <IEnumerable <NewItemDto> > AddItemsAsync(ParsingConfiguration config)
        {
            var items      = GetParsedItem(config);
            var newRecords = _mapper.Map <IEnumerable <NewItemDto> >(items);

            await SaveParsedItemsAsync(items);

            return(newRecords);
        }
Example #3
0
        public IEnumerable <NewItemDto> AddItems(ParsingConfiguration config)
        {
            var items      = GetParsedItem(config);
            var newRecords = _mapper.Map <IEnumerable <NewItemDto> >(items);

            SaveParsedItems(items);

            return(newRecords);
        }
Example #4
0
        public void Should_Add_New_Items()
        {
            var itemGet = new Item {
                Id = 1, Description = "MyItem1"
            };

            var resuattItems = new[]
            {
                new ParseResultItem {
                    Description = "MyItem1", Price = 10, Code = "1"
                },
                new ParseResultItem {
                    Description = "MyItem2", Price = 10, Code = "2"
                },
                new ParseResultItem {
                    Description = "MyItem3", Price = 10, Code = "3"
                },
            };

            var parsingConfiguration = new ParsingConfiguration
            {
                Path        = "https://www.citrus.ua/bluetooth-garnitury/",
                Stategy     = ParseStategyEnum.CitrusParserStategy,
                AmountItems = 10
            };

            var parserMock = new Mock <Parser>();

            parserMock.Setup(u => u.GetAllItems(parsingConfiguration.Path, parsingConfiguration.AmountItems)).Returns(resuattItems);

            var repositoryMock      = new Mock <IRepository <Item> >(MockBehavior.Default);
            var repositorypriseMock = new Mock <IRepository <Price> >(MockBehavior.Default);

            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(u => u.Items).Returns(() => repositoryMock.Object);
            unitOfWorkMock.Setup(u => u.Prices).Returns(() => repositorypriseMock.Object);

            var mappingProfile = new MappingProfile();
            var config         = new MapperConfiguration(mappingProfile);
            var mapper         = new Mapper(config);

            var service = new ItemService(unitOfWorkMock.Object, parserMock.Object, mapper);

            service.AddItems(parsingConfiguration);

            repositoryMock.Verify(m => m.Create(It.Is <Item>(t => t.Code == resuattItems[0].Code)));
            repositoryMock.Verify(m => m.Create(It.Is <Item>(t => t.Code == resuattItems[1].Code)));
            repositoryMock.Verify(m => m.Create(It.Is <Item>(t => t.Code == resuattItems[2].Code)));

            unitOfWorkMock.Verify(m => m.Save());
        }
Example #5
0
        static async Task Main(string[] args)
        {
            //Console.WriteLine("Azure Cognitive Services CLI tool\n");

            var appConfig = LoadAppSettings();

            //if (appConfig == null)
            //{
            //    Console.WriteLine("Missing or invalid appsettings.json...exiting");
            //    return;
            //}

            var config = new ParsingConfiguration(args);
            await config.SetupAsync();

            //var configValue = appConfig["configValue"];
            //Console.WriteLine("Got config value: [{0}]",configValue);
        }
Example #6
0
        public async Task <IActionResult> Parse(ParsingConfiguration config)
        {
            try
            {
                IEnumerable <NewItemDto> newItems;
                if (_isAsync)//TODO Rework if statement
                {
                    newItems = await _requestTypeService.AddItemsAsync(config);
                }
                else
                {
                    newItems = await Task.Run(() => _requestTypeService.AddItems(config));
                }

                return(View("NewItemsList", newItems));
            }
            catch (Exception e)
            {
                ViewData["Message"] = "A  exception has occurred";
                return(View("NewItemsList", new List <NewItemDto>()));
            }
        }