public void RepositoryGetError_ThrowException() { _repository.Setup(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>())).ThrowsAsync(new DataException()); var service = new MatchesService(_repository.Object, null, _mapper); Assert.ThrowsAsync <DataException>(async() => await service.SetRoundResults(Year, Season, Round, MockedResults().ToList())); _repository.Verify(x => x.BatchUpsertAsync(It.IsAny <IEnumerable <DataRepository.DataEntities.Match> >()), Times.Never); _repository.Verify(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>()), Times.Once); }
public async Task Ok_Success() { _repository.Setup(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>())) .ReturnsAsync(MockedMatches().ToList()); var service = new MatchesService(_repository.Object, null, _mapper); await service.SetRoundResults(Year, Season, Round, MockedResults().ToList()); _repository.Verify(x => x.BatchUpsertAsync(It.IsAny <IEnumerable <DataRepository.DataEntities.Match> >()), Times.Once); _repository.Verify(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>()), Times.Once); }
public void RepositoryMissingMatch_ThrowException() { _repository.Setup(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>())) .ReturnsAsync(MockedMatches().ToList()); var wrongMatch = MockedResults().ToList(); wrongMatch[2].HomeTeamId = 99; var service = new MatchesService(_repository.Object, null, _mapper); Assert.ThrowsAsync <DataException>(async() => await service.SetRoundResults(Year, Season, Round, wrongMatch)); _repository.Verify(x => x.BatchUpsertAsync(It.IsAny <IEnumerable <DataRepository.DataEntities.Match> >()), Times.Never); _repository.Verify(x => x.GetMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>()), Times.Once); }