public async Task BuildAsync_WhenCalled_AssertGetSystemErrorsAsyncWasCalledOnSystemErrorLogic()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            IDashboardFactory sut = CreateSut(dashboardContentBuilder3ShouldBuild: false);

            await sut.BuildAsync(dashboardSettings);

            _systemErrorLogic.Verify(m => m.GetSystemErrorsAsync(), Times.Once);
        }
Esempio n. 2
0
        public async Task <IActionResult> Build(string dashboardSettings)
        {
            if (string.IsNullOrWhiteSpace(dashboardSettings))
            {
                throw new ArgumentNullException(nameof(dashboardSettings));
            }

            DashboardSettingsViewModel dashboardSettingsViewModel = _contentHelper.ToDashboardSettingsViewModel(dashboardSettings);

            if (dashboardSettingsViewModel == null)
            {
                return(BadRequest());
            }

            IDashboard dashboard = await _dashboardFactory.BuildAsync(dashboardSettingsViewModel.ToDashboardSettings());

            DashboardViewModel dashboardViewModel = await _dashboardViewModelBuilder.BuildAsync(dashboard);

            return(PartialView("_MainContentPartial", dashboardViewModel));
        }
        public async Task BuildAsync_WhenCalledAndExceptionOccurs_AssertGetSystemErrorsAsyncWasCalledOnSystemErrorLogic()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            Exception         exception = new Exception();
            IDashboardFactory sut       = CreateSut(provokeException: exception);

            await sut.BuildAsync(dashboardSettings);

            _systemErrorLogic.Verify(m => m.GetSystemErrorsAsync(), Times.Once);
        }
        public async Task BuildAsync_WhenCalledAndExceptionOccurs_AssertHandleAsyncWasCalledOnExceptionHandler()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            Exception         exception = new Exception();
            IDashboardFactory sut       = CreateSut(provokeException: exception);

            await sut.BuildAsync(dashboardSettings);

            _exceptionHandlerMock.Verify(m => m.HandleAsync(It.Is <Exception>(ex => ex == exception)), Times.Once);
        }
        public async Task BuildAsync_WhenCalled_AssertShouldBuildWasCalledOnEachDashboardContentBuilder()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            IDashboardFactory sut = CreateSut();

            await sut.BuildAsync(dashboardSettings);

            _dashboardContentBuilder1Mock.Verify(m => m.ShouldBuild(It.Is <IDashboardSettings>(value => value == dashboardSettings)), Times.Once);
            _dashboardContentBuilder2Mock.Verify(m => m.ShouldBuild(It.Is <IDashboardSettings>(value => value == dashboardSettings)), Times.Once);
            _dashboardContentBuilder3Mock.Verify(m => m.ShouldBuild(It.Is <IDashboardSettings>(value => value == dashboardSettings)), Times.Once);
        }
        public async Task BuildAsync_WhenCalledAndFirstDashboardBuilderShouldNotBuild_AssertBuildAsyncWasNotCalledOnFirstDashboardContentBuilder()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            IDashboardFactory sut = CreateSut(dashboardContentBuilder1ShouldBuild: false);

            await sut.BuildAsync(dashboardSettings);

            _dashboardContentBuilder1Mock.Verify(m => m.BuildAsync(
                                                     It.IsAny <IDashboardSettings>(),
                                                     It.IsAny <IDashboard>()),
                                                 Times.Never);
        }
        public async Task BuildAsync_WhenCalled_ReturnsDashboard()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();

            List <ISystemError> systemErrors = BuildSystemErrors(_random.Next(1, 10));
            IDashboardFactory   sut          = CreateSut(systemErrors: systemErrors);

            IDashboard dashboard = await sut.BuildAsync(dashboardSettings);

            Assert.IsNotNull(dashboard);
            Assert.IsNotNull(dashboard.SystemErrors);
            Assert.AreEqual(systemErrors.Count, dashboard.SystemErrors.Count());
            Assert.IsNotNull(dashboard.Settings);
            Assert.AreEqual(dashboardSettings, dashboard.Settings);

            systemErrors.ForEach(systemError => Assert.IsTrue(dashboard.SystemErrors.Contains(systemError)));
        }
        public async Task BuildAsync_WhenDashboardSettingsIsNull_ThrowsArgumentNullException()
        {
            IDashboardFactory sut = CreateSut();

            await sut.BuildAsync(null);
        }