public async Task GetNewsAsync_WhenCalled_AssertGetNewsAsyncWasCalledOnNewRepository() { INewsLogic sut = CreateSut(); await sut.GetNewsAsync(25); _newRepositoryMock.Verify(m => m.GetNewsAsync(), Times.Once); }
public async Task GetNewsAsync_WhenCalled_ExpectNoError() { INewsLogic sut = CreateSut(); await sut.GetNewsAsync(25); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task GetNewsAsync_WhenCalledAndGetNewsAsyncOnNewsRepositoryReturnsNull_ReturnsEmptyCollection() { INewsLogic sut = CreateSut(getNewsAsyncReturnsNull: true); IEnumerable <INews> result = await sut.GetNewsAsync(25); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetNewsAsync_WhenCalledAndExceptionOccurs_AssertHandleAsyncWasCalledOnExceptionHandler() { Exception exception = new Exception(); INewsLogic sut = CreateSut(provokedException: exception); await sut.GetNewsAsync(25); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.Is <Exception>(ex => ex == exception)), Times.Once); }
public async Task GetNewsAsync_WhenCalledAndGetNewsAsyncOnNewsRepositoryReturnsEmptyCollection_ReturnsEmptyCollection() { IEnumerable <INews> news = BuildNews(numberOfNews: 0); INewsLogic sut = CreateSut(news: news); IEnumerable <INews> result = await sut.GetNewsAsync(25); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetNewsAsync_WhenCalledAndExceptionOccurs_ReturnsEmptyCollection() { Exception exception = new Exception(); INewsLogic sut = CreateSut(provokedException: exception); IEnumerable <INews> result = await sut.GetNewsAsync(25); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetNewsAsync_WhenCalledAndGetNewsAsyncOnNewsRepositoryReturnsEqualToQueried_ReturnsCollectionWithAllElements() { IEnumerable <INews> news = BuildNews(numberOfNews: 25); INewsLogic sut = CreateSut(news: news); IEnumerable <INews> result = await sut.GetNewsAsync(25); Assert.IsNotNull(result); Assert.AreEqual(25, result.Count()); Assert.IsTrue(result.All(item => news.Contains(item))); }
public async Task BuildAsync(IDashboardSettings dashboardSettings, IDashboard dashboard) { if (dashboardSettings == null) { throw new ArgumentNullException(nameof(dashboardSettings)); } if (dashboard == null) { throw new ArgumentNullException(nameof(dashboard)); } try { IEnumerable <INews> news = await _newLogic.GetNewsAsync(dashboardSettings.NumberOfNews); dashboard.Replace(news); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } }