コード例 #1
0
        public async Task GetNewsAsync_WhenCalled_AssertGetNewsAsyncWasCalledOnNewRepository()
        {
            INewsLogic sut = CreateSut();

            await sut.GetNewsAsync(25);

            _newRepositoryMock.Verify(m => m.GetNewsAsync(), Times.Once);
        }
コード例 #2
0
        public async Task GetNewsAsync_WhenCalled_ExpectNoError()
        {
            INewsLogic sut = CreateSut();

            await sut.GetNewsAsync(25);

            _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never);
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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)));
        }
コード例 #8
0
        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);
            }
        }