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")); }
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")); }
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; }
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")); }
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()); }
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")); }
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")); }
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")); }
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")); }
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")); }
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")); }
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")); }
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")); }
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")); }
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")); }
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"); }
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")); }
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)); }
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); }
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()); }
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")); }
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")); }
/// <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"); } } }
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")); }