예제 #1
0
        /// <summary>
        /// Creates notification if database deployment failed.
        /// Notification severity is determined by whether the application is stuck in prerequisites mode.
        /// </summary>
        /// <returns>Notification</returns>
        public async Task <PDBNotification> GetDatabaseDeploymentFailureAlertAsync()
        {
            // TODO make sure that async results don't deadlock web server or add non-async repo methods
            var databaseDeplymentService = new DatabaseDeploymentService(this.eventRepository, this.serverRepository);
            var eventSystemState         = await this.eventRepository.ReadEventSystemStateAsync();

            return((await databaseDeplymentService.FindAnyFailedDeployments())
                                ? new PDBNotification()
            {
                Type = eventSystemState == EventSystemState.Prerequisites ? NotificationType.Critical : NotificationType.Warning,
                Message = Messages.Notification.DeploymentFailure
            }
                                : null);
        }
        public async Task FindAnyFailedDeployments()
        {
            // Arrange
            var servers = new[] { new Server {
                                      ServerId = 123, ServerType = ServerType.Database
                                  }, new Server {
                                      ServerId = 345, ServerType = ServerType.Database
                                  } };

            this.serverRepository.Setup(r => r.ReadAllActiveAsync()).ReturnsAsync(servers);
            this.eventRepository.Setup(r => r.ReadLastBySourceIdAndTypeAsync(EventSourceType.DeployServerDatabases, It.IsAny <int>()))
            .Returns <EventSourceType, int>((t, sid) => Task.FromResult(new Event {
                Status = EventStatus.Error, SourceId = sid, SourceType = EventSourceType.DeployServerDatabases
            }));

            // Act
            var result = await databaseDeploymentService.FindAnyFailedDeployments();

            // Assert
            Assert.That(result, Is.True);
        }