public void RoundTrip()
    {
        var factory    = new EncryptionFactory();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        using (var algorithm = CryptoBuilder.Build())
        {
            string serialized;
            using (factory.GetEncryptSession(algorithm))
            {
                var instance = new ClassToSerialize
                {
                    Property1 = "Property1Value",
                    Property2 = "Property2Value"
                };
                serialized = serializer.Serialize(instance);
            }
            using (factory.GetDecryptSession(algorithm))
            {
                var result = serializer.Deserialize <ClassToSerialize>(serialized);
                ObjectApprover.VerifyWithJson(result);
            }
        }
    }
    public async Task Works()
    {
        var target = new ClassWithString
        {
            Property = "Foo"
        };

        using var factory   = new EncryptionFactory();
        using var algorithm = CryptoBuilder.Build();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        string serialized;

        using (factory.GetEncryptSession(algorithm))
        {
            await Task.Delay(1);

            serialized = serializer.Serialize(target);
        }

        using (factory.GetDecryptSession(algorithm))
        {
            await Task.Delay(1);

            var result = serializer.Deserialize <ClassWithString>(serialized);
            Assert.Equal("Foo", result.Property);
        }
    }
    public void Simple()
    {
        var factory    = new EncryptionFactory();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        using (var algorithm = CryptoBuilder.Build())
            using (factory.GetEncryptSession(algorithm))
            {
                var instance = new ClassToSerialize
                {
                    Property1 = "Property1Value",
                    Property2 = "Property2Value"
                };
                var result = serializer.Serialize(instance);
                Approvals.Verify(result);
            }
    }
Example #4
0
    public static T Run <T>(T instance)
    {
        using (var factory = new EncryptionFactory())
            using (var algorithm = CryptoBuilder.Build())
            {
                var serializer = new JsonSerializer
                {
                    ContractResolver = factory.GetContractResolver()
                };

                string result;
                using (factory.GetEncryptSession(algorithm))
                {
                    result = serializer.Serialize(instance);
                }

                Approvals.Verify(result);
                using (factory.GetDecryptSession(algorithm))
                {
                    return(serializer.Deserialize <T>(result));
                }
            }
    }
Example #5
0
    public static async Task <T> Run <T>(T instance, [CallerFilePath] string sourceFile = "")
    {
        using var factory   = new EncryptionFactory();
        using var algorithm = CryptoBuilder.Build();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        string result;

        using (factory.GetEncryptSession(algorithm))
        {
            result = serializer.Serialize(instance);
        }

        await Verify(result, null, sourceFile);

        using (factory.GetDecryptSession(algorithm))
        {
            return(serializer.Deserialize <T>(result));
        }
    }