Exemple #1
0
        public void FailWithInvalidXML()
        {
            var exception = Assert.Throws <XmlException>(() => TagDictionary.FromXml("ident", "ThisIsNotXML"));

            Assert.NotNull(exception);
            Assert.AreEqual("Unable to parse XML data", exception.Message);
        }
        public void DbLoginWithKey()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.AreEqual("Data Source=DbServerAddress; Initial Catalog=ZZ-ENV-LOGIN; User ID=ZZ-ENV-LOGIN; Password=Some high entrophy random text;", GetDbLoginValue(sut, "LOGIN", "ConnectionString"));
            Assert.AreEqual("ZZ-ENV-LOGIN", GetDbLoginValue(sut, "LOGIN", "Username"));
            Assert.AreEqual("ZZ-ENV-LOGIN", GetDbLoginValue(sut, "LOGIN", "DefaultDb"));
        }
        public void EndsWith_WhenPropertyDoesntExist_Defaulted(string value, string endsWith, bool expected)
        {
            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties />
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            Assert.AreEqual(expected.ToString().ToLower(), "{% if Data|default:'#value#'|endsWith:'#endsWith#' %}true{% else %}false{% endif %}".Replace("#endsWith#", endsWith).Replace("#value#", value).RenderTemplate(sut.ToLazyTagDictionary()));
        }
        public void StartsWith(string value, string startsWith, bool expected)
        {
            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">{value}</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            Assert.AreEqual(expected.ToString().ToLower(), "{% if Data|startsWith:'#startsWith#' %}true{% else %}false{% endif %}".Replace("#startsWith#", startsWith).RenderTemplate(sut.ToLazyTagDictionary()));
        }
        public void EndsWith_WhenPropertyDoesntExist_Throws()
        {
            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">Value</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            Assert.Throws <NDjangoWrapper.NDjangoWrapperException>(() => "{% if Undata|startsWith:'V' %}true{% else %}false{% endif %}".RenderTemplate(sut.ToLazyTagDictionary()));
        }
Exemple #6
0
        public void EndsWith_EmptyString_Throws()
        {
            var sut = TagDictionary.FromXml("ident", @"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">Value</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            Assert.Throws <ArgumentException>(() => "{% if Data|endsWith:'' %}true{% else %}false{% endif %}".RenderTemplate(sut.ToLazyTagDictionary()));
        }
Exemple #7
0
        public void Encrypt_Test()
        {
            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">hello</Property>
                                                        <Property name=""Certificate"">XX-NON-Certificate</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            var data = "{{ Data|encrypt:Certificate }}".RenderTemplate(sut.ToLazyTagDictionary());

            Assert.IsNotNull(data);
            Console.WriteLine(data);
        }
Exemple #8
0
        public void Decrypt_Test()
        {
            string value = "qMMwh9SXoPUnTJeSm1Valokg9jPmekkkVy8VwRNGzpKruLZIgHoBjazLcym4voW8mQT8uadvyvs3TSWUMGo/70PFQZhkR60RVs8v0BcQWJowdF00j2c3KKcoQFutP/Y9UR+7L88cpRiS9/KosIYssZ+1kfkAne0skWENAdL1JUe0c2v7vXy+EXuInkuuX5lQuBngHlb35TtXdgYK46b4XSzuPFtDGwk3yV4MXSXjOOXgy/0dQLHxq6mn7kIDnlQeApgie9tnss3jIQlv1rvGVi3iChT+RADCdubNXw4XU3PDPV3I0ayMNRH5gysG41eJP4opQ2QJ+e68dfLwGGLyyA==";

            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">{value}</Property>
                                                        <Property name=""Certificate"">XX-NON-Certificate</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            var expected = "hello";

            Assert.AreEqual(expected.ToString().ToLower(), "{{ Data|decrypt:Certificate }}".RenderTemplate(sut.ToLazyTagDictionary()));
        }
        [Explicit] // You can only run this with a specific certificate loaded into your computer
        public void Decrypt_Test()
        {
            string value = "fQF5wgZ4J9+lm2LbpqoxWeeao6A9x1XoIc3VTDSHBosJ1tM/mLX2XO8+AENaizmalFhCD1YKK4j7YmzEP72FwtfGgm2jazDGNb1WR440ZPL96P/tO/dKvy53KHtlkY76qFiP2KZPxRWjbem+5kpWn5lLczwl/7lQfBAM6ntawghntVAA7l7gwvKDuq2FcVIP3Njdu3DzSWPgP4P83pQxn04KtG7fO0VudUXjllI6Y/LAgpovYuC1SR3lTw33V4KVPXcOvB16bwplw+izKGWBn9Wjc6B0IxyW0tSz87ETzuL0HpiOeTZvEObrzSXlCjz3qbt4mf5gQ9QN4Gk7tLpOAZhrV1fn94IDL+l73KDbQDVo/HsX5sFFK1amFu7669kjlCOtiXxS9nZ35GtMVV2N+TC78xg0tAmYZtCOaJ+AgKoPj+PZTaR+Heu+nddiy7EAsezQ0FePxL1FN6+VcMydA16htdfdhwBzt/Sjql1LLoqSuaduOvXwftkOfhl3ylVRNnGjgHtIlAAEXtxfyitxVQSVVDgPRwfncB0S4LgpXrnuw+Bj7CuslXvCL6x9ZCp5PYqcXTYcwuv/xysFrTKM0k6xS4D6mIShlOwOxaMm0nntg3VBIXwJZULHabd/xMb2UkwQOAjKvgplLmduaSeGdS8axup326eSmEDRXQlHqUM=";

            var sut = TagDictionary.FromXml("ident", $@"<Structure xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
                                                      <ClientCode>XX</ClientCode>
                                                      <Environment>LOC</Environment>
                                                      <Properties>
                                                        <Property name=""Data"">{value}</Property>
                                                        <Property name=""Certificate"">XX-NON-Certificate</Property>
                                                      </Properties>
                                                      <PropertyGroups />
                                                      <DbLogins />
                                                  </Structure>");

            var expected = "hello";

            Assert.AreEqual(expected.ToString().ToLower(), "{{ Data|decrypt:Certificate }}".RenderTemplate(sut.ToLazyTagDictionary()));
        }
        public void DbLoginDefaultDbsAreSubstituted()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.AreEqual("FAA-LOC-AUDIT", GetDbLoginValue(sut, "AUDIT", "DefaultDb"));
        }
        public void TestDefaultLoader(string expected, string key)
        {
            var loader = TagDictionary.FromXml("myId", XmlData);

            Assert.AreEqual(expected, loader[key]);
        }
        public void LoadEnvironmentOnlyWithInvalidXML()
        {
            var sut = TagDictionary.FromXml("ident", "ThisIsNotXML");

            Assert.AreEqual(EnvClientCode, sut["ClientCode"]);
        }
        public void DbLoginsGenerated()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.AreEqual("This isn't a password either", GetDbLoginValue(sut, "config", "Password"));
        }
 public void PropertyAndLabelWithSameNameThrowException()
 {
     Environment.SetEnvironmentVariable("GDS", "This shouldn't be here");
     Assert.Throws <InvalidDataException>(() => TagDictionary.FromXml("ident", XmlData));
     Environment.SetEnvironmentVariable("GDS", null);
 }
        public void LoadFlatLabelledGroups()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.IsTrue(sut.ContainsKey("FlatGroup"));
        }
        public void DbLoginNamesAreSubstituted()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.AreEqual(string.Format("{0}-{1}-AUDIT", Environment.GetEnvironmentVariable("ClientCode"), Environment.GetEnvironmentVariable("Environment")), GetDbLoginValue(sut, "AUDIT", "Username"));
        }
        public void DbLoginConnectionStringLoaded()
        {
            var sut = TagDictionary.FromXml("ident", XmlData);

            Assert.AreEqual("Actual ConnectionString", GetDbLoginValue(sut, "ConnectionString", "ConnectionString"));
        }