public async Task GivenNoParams_WhenGetSystemInfo_ThenGetSystemInfoCommandSent_AndResponseReturned()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();
            var sut          = new SystemController(
                mockMediator.Object,
                Mock.Of <ILogger <SystemController> >());

            var response = new GetSystemInfoResponse
            {
                SystemInfo = new Dto.Response.SystemInfo
                {
                    StartedAt = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0))
                }
            };

            mockMediator.Setup(x => x.Send <GetSystemInfoResponse>(
                                   It.IsAny <IRequest <GetSystemInfoResponse> >(),
                                   It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(response));

            // Act
            var result = await sut.GetSystemInfo();

            // Assert
            mockMediator.Verify(x => x.Send <GetSystemInfoResponse>(
                                    It.IsAny <IRequest <GetSystemInfoResponse> >(),
                                    It.IsAny <CancellationToken>()), Times.Once);
            Assert.True(result.Success);
            Assert.Equal(response.SystemInfo, result.Value);
        }
Example #2
0
        public async Task ShouldReturnInternalServerErrorWhenGetSystemInfoCalledWithError()
        {
            //Given
            _swarmClient.When(x => x.GetSystemInfo()).Do(_ => throw new ArgumentException());
            var systemService     = new SwarmApi.Services.SystemService(_swarmClient, _loggerFactory);
            var serviceController = new SystemController(systemService);

            //When
            var response = await serviceController.GetSystemInfo();

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(500, result.StatusCode);
        }
Example #3
0
        public async Task ShouldReturnSystemInfoResponseWhenGetSystemInfoCalled()
        {
            //Given
            _swarmClient.GetSystemInfo().Returns(Task.FromResult(_any.Create <SystemInfoResponse>()));
            var systemService     = new SwarmApi.Services.SystemService(_swarmClient, _loggerFactory);
            var serviceController = new SystemController(systemService);

            //When
            var response = await serviceController.GetSystemInfo();

            var result = response as JsonResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
        }