Beispiel #1
0
        public void OkEncodeDecodeReplace()
        {
            // arrange
            var    encryptorDecryptor = new EncryptorDecryptor();
            var    inputFilePath      = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "CustomXdtTransforms.Tests", "TestAppConfigs", "TestApp.config");
            var    transformFilePath  = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "CustomXdtTransforms.Tests", "TestAppConfigs", "TestApp.Debug.config");
            string result;

            // act
            using (var input = new XmlTransformableDocument())
                using (var transformer = new XmlTransformation(transformFilePath))
                {
                    input.Load(inputFilePath);
                    transformer.Apply(input);

                    using (var stringWriter = new StringWriter())
                        using (var xmlWriter = XmlWriter.Create(stringWriter))
                        {
                            input.WriteContentTo(xmlWriter);
                            xmlWriter.Flush();
                            result = stringWriter.ToString();

                            var xmlDoc = XDocument.Parse(result);

                            var root = xmlDoc.Root;

                            // assert
                            var ecnrypteNode2          = root.Descendants("setting").Single(x => x.Attribute("name").Value == "ExpectedEncrypted2");
                            var ecnrypteNode2Attrubute = ecnrypteNode2.Attribute("serializeAs").Value;
                            encryptorDecryptor.Decrypt(ecnrypteNode2Attrubute).Should().Be("String");
                            var encryptedNode2Value = ecnrypteNode2.Value;
                            encryptorDecryptor.Decrypt(encryptedNode2Value).Should().Be("SomeNewEncryptedValue2");
                        }
                }
        }
        public static XDocument Transform(string appConfig, string transformConfig)
        {
            var transformation = new XmlTransformation(transformConfig, false, null);

            var configurationFileDocument = new XmlTransformableDocument();

            configurationFileDocument.LoadXml(appConfig);

            transformation.Apply(configurationFileDocument);

            var sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb))
            {
                configurationFileDocument.WriteContentTo(writer);
            }

            return(XDocument.Parse(sb.ToString()));
        }
Beispiel #3
0
        public void OkEncodeDecodeReplaceAttributeAndInnerTextByXPath()
        {
            // arrange
            var encryptorDecryptor = new EncryptorDecryptor();

            var dllPath       = Assembly.GetAssembly(typeof(TestEnvironmentForEncode)).EscapedCodeBase.TrimStart("file:///".ToArray());
            var appConfigPath = string.Format("{0}.config", dllPath);


            using (var input = new XmlTransformableDocument())
            {
                input.Load(appConfigPath);

                using (var stringWriter = new StringWriter())
                    using (var xmlWriter = XmlWriter.Create(stringWriter))
                    {
                        input.WriteContentTo(xmlWriter);
                        xmlWriter.Flush();
                        var result = stringWriter.ToString();

                        var doc = XDocument.Parse(result);

                        var root = doc.Root;

                        // assert
                        var encryptedNode1          = root.Descendants("setting").Single(x => x.Attribute("name").Value == "ExpectedEncrypted1");
                        var encryptedNode1Attribute = encryptedNode1.Attribute("serializeAs").Value;
                        encryptorDecryptor.Decrypt(encryptedNode1Attribute).Should().Be("String");
                        var encryptedNode1Value = encryptedNode1.Value;
                        encryptorDecryptor.Decrypt(encryptedNode1Value).Should().Be("SomeNewEncryptedValue1");

                        var encryptedNode2          = root.Descendants("setting").Single(x => x.Attribute("name").Value == "ExpectedEncrypted2");
                        var encryptedNode2Attribute = encryptedNode2.Attribute("serializeAs").Value;
                        encryptorDecryptor.Decrypt(encryptedNode2Attribute).Should().Be("String");
                        var encryptedNode2Value = encryptedNode2.Value;
                        encryptorDecryptor.Decrypt(encryptedNode2Value).Should().Be("EncryptedValue2");
                    }
            }
        }