Пример #1
0
        public async void Should_Add_New_ItemsAsync()
        {
            var itemGet = new Item {
                Id = 1, Description = "MyItem1Async"
            };

            var resuattItems = new[]
            {
                new ParseResultItem {
                    Description = "MyItem1Async", Price = 10, Code = "1"
                },
                new ParseResultItem {
                    Description = "MyItem2Async", Price = 10, Code = "2"
                },
                new ParseResultItem {
                    Description = "MyItem3Async", 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);

            await service.AddItemsAsync(parsingConfiguration);

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

            unitOfWorkMock.Verify(m => m.Save());
        }