Skip to content

Commit

Permalink
Added unit tets
Browse files Browse the repository at this point in the history
  • Loading branch information
MoSelem authored and brentschmaltz committed Oct 6, 2023
1 parent 5cd6ed6 commit a5a4642
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -54,6 +95,34 @@ public static TheoryData<DelegatingXmlDictionaryReaderTheoryData> ReadXmlTheoryD
};
}
}

public static TheoryData<DelegatingXmlDictionaryReaderTheoryData> ReadPartialXmlWithUniqueIdTheoryData
{
get
{
return new TheoryData<DelegatingXmlDictionaryReaderTheoryData>
{
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("<Elemnt URI=\"uuid-88d1a312-e27e-4bb8-a69f-e4fd295daf04\" />")
},
TestId = "InnerReader-PartialXmlWithUri"
}
};
}
}
}

public class DelegatingXmlDictionaryReaderPublic : DelegatingXmlDictionaryReader
Expand Down

0 comments on commit a5a4642

Please sign in to comment.