예제 #1
0
        public async Task <ServiceCheckResultDto> CheckServiceAsync(Shared.Service service)
        {
            var requestTasks = new List <Task <KeyValuePair <string, string> > >();

            if (!string.IsNullOrWhiteSpace(service.LocalUrl))
            {
                requestTasks.Add(CheckUrl(service.LocalUrl));
            }
            if (!string.IsNullOrWhiteSpace(service.LocalNetworkUrl))
            {
                requestTasks.Add(CheckUrl(service.LocalNetworkUrl));
            }
            if (!string.IsNullOrWhiteSpace(service.PublicNetworkUrl))
            {
                requestTasks.Add(CheckUrl(service.PublicNetworkUrl));
            }

            var checkResult = new ServiceCheckResultDto {
                Service = service
            };

            var responses = await Task.WhenAll(requestTasks);

            foreach (var response in responses)
            {
                if (response.Value != string.Empty)
                {
                    checkResult.Errors.Add(response);
                }
            }

            return(checkResult);
        }
예제 #2
0
        public BackgroundCheckerTests()
        {
            ResultWithErrors = new ServiceCheckResultDto
            {
                Errors = new Dictionary <string, string>
                {
                    { TestService.LocalNetworkUrl, "timeout" },
                    { TestService.PublicNetworkUrl, "404" }
                },
                Service = TestService
            };
            ResultWithoutErrors = new ServiceCheckResultDto
            {
                Errors  = new Dictionary <string, string>(),
                Service = TestService
            };

            serviceCheckerMock = new Mock <IServiceChecker>();

            serviceStoreMock = new Mock <IServiceStore>();
            serviceStoreMock.Setup(ss => ss.GetAll())
            .Returns(new List <Shared.Service>()
            {
                TestService
            });

            backgroundCheckerConfigurationMock = new Mock <IOptions <BackgroundCheckerConfiguration> >();
            backgroundCheckerConfigurationMock.SetupGet(bcc => bcc.Value)
            .Returns(TestBackgroundCheckerConfiguration);

            notificationServiceMock = new Mock <INotificationService>();

            logger = new Mock <ILogger <BackgroundChecker> >();

            backgroundChecker = new BackgroundChecker(serviceCheckerMock.Object,
                                                      serviceStoreMock.Object,
                                                      backgroundCheckerConfigurationMock.Object,
                                                      notificationServiceMock.Object,
                                                      logger.Object);
        }