public void AssertElementText_should_not_throw_exception_when_element_has_expected_text_and_attributes()
        {
            var tester = new XmlTester(FormattedXml("<textSection><textElem att1=\"value1\">test string</textElem></textSection>"));

            AssertExceptionNotThrown
            .WhenExecuting(() => tester.AssertElementText("configuration/textSection/textElem", "test string"));
        }
Ejemplo n.º 2
0
        public void AssertAppSettingsValueMatch_should_not_throw_exception_when_value_matches()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            AssertExceptionNotThrown
            .WhenExecuting(() => tester.AssertAppSettingsValueMatch("testKey", ".*Value"));
        }
        public void GetElements_should_return_empty_enumerable_when_elements_do_not_exist()
        {
            var tester = new XmlTester(FormattedXml());

            XElement[] elems = tester.GetElements("configuration/appSettings/add").ToArray();

            Assert.AreEqual(0, elems.Length);
        }
        public void AssertAttributeValue_should_not_throw_when_value_matches()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "testValue"));

            AssertExceptionNotThrown
            .WhenExecuting(() =>
                           tester.AssertAttributeValue(ConfigXPath.AppSettingForKey("testKey"), "value", "testValue"));
        }
        public void GetElement_should_return_element_when_it_exists()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            XElement elem = tester.GetElement(ConfigXPath.AppSettingForKey("testKey"));

            Assert.IsNotNull(elem);
        }
        public void GetElement_should_return_null_when_element_does_not_exist()
        {
            var tester = new XmlTester(FormattedXml());

            XElement elem = tester.GetElement(ConfigXPath.AppSettingForKey("testKey"));

            Assert.IsNull(elem);
        }
        public void GetAttributeValue_should_return_value_when_attribute_exists()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "testValue"));

            XElement elem = tester.GetElement(ConfigXPath.AppSettingForKey("testKey"));

            Assert.AreEqual("testValue", tester.GetAttributeValue(elem, "value"));
        }
        public void GetAttributeValue_should_return_null_when_attribute_does_not_exist()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            XElement elem = tester.GetElement(ConfigXPath.AppSettingForKey("testKey"));

            Assert.IsNull(tester.GetAttributeValue(elem, "badAttributeName"));
        }
Ejemplo n.º 9
0
 protected MappingToXmlTesterBase(ISimpleLogger logger, ILogAsserter logAsserter)
 {
     this.Logger    = logger;
     this.LogAssert = logAsserter;
     this.xmlTester = new XmlTester(logAsserter);
     this.xmlTester.ActualXmlChangedEvent   += this.XmlTester_ActualXmlChangedEvent;
     this.xmlTester.ExpectedXmlChangedEvent += this.XmlTester_ExpectedXmlChangedEvent;
 }
Ejemplo n.º 10
0
        public void AssertAppSettingsKeyDoesNotExist_should_throw_exception_when_key_exists()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "testValue"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("Element should not exist: configuration/appSettings/add[@key='testKey']")
            .WhenExecuting(() => tester.AssertAppSettingsKeyDoesNotExist("testKey"));
        }
Ejemplo n.º 11
0
        public void AssertCompilationDebugFalse_should_throw_exception_when_attribute_is_true()
        {
            var tester = new XmlTester(FormattedXml("<system.web><compilation defaultLanguage=\"c#\" debug=\"true\" /></system.web>"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("configuration/system.web/compilation@debug: Expected: <false> actual: <true>")
            .WhenExecuting(() => tester.AssertCompilationDebugFalse());
        }
Ejemplo n.º 12
0
        public void AssertAppSettingsValueMatch_should_throw_exception_when_key_does_not_exist()
        {
            var tester = new XmlTester(FormattedXml());

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("Element not found: configuration/appSettings/add[@key='testKey']")
            .WhenExecuting(() => tester.AssertAppSettingsValueMatch("testKey", "testValue"));
        }
Ejemplo n.º 13
0
        public void AssertElementText_should_throw_exception_when_element_not_found()
        {
            var tester = new XmlTester(FormattedXml());

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("Element not found: configuration/textSection/textElem")
            .WhenExecuting(() => tester.AssertElementText("configuration/textSection/textElem", "test string"));
        }
Ejemplo n.º 14
0
        public void AssertElementText_should_throw_exception_when_element_has_children()
        {
            var tester = new XmlTester(FormattedXml("<textSection><textElem><child>child text</child></textElem></textSection>"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("configuration/textSection/textElem has child element(s). Expected element with text content: \"test string\".")
            .WhenExecuting(() => tester.AssertElementText("configuration/textSection/textElem", "test string"));
        }
Ejemplo n.º 15
0
        public void AssertElementText_should_throw_exception_when_element_has_unexpected_text()
        {
            var tester = new XmlTester(FormattedXml("<textSection><textElem>wrong string</textElem></textSection>"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("configuration/textSection/textElem: Expected text: <test string> actual: <wrong string>")
            .WhenExecuting(() => tester.AssertElementText("configuration/textSection/textElem", "test string"));
        }
Ejemplo n.º 16
0
        public void AssertAppSettingsValueMatch_should_throw_exception_when_value_does_not_match()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("configuration/appSettings/add[@key='testKey']@value:"
                         + " Value \"actualValue\" doesn't match regex pattern \"testPattern\".")
            .WhenExecuting(() => tester.AssertAppSettingsValueMatch("testKey", "testPattern"));
        }
Ejemplo n.º 17
0
        public void AssertAppSettingsValue_should_throw_exception_when_value_does_not_match()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("configuration/appSettings/add[@key='testKey']@value:"
                         + " Expected: <expectedValue> actual: <actualValue>")
            .WhenExecuting(() => tester.AssertAppSettingsValue("testKey", "expectedValue"));
        }
Ejemplo n.º 18
0
        public void AssertClientEndpointAddressIsWellFormedUrl_should_not_throw_exception_for_valid_URL()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service.svc\" name=\"testName\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertClientEndpointAddressIsWellFormedUrl("testName"));
        }
Ejemplo n.º 19
0
        public void AssertAttributeValueIsWellFormedUrl_should_not_throw_exeption_when_value_is_valid_URL()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service.svc\" name=\"testName\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertAttributeValueIsWellFormedUrl(
                                                       ConfigXPath.ClientEndpointForName("testName"), "address"));
        }
Ejemplo n.º 20
0
        public void Exceptions_should_use_exceptionPrefix_when_supplied()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"), "EXCEPTION_PREFIX: ");

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("EXCEPTION_PREFIX: Element found, but attribute does not exist: "
                         + "configuration/appSettings/add[@key='testKey']@badAttribute")
            .WhenExecuting(() =>
                           tester.AssertAttributeValue(ConfigXPath.AppSettingForKey("testKey"), "badAttribute", "value"));
        }
Ejemplo n.º 21
0
        public void GetConnectionString_should_return_expected_value()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<connectionStrings>"
                                           + "<add name=\"Name1\" connectionString=\"String1\" />"
                                           + "<add name=\"Name2\" connectionString=\"String2\" />"
                                           + "<add name=\"Name3\" connectionString=\"String3\" />"
                                           + "</connectionStrings>"));

            Assert.AreEqual("String3", tester.GetConnectionString("Name3"));
        }
Ejemplo n.º 22
0
        public void ConfigXPath_authentication_constants_should_be_correct()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.webServer><security><authentication>"
                                           + "<anonymousAuthentication enabled=\"true\" />"
                                           + "<windowsAuthentication enabled=\"false\" />"
                                           + "</authentication></security></system.webServer>"));

            tester.AssertAttributeValue(ConfigXPath.AnonymousAuthentication, "enabled", "true");
            tester.AssertAttributeValue(ConfigXPath.WindowsAuthentication, "enabled", "false");
        }
Ejemplo n.º 23
0
        public void AssertAttributeValueMatch_should_throw_exception_when_attribute_does_not_exist()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("Element found, but attribute does not exist: "
                         + "configuration/appSettings/add[@key='testKey']@badAttribute")
            .WhenExecuting(() =>
                           tester.AssertAttributeValueMatch(ConfigXPath.AppSettingForKey("testKey"), "badAttribute", "value"));
        }
Ejemplo n.º 24
0
        public void AssertAppSettingsValues_should_not_throw_exception_when_values_match()
        {
            KeyValuePair <string, string>[] appSettings =
                Enumerable.Range(1, 5).Select(i => new KeyValuePair <string, string>($"key{i}", $"value{i}")).ToArray();

            string appSettingsXml = string.Join("\n", appSettings.Select(kv => FormattedAppSettingsElem(kv.Key, kv.Value)));

            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(appSettingsXml)));

            AssertExceptionNotThrown.WhenExecuting(() => tester.AssertAppSettingsValues(appSettings));
        }
Ejemplo n.º 25
0
        public void GetElements_should_return_elements_when_they_exist()
        {
            string appSettingsXml = string.Join("\n",
                                                Enumerable.Range(1, 5).Select(i => FormattedAppSettingsElem($"key{i}", $"value{i}")));

            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(appSettingsXml)));

            XElement[] elems = tester.GetElements("configuration/appSettings/add").ToArray();

            Assert.AreEqual(5, elems.Length);
        }
Ejemplo n.º 26
0
        public void AssertClientEndpointAddressesAreWellFormedUrls_should_not_throw_exeption_when_URLs_are_valid()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service1.svc\" name=\"name1\" />"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service2.svc\" name=\"name2\" />"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service3.svc\" name=\"name3\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() => tester.AssertClientEndpointAddressesAreWellFormedUrls());
        }
Ejemplo n.º 27
0
        public void GetClientEndpointAddress_should_throw_exception_when_endpoint_not_found()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"testAddress\" name=\"testName\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionThrown
            .OfType <XmlTesterException>()
            .WithMessage("Element not found: configuration/system.serviceModel/client/endpoint[@name='badName']")
            .WhenExecuting(() => tester.GetClientEndpointAddress("badName"));
        }
Ejemplo n.º 28
0
        public void AssertNoDuplicateElements_should_not_throw_exception_when_there_are_no_duplicates()
        {
            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(
                                                        FormattedAppSettingsElem("key1", "value1")
                                                        + FormattedAppSettingsElem("key2", "value2")
                                                        + FormattedAppSettingsElem("key3", "value3")
                                                        + FormattedAppSettingsElem("key4", "value4")
                                                        )));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertNoDuplicateElements(ConfigXPath.AppSettings, "key"));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Assert that confirmation/system.web/compilation "debug" attribute has been removed or set to false.
        /// </summary>
        /// <param name="xmlTester"><see cref="XmlTester"/>.</param>
        /// <exception cref="XmlTesterException">if element has debug value of true.</exception>
        public static void AssertCompilationDebugFalse(this XmlTester xmlTester)
        {
            var elem = xmlTester.GetElement(ConfigXPath.SystemWebCompilation);

            if (elem != null)
            {
                string value = xmlTester.GetAttributeValue(elem, "debug");
                if (value == "true")
                {
                    xmlTester.AssertAttributeValue(ConfigXPath.SystemWebCompilation, "debug", "false");
                }
            }
        }
Ejemplo n.º 30
0
        public void AssertNoDuplicateElements_should_ignore_specified_keys()
        {
            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(
                                                        FormattedAppSettingsElem("TransformApplied", "transform1")
                                                        + FormattedAppSettingsElem("TransformApplied", "transform2")
                                                        + FormattedAppSettingsElem("key1", "value1")
                                                        + FormattedAppSettingsElem("key2", "value2")
                                                        + FormattedAppSettingsElem("key3", "value3")
                                                        + FormattedAppSettingsElem("key4", "value4")
                                                        )));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertNoDuplicateElements(ConfigXPath.AppSettings, "key", "TransformApplied"));
        }