コード例 #1
0
        public void GetKeys()
        {
            var prefix = "/" + BasePrefix + "/";

            _mockSSM.Setup(client => client.GetParametersByPathAsync(It.IsAny <GetParametersByPathRequest>(), It.IsAny <CancellationToken>()))
            .Callback <GetParametersByPathRequest, CancellationToken>((request, token) =>
            {
                Assert.NotNull(request.Path);
                Assert.Equal(prefix, request.Path);

                Assert.True(request.WithDecryption);
            })
            .Returns((GetParametersByPathRequest r, CancellationToken token) =>
            {
                var response = new GetParametersByPathResponse();
                response.Parameters.Add(new Parameter
                {
                    Name  = prefix + "foo",
                    Type  = ParameterType.SecureString,
                    Value = "<key id=\"foo\"></key>"
                });
                response.Parameters.Add(new Parameter
                {
                    Name  = prefix + "bar",
                    Type  = ParameterType.SecureString,
                    Value = "<key id=\"bar\"></key>"
                });
                return(Task.FromResult(response));
            });

            var repository = new SSMXmlRepository(_mockSSM.Object, prefix, null, null);

            var elements = repository.GetAllElements();

            Assert.Equal(2, elements.Count);
            foreach (var key in elements)
            {
                Assert.NotNull(key);
            }
        }
コード例 #2
0
        public void EnsureValidKeysComebackEvenWhenOneIsInvalid()
        {
            var prefix = "/" + BasePrefix + "/";

            _mockSSM.Setup(client => client.GetParametersByPathAsync(It.IsAny <GetParametersByPathRequest>(), It.IsAny <CancellationToken>()))
            .Callback <GetParametersByPathRequest, CancellationToken>((request, token) =>
            {
                Assert.NotNull(request.Path);
                Assert.Equal(prefix, request.Path);

                Assert.True(request.WithDecryption);
            })
            .Returns((GetParametersByPathRequest r, CancellationToken token) =>
            {
                var response = new GetParametersByPathResponse();
                response.Parameters.Add(new Parameter
                {
                    Name  = prefix + "foo",
                    Type  = ParameterType.SecureString,
                    Value = "<key id=\"foo\"></key>"
                });
                response.Parameters.Add(new Parameter
                {
                    Name  = prefix + "bar",
                    Type  = ParameterType.SecureString,
                    Value = "<key id=\"bar\"></missing-endtag>"
                });
                return(Task.FromResult(response));
            });

            var repository = new SSMXmlRepository(_mockSSM.Object, prefix, null, null);

            var elements = repository.GetAllElements();

            Assert.Equal(1, elements.Count);
            Assert.NotNull(elements.FirstOrDefault(x => string.Equals(x.Attribute("id").Value, "foo")));
        }