Beispiel #1
0
        public async Task ShouldReturnClusterIdWhenInitClusterCalled()
        {
            //Given
            const string clusterId = "1234";

            _swarmClient.InitCluster(Arg.Any <SwarmInitParameters>()).Returns(Task.FromResult(clusterId));
            var swarmService      = new SwarmApi.Services.SwarmService(_swarmClient, _loggerFactory);
            var serviceController = new SwarmController(swarmService);

            //When
            var response = await serviceController.InitCluster(new SwarmApi.Dtos.ClusterInitParameters {
                AdvertiseAddress = "192.168.0.101",
                ListenAddress    = "192.168.0.101"
            });

            var result  = response as JsonResult;
            var content = result.Value;

            //Then
            Assert.NotNull(result);
            string id = content.GetType().GetProperty("Id").GetValue(content, null).ToString();

            Assert.Equal(200, result.StatusCode);
            Assert.Equal(clusterId, id);
        }
Beispiel #2
0
        public async Task ShouldReturnBadRequestWhenIpIsNotValidAddress(string adverIp, string listenIp, string message)
        {
            //Given
            var swarmService      = new SwarmApi.Services.SwarmService(_swarmClient, _loggerFactory);
            var serviceController = new SwarmController(swarmService);

            //When
            var response = await serviceController.InitCluster(new SwarmApi.Dtos.ClusterInitParameters {
                AdvertiseAddress = adverIp,
                ListenAddress    = listenIp
            });

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
            Assert.Equal(message, result.Content);
        }
Beispiel #3
0
        public async Task ShouldReturnInternalServerErrorWhenInitClusterCalledWithError()
        {
            //Given
            _swarmClient.When(x => x.InitCluster(Arg.Any <SwarmInitParameters>())).Do(_ => throw new InvalidCastException());
            var swarmService      = new SwarmApi.Services.SwarmService(_swarmClient, _loggerFactory);
            var serviceController = new SwarmController(swarmService);

            //When
            var response = await serviceController.InitCluster(new SwarmApi.Dtos.ClusterInitParameters {
                AdvertiseAddress = "192.168.0.101",
                ListenAddress    = "192.168.0.101"
            });

            var result = response as ContentResult;

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