public async void ServiceChecker_Throws_Exception_With_Null_ServiceEntry()
        {
            var checker = new ServiceChecker(_checkerLogger);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                             await checker.CheckServiceAsync(null, CancellationToken.None));
        }
Example #2
0
        public ServiceCheckerTests()
        {
            _messageHandlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            var httpClient = new HttpClient(_messageHandlerMock.Object);

            _serviceChecker = new ServiceChecker(httpClient);
        }
        public async Task ServiceChecker_Work()
        {
            // Arrange
            var logger       = new Mock <ILogger <ServiceChecker> >();
            var storeService = new Mock <IStatusLogService>();

            var service1 = new Mock <IStatusProvider>();

            service1
            .Setup(x => x.GetStatusAsync())
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));

            var service2 = new Mock <IStatusProvider>();

            service2
            .Setup(x => x.GetStatusAsync())
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadRequest));

            var sut = new ServiceChecker(logger.Object, new List <IStatusProvider>()
            {
                service1.Object, service2.Object
            }, storeService.Object);
            // Act
            var cts = new CancellationTokenSource();

            await sut.StartAsync(cts.Token);

            await Task.Delay(1000);

            cts.Cancel();

            //Assert
            service1.Verify(m => m.GetStatusAsync(), Times.Once);
            service2.Verify(m => m.GetStatusAsync(), Times.Once);
            storeService.Verify(m => m.AddStatusLog(It.IsAny <StatusLog>()), Times.Exactly(2));
            storeService.Verify(m => m.SaveChangesAsync(), Times.Once);
        }
Example #4
0
 public override bool IsEnabled()
 {
     return(ServiceChecker.IsRunning(name));
 }
Example #5
0
 public ServiceStateMessage(ServiceChecker sender, ServiceControllerStatus?status) : base(sender)
 {
     Status = status;
 }
Example #6
0
 public override bool IsEnabled()
 {
     return(ServiceChecker.IsInstalled(name));
 }