Example #1
0
        public void DecryptSucceedsWithExistingICrypto()
        {
            ICrypto fooCrypto = CreateICrypto("foo");
            ICrypto barCrypto = CreateICrypto("bar");

            var compositeCrypto = new CompositeCrypto(new List <ICrypto> {
                fooCrypto, barCrypto
            });

            compositeCrypto.Decrypt("stuff", "foo").Should().Be("DecryptedString : foo");
            compositeCrypto.Decrypt(new byte[0], "foo").Should().BeEquivalentTo(Encoding.UTF8.GetBytes("foo"));
            compositeCrypto.Decrypt("stuff", "bar").Should().Be("DecryptedString : bar");
            compositeCrypto.Decrypt(new byte[0], "bar").Should().BeEquivalentTo(Encoding.UTF8.GetBytes("bar"));
        }
Example #2
0
        public void DecryptThrowsWhenICryptoDoesntExist()
        {
            ICrypto fooCrypto = CreateICrypto("foo");
            ICrypto barCrypto = CreateICrypto("bar");

            var compositeCrypto = new CompositeCrypto(new List <ICrypto> {
                fooCrypto, barCrypto
            });

            Action action = () => compositeCrypto.Decrypt("stuff", "baz");

            action.ShouldThrow <KeyNotFoundException>()
            .WithMessage("Unable to locate implementation of ICrypto that can locate a credential using credentialName: baz");
        }