示例#1
0
        public async Task ScrapAsync_EventsAlreadyExistInRepository_RemoveAllOldEventsFromRepositoryAddNewOnes(int eventsCount, EventCategories category)
        {
            var scrappedEvents = generateEvents(eventsCount);

            _scrapperMock.Setup(scr => scr.Scrap(category)).ReturnsAsync(scrappedEvents);

            var eventsMock = scrappedEvents.AsQueryable().BuildMock();

            _eventRepositoryMock.Setup(rp => rp.Get()).Returns(eventsMock.Object);

            var todaysEvents     = new List <EventDate>();
            var todaysEventsMock = todaysEvents.AsQueryable().BuildMock();

            _eventDateRepositoryMock.Setup(rp => rp.Get()).Returns(todaysEventsMock.Object);

            var serviceMock = new ScrapperServiceMock(_scrapperMock.Object,
                                                      _eventRepositoryMock.Object,
                                                      _eventDateRepositoryMock.Object);

            await serviceMock.ScrapAsync(category);

            foreach (var scrappedEvent in scrappedEvents)
            {
                _eventRepositoryMock.Verify(sr => sr.RemoveAsync(scrappedEvent.Id), Times.Once);
            }
        }
示例#2
0
        public async Task ScrapAsync_EventRepositoryAddRangeCalledOnce(EventCategories category)
        {
            var serviceMock = new ScrapperServiceMock(_scrapperMock.Object,
                                                      _eventRepositoryMock.Object,
                                                      _eventDateRepositoryMock.Object);

            await serviceMock.ScrapAsync(category);

            _eventRepositoryMock.Verify(sr => sr.AddRangeAsync(It.IsAny <IEnumerable <Event> >()), Times.Once);
        }
示例#3
0
        public async Task ScrapAsync_KinoAfishaScrapperScrapCalledOnce(EventCategories category)
        {
            var serviceMock = new ScrapperServiceMock(_scrapperMock.Object,
                                                      _eventRepositoryMock.Object,
                                                      _eventDateRepositoryMock.Object);

            await serviceMock.ScrapAsync(category);

            _scrapperMock.Verify(sr => sr.Scrap(category), Times.Once);
        }
示例#4
0
        public async Task ScrapAsync_ScrapperReturnedEvents_AddedToRepository(int eventsCount, EventCategories category)
        {
            var scrappedEvents = generateEvents(eventsCount);

            _scrapperMock.Setup(scr => scr.Scrap(category)).ReturnsAsync(scrappedEvents);

            var eventsEmpty = new List <Event>();
            var eventsMock  = eventsEmpty.AsQueryable().BuildMock();

            _eventRepositoryMock.Setup(rp => rp.Get()).Returns(eventsMock.Object);

            var serviceMock = new ScrapperServiceMock(_scrapperMock.Object,
                                                      _eventRepositoryMock.Object,
                                                      _eventDateRepositoryMock.Object);

            await serviceMock.ScrapAsync(category);

            _eventRepositoryMock.Verify(sr => sr.AddRangeAsync(scrappedEvents), Times.Once);
        }