diff --git a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs index cc3280c472..fa8d3d412f 100644 --- a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs +++ b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs @@ -6,6 +6,7 @@ using System.IO; using System.Reflection; using System.Security.Cryptography; +using System.Xml; using Microsoft.IdentityModel.Tokens; namespace Microsoft.IdentityModel.TestUtils @@ -67,6 +68,11 @@ public static ExpectedException IOException(string substringExpected = null, Typ return new ExpectedException(typeof(IOException), substringExpected, inner); } + public static ExpectedException XmlException(string substringExpected = null, Type inner = null, string contains = null) + { + return new ExpectedException(typeof(XmlException), substringExpected, inner); + } + public static ExpectedException NoExceptionExpected { get { return new ExpectedException(); } diff --git a/test/Microsoft.IdentityModel.Xml.Tests/DelegatingXmlDictionaryReaderTests.cs b/test/Microsoft.IdentityModel.Xml.Tests/DelegatingXmlDictionaryReaderTests.cs index 8361d6d05d..50a66c9eed 100644 --- a/test/Microsoft.IdentityModel.Xml.Tests/DelegatingXmlDictionaryReaderTests.cs +++ b/test/Microsoft.IdentityModel.Xml.Tests/DelegatingXmlDictionaryReaderTests.cs @@ -20,6 +20,47 @@ public void ReadXml(DelegatingXmlDictionaryReaderTheoryData theoryData) try { var depth = theoryData.DelegatingReader.Depth; + + if (!theoryData.First) + { + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Depth, theoryData.DelegatingReader.Depth); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Value, theoryData.DelegatingReader.Value); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Name, theoryData.DelegatingReader.Name); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.NamespaceURI, theoryData.DelegatingReader.NamespaceURI); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.AttributeCount, theoryData.DelegatingReader.AttributeCount); + } + + theoryData.ExpectedException.ProcessNoException(context); + } + catch (Exception ex) + { + theoryData.ExpectedException.ProcessException(ex, context); + } + + TestUtilities.AssertFailIfErrors(context); + } + + [Theory, MemberData(nameof(ReadPartialXmlWithUniqueIdTheoryData))] + public void ReadPartialXml(DelegatingXmlDictionaryReaderTheoryData theoryData) + { + var context = TestUtilities.WriteHeader($"{this}.ReadXml", theoryData); + try + { + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Depth, theoryData.DelegatingReader.Depth); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Value, theoryData.DelegatingReader.Value); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.Name, theoryData.DelegatingReader.Name); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.NamespaceURI, theoryData.DelegatingReader.NamespaceURI); + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.AttributeCount, theoryData.DelegatingReader.AttributeCount); + + theoryData.DelegatingReader.InnerReaderPublic.MoveToContent(); + theoryData.DelegatingReader.MoveToContent(); + + theoryData.DelegatingReader.InnerReaderPublic.MoveToAttribute("URI"); + theoryData.DelegatingReader.MoveToAttribute("URI"); + + Assert.Equal(theoryData.DelegatingReader.InnerReaderPublic.ReadContentAsUniqueId(), + theoryData.DelegatingReader.ReadContentAsUniqueId()); + theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) @@ -54,6 +95,34 @@ public static TheoryData ReadXmlTheoryD }; } } + + public static TheoryData ReadPartialXmlWithUniqueIdTheoryData + { + get + { + return new TheoryData + { + new DelegatingXmlDictionaryReaderTheoryData + { + DelegatingReader = new DelegatingXmlDictionaryReaderPublic + { + InnerReaderPublic = XmlUtilities.CreateDictionaryReader(Default.OuterXml) + }, + First = true, + ExpectedException = ExpectedException.XmlException(inner: typeof(FormatException)), + TestId = "InnerReader-FullXml" + }, + new DelegatingXmlDictionaryReaderTheoryData + { + DelegatingReader = new DelegatingXmlDictionaryReaderPublic + { + InnerReaderPublic = XmlUtilities.CreateDictionaryReader("") + }, + TestId = "InnerReader-PartialXmlWithUri" + } + }; + } + } } public class DelegatingXmlDictionaryReaderPublic : DelegatingXmlDictionaryReader