コード例 #1
0
        public async Task ShouldReturnInternalServerErrorWhenGetServicesCalledAndErrorOccour()
        {
            //Given
            _swarmClient.When(x => {
                x.GetServices();
            }).Do(_ => { throw new Exception(); });
            var swarmService      = new SwarmApi.Services.SwarmService(_swarmClient, _loggerFactory);
            var serviceController = new SwarmController(swarmService);

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

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(500, result.StatusCode);
        }
コード例 #2
0
        public async Task ShouldReturnAllServicesInfoWhenGetServicesCalled()
        {
            //Given
            _swarmClient.GetServices().Returns(x => {
                return(Task.FromResult <IEnumerable <SwarmService> >(new [] { _any.Create <SwarmService>(), _any.Create <SwarmService>() }));
            });
            var swarmService      = new SwarmApi.Services.SwarmService(_swarmClient, _loggerFactory);
            var serviceController = new SwarmController(swarmService);

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

            var jsonResult = response as JsonResult;
            var value      = jsonResult?.Value as IEnumerable <SwarmService>;

            //Then
            Assert.NotNull(jsonResult);
            Assert.NotNull(value);
            Assert.Equal(200, jsonResult.StatusCode);
            Assert.Equal(2, value.Count());
        }