Пример #1
0
        public async Task ShouldReturnBadRequestWhenNameIsEmpty()
        {
            //Given
            _swarmClient.CreateSecret(Arg.Any <SecretSpec>()).Returns(x => _any.Create <SecretCreateResponse>());
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.CreateSecret(new SwarmApi.Dtos.SecretParameters {
                Content = _any.Create <string>(),
                Name    = string.Empty
            });

            var result = response as ContentResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
            Assert.Equal("Name field cannot be empty.", result.Content);
        }
Пример #2
0
        public async Task ShouldCreateNewSecretWhenCreateSecretCalled()
        {
            //Given
            const string secretName = "test-secret";

            _swarmClient.CreateSecret(Arg.Any <SecretSpec>()).Returns(x => _any.Create <SecretCreateResponse>());
            var secretService    = new SecretService(_swarmClient, _loggerFactory);
            var secretController = new SecretController(secretService);

            //When
            var response = await secretController.CreateSecret(new SwarmApi.Dtos.SecretParameters {
                Content = _any.Create <string>(),
                Name    = secretName
            });

            var result = response as CreatedResult;

            //Then
            Assert.NotNull(result);
            Assert.Equal($"/api/secret/{secretName}", result.Location);
        }