public async Task <IDashboard> BuildAsync(IDashboardSettings dashboardSettings) { if (dashboardSettings == null) { throw new ArgumentNullException(nameof(dashboardSettings)); } IDashboard dashboard = new Dashboard(); try { Task[] dashboardContentBuilderTasks = _dashboardContentBuilderCollection .Where(dashboardContentBuilder => dashboardContentBuilder.ShouldBuild(dashboardSettings)) .Select(dashboardContentBuilder => dashboardContentBuilder.BuildAsync(dashboardSettings, dashboard)) .ToArray(); await Task.WhenAll(dashboardContentBuilderTasks); } catch (AggregateException ex) { await _exceptionHandler.HandleAsync(ex); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } finally { dashboard.Replace(dashboardSettings); IEnumerable <ISystemError> systemErrors = await _systemErrorLogic.GetSystemErrorsAsync(); dashboard.Replace(systemErrors.OrderByDescending(systemError => systemError.Timestamp)); } return(dashboard); }
public async Task GetSystemErrorsAsync_WhenCalled_AssertGetSystemErrorsAsyncWasCalledOnExceptionRepository() { ISystemErrorLogic sut = CreateSut(); await sut.GetSystemErrorsAsync(); _exceptionRepositoryMock.Verify(m => m.GetSystemErrorsAsync(), Times.Once); }
public async Task GetSystemErrorsAsync_WhenCalled_ExpectNoError() { ISystemErrorLogic sut = CreateSut(); await sut.GetSystemErrorsAsync(); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task GetSystemErrorsAsync_WhenCalledAndExceptionOccurs_AssertHandleAsyncWasCalledOnExceptionHandler() { Exception exception = new Exception(); ISystemErrorLogic sut = CreateSut(provokedException: exception); await sut.GetSystemErrorsAsync(); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.Is <Exception>(ex => ex == exception)), Times.Once); }
public async Task GetSystemErrorsAsync_WhenCalledAndGetSystemErrorsAsyncOnExceptionRepositoryReturnsNull_ReturnsEmptyCollection() { ISystemErrorLogic sut = CreateSut(getSystemErrorsAsyncReturnsNull: true); IEnumerable <ISystemError> result = await sut.GetSystemErrorsAsync(); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetSystemErrorsAsync_WhenCalledAndExceptionOccurs_ReturnsEmptyCollection() { Exception exception = new Exception(); ISystemErrorLogic sut = CreateSut(provokedException: exception); IEnumerable <ISystemError> result = await sut.GetSystemErrorsAsync(); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetSystemErrorsAsync_WhenCalledAndGetSystemErrorsAsyncOnExceptionRepositoryReturnsEmptyCollection_ReturnsEmptyCollection() { IEnumerable <ISystemError> systemErrors = BuildSystemErrors(numberOfSystemErrors: 0); ISystemErrorLogic sut = CreateSut(systemErrors: systemErrors); IEnumerable <ISystemError> result = await sut.GetSystemErrorsAsync(); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public async Task GetSystemErrorsAsync_WhenCalledAndGetSystemErrorsAsyncOnExceptionRepositoryReturnsCollection_ReturnsEmptyCollection() { IEnumerable <ISystemError> systemErrors = BuildSystemErrors(numberOfSystemErrors: 100); ISystemErrorLogic sut = CreateSut(systemErrors: systemErrors); IEnumerable <ISystemError> result = await sut.GetSystemErrorsAsync(); Assert.IsNotNull(result); Assert.AreEqual(100, result.Count()); Assert.IsTrue(result.All(systemError => systemErrors.Contains(systemError))); }