diff options
author | Hugh Bellamy <hughbellars@gmail.com> | 2017-06-23 22:33:47 +0300 |
---|---|---|
committer | Dan Moseley <danmose@microsoft.com> | 2017-06-23 22:33:47 +0300 |
commit | 59915687bb261efeae70565d0ca8990ac45ceb9c (patch) | |
tree | 383131ec60df92b19c95d7103c1eb7e1bf577426 /src/System.Private.Xml.Linq | |
parent | 876acca296364f025a1920ecbe23bd0e5b547932 (diff) |
Convert most Assert.Throws<ArgumentException> without param name to AssertExtensions (#21455)
* Registry
* Collections
* ComponentModel
* Configuration
* Data
* Globalization
* Drawing
* Diagnostics
* IO
* Linq
* Add System.Net param names in tests
* Move ArgumentExceptions in System.Private.Xml to AssertExtensions
* Add System.Reflection.* ArgumentException param names
* Add param names for System.Runtime* ArgumentExceptions
* Add ArgumentException param names to System.Security.*
* Add ArgumentException param names to System.Text.*
* Add param names to ArgumentExceptions in misc projects
* Add System.Threading.* ArgumentException param names
* Fix missing files
* Fixes for unix and netfx
* Fix more failures and revert a IdnaConformance tests to avoid merge conflicts with #21463
Diffstat (limited to 'src/System.Private.Xml.Linq')
14 files changed, 40 insertions, 25 deletions
diff --git a/src/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs b/src/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs index 3917b8b3a0..029de3b39c 100644 --- a/src/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs +++ b/src/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs @@ -132,19 +132,19 @@ namespace System.Xml.Linq.Tests public static IEnumerable<object[]> GetNotXNodes() { - yield return new object[] { new XAttribute("a", "A"), new XElement("E") }; - yield return new object[] { new XDeclaration("1.0", "UFT8", "false"), new XElement("E") }; - yield return new object[] { "", new XElement("E") }; - yield return new object[] { new XElement("E"), new XAttribute("a", "A") }; - yield return new object[] { new XElement("E"), new XDeclaration("1.0", "UFT8", "false") }; - yield return new object[] { new XElement("E"), "" }; + yield return new object[] { new XAttribute("a", "A"), new XElement("E"), "x" }; + yield return new object[] { new XDeclaration("1.0", "UFT8", "false"), new XElement("E"), "x" }; + yield return new object[] { "", new XElement("E"), "x" }; + yield return new object[] { new XElement("E"), new XAttribute("a", "A"), "y" }; + yield return new object[] { new XElement("E"), new XDeclaration("1.0", "UFT8", "false"), "y" }; + yield return new object[] { new XElement("E"), "", "y" }; } [Theory] [MemberData(nameof(GetNotXNodes))] - public void NotXNode(object x, object y) + public void NotXNode(object x, object y, string paramName) { - Assert.Throws<ArgumentException>(() => ((IComparer)XNode.DocumentOrderComparer).Compare(x, y)); + AssertExtensions.Throws<ArgumentException>(paramName, () => ((IComparer)XNode.DocumentOrderComparer).Compare(x, y)); } [Fact] diff --git a/src/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj b/src/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj index 772734494a..578b5720fb 100644 --- a/src/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj +++ b/src/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj @@ -18,6 +18,9 @@ <Compile Include="IXmlLineInfo.cs" /> <Compile Include="NamespaceAccessors.cs" /> <Compile Include="XElement_Value.cs" /> + <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs"> + <Link>Common\System\AssertExtensions.cs</Link> + </Compile> </ItemGroup> <ItemGroup> <ProjectReference Include="$(CommonTestPath)\System\Xml\XmlCoreTest\XmlCoreTest.csproj" /> diff --git a/src/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs b/src/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs index ce0d6ade93..3dc1d58ea8 100644 --- a/src/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs +++ b/src/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs @@ -60,7 +60,7 @@ namespace XDocumentTests.SDMSample // Not allowed to add a document as a child. XDocument document = new XDocument(); - Assert.Throws<ArgumentException>(() => element.Add(document)); + AssertExtensions.Throws<ArgumentException>(null, () => element.Add(document)); } /// <summary> @@ -72,7 +72,7 @@ namespace XDocumentTests.SDMSample // Not allowed to add attributes in the general case. // The only general case of a container is a document. XDocument document = new XDocument(); - Assert.Throws<ArgumentException>(() => document.Add(new XAttribute("foo", "bar"))); + AssertExtensions.Throws<ArgumentException>(null, () => document.Add(new XAttribute("foo", "bar"))); // Can add to elements, but no duplicates allowed. XElement e = new XElement("element"); @@ -127,7 +127,7 @@ namespace XDocumentTests.SDMSample // Can't use to add attributes. XAttribute a = new XAttribute("foo", "bar"); - Assert.Throws<ArgumentException>(() => element.AddFirst(a)); + AssertExtensions.Throws<ArgumentException>(null, () => element.AddFirst(a)); } /// <summary> diff --git a/src/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs b/src/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs index 79f6db7395..1efa4b1edc 100644 --- a/src/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs +++ b/src/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs @@ -141,8 +141,8 @@ namespace XDocumentTests.SDMSample doc.Add(" \t" + Environment.NewLine); Assert.Equal(" \t" + Environment.NewLine, doc.ToString(SaveOptions.DisableFormatting)); - Assert.Throws<ArgumentException>(() => doc.Add("a")); - Assert.Throws<ArgumentException>(() => doc.Add("\tab")); + AssertExtensions.Throws<ArgumentException>(null, () => doc.Add("a")); + AssertExtensions.Throws<ArgumentException>(null, () => doc.Add("\tab")); } } } diff --git a/src/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs b/src/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs index a5ac9fcc4c..4bcefe1d3b 100644 --- a/src/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs +++ b/src/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs @@ -769,7 +769,7 @@ namespace XDocumentTests.SDMSample XElement e = new XElement(ns + "foo"); Assert.Throws<ArgumentNullException>(() => e.GetNamespaceOfPrefix(null)); - Assert.Throws<ArgumentException>(() => e.GetNamespaceOfPrefix(string.Empty)); + AssertExtensions.Throws<ArgumentException>(null, () => e.GetNamespaceOfPrefix(string.Empty)); XNamespace n = e.GetNamespaceOfPrefix("xmlns"); Assert.Equal("http://www.w3.org/2000/xmlns/", n.NamespaceName); diff --git a/src/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs b/src/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs index 9fbf35195c..fd5f1a8d0e 100644 --- a/src/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs +++ b/src/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs @@ -30,9 +30,9 @@ namespace XDocumentTests.SDMSample Assert.Throws<ArgumentNullException>(() => XName.Get(null)); Assert.Throws<ArgumentNullException>(() => XName.Get(null, "foo")); Assert.Throws<ArgumentNullException>(() => XName.Get(string.Empty, "foo")); - Assert.Throws<ArgumentException>(() => XName.Get(string.Empty)); - Assert.Throws<ArgumentException>(() => XName.Get("{}")); - Assert.Throws<ArgumentException>(() => XName.Get("{foo}")); + AssertExtensions.Throws<ArgumentException>(null, () => XName.Get(string.Empty)); + AssertExtensions.Throws<ArgumentException>(null, () => XName.Get("{}")); + AssertExtensions.Throws<ArgumentException>(null, () => XName.Get("{foo}")); } /// <summary> diff --git a/src/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj b/src/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj index efa7daccce..a1346c0047 100644 --- a/src/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj +++ b/src/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj @@ -21,6 +21,9 @@ <Compile Include="SDMNode.cs" /> <Compile Include="SDMPI.cs" /> <Compile Include="SDMXName.cs" /> + <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs"> + <Link>Common\System\AssertExtensions.cs</Link> + </Compile> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> </Project>
\ No newline at end of file diff --git a/src/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs b/src/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs index 9a308a114f..99fe0fa05d 100644 --- a/src/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs +++ b/src/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs @@ -61,7 +61,7 @@ namespace XDocumentTests.Streaming [Fact] public void XNameAsEmptyStringConstructor() { - Assert.Throws<ArgumentException>(() => new XStreamingElement(string.Empty)); + AssertExtensions.Throws<ArgumentException>(null, () => new XStreamingElement(string.Empty)); Assert.Throws<XmlException>(() => new XStreamingElement(" ")); } diff --git a/src/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj b/src/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj index 3e8d88ec48..e47da7e696 100644 --- a/src/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj +++ b/src/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj @@ -12,6 +12,9 @@ <ItemGroup> <Compile Include="StreamExtensions.cs" /> <Compile Include="StreamingOutput.cs" /> + <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs"> + <Link>Common\System\AssertExtensions.cs</Link> + </Compile> </ItemGroup> <ItemGroup> <ProjectReference Include="$(CommonTestPath)\System\Xml\XmlDiff\XmlDiff.csproj" /> diff --git a/src/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs b/src/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs index b49a61f75f..1781bde2c7 100644 --- a/src/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs +++ b/src/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs @@ -51,9 +51,9 @@ namespace System.Xml.Linq.Tests public static void InvalidXNameTest() { Assert.Throws<XmlException>(() => { TestData.GetDocumentWithContacts().Root.Attribute("*&^%_#@!"); }); - Assert.Throws<ArgumentException>(() => { TestData.GetDocumentWithContacts().Root.Attribute(""); }); + AssertExtensions.Throws<ArgumentException>(null, () => { TestData.GetDocumentWithContacts().Root.Attribute(""); }); Assert.Throws<XmlException>(() => { TestData.GetDocumentWithContacts().Root.Attributes("*&^%_#@!"); }); - Assert.Throws<ArgumentException>(() => { TestData.GetDocumentWithContacts().Root.Attributes(""); }); + AssertExtensions.Throws<ArgumentException>(null, () => { TestData.GetDocumentWithContacts().Root.Attributes(""); }); } } diff --git a/src/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj b/src/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj index 574b48d62c..47d22b02b8 100644 --- a/src/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj +++ b/src/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj @@ -14,6 +14,9 @@ <Compile Include="Utils.cs" /> <Compile Include="TestData.cs" /> <Compile Include="InvalidParamValidation.cs" /> + <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs"> + <Link>Common\System\AssertExtensions.cs</Link> + </Compile> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> </Project>
\ No newline at end of file diff --git a/src/System.Private.Xml.Linq/tests/misc/RegressionTests.cs b/src/System.Private.Xml.Linq/tests/misc/RegressionTests.cs index b3dabcff11..adf475fe36 100644 --- a/src/System.Private.Xml.Linq/tests/misc/RegressionTests.cs +++ b/src/System.Private.Xml.Linq/tests/misc/RegressionTests.cs @@ -217,8 +217,8 @@ namespace System.Xml.Linq.Tests XStreamingElement se = new XStreamingElement("se", t); se.Add(t); - Assert.Throws<ArgumentException>(() => new XDocument(t)); - Assert.Throws<ArgumentException>(() => new XDocument(t)); + AssertExtensions.Throws<ArgumentException>(null, () => new XDocument(t)); + AssertExtensions.Throws<ArgumentException>(null, () => new XDocument(t)); } public static IEnumerable<object[]> GetObjects() diff --git a/src/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs b/src/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs index 3081221d4e..bf5589d9cb 100644 --- a/src/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs +++ b/src/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs @@ -3415,7 +3415,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws<ArgumentException>(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "Cannot have ']]>' inside an XML CDATA block."; @@ -3609,7 +3609,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws<ArgumentException>(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "An XML comment cannot contain '--', and '-' cannot be the last character."; @@ -4212,7 +4212,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws<ArgumentException>(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "Cannot have '?>' inside an XML processing instruction."; diff --git a/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj b/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj index 993626a53f..5d852f9271 100644 --- a/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj +++ b/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj @@ -13,6 +13,9 @@ <Compile Include="$(CommonTestPath)\System\Collections\DictionaryExtensions.cs"> <Link>Common\System\Collections\DictionaryExtensions.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs"> + <Link>Common\System\AssertExtensions.cs</Link> + </Compile> <Compile Include="$(CommonTestPath)\System\PlatformDetection.cs"> <Link>Common\System\PlatformDetection.cs</Link> </Compile> |