-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from spekt/xsd-format-fixes_misc-features
Xsd format fixes misc features
- Loading branch information
Showing
8 changed files
with
481 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Changelog | ||
|
||
A changelog is maintained on the releases page of the [JUnit Test Logger GitHub repository](https://github.com/spekt/junit.testlogger/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/JUnit.Xml.TestLogger.AcceptanceTests/JunitXmlValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Spekt Contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace JUnit.Xml.TestLogger.AcceptanceTests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using System.Xml.Schema; | ||
|
||
public class JunitXmlValidator | ||
{ | ||
/// <summary> | ||
/// Field is provided only to simplify debugging test failures. | ||
/// </summary> | ||
private readonly List<XmlSchemaException> failures = new List<XmlSchemaException>(); | ||
|
||
public bool IsValid(string xml) | ||
{ | ||
var xmlReader = new StringReader(xml); | ||
var xsdReader = new StringReader( | ||
File.ReadAllText( | ||
Path.Combine("..", "..", "..", "..", "assets", "JUnit.xsd"))); | ||
|
||
var schema = XmlSchema.Read( | ||
xsdReader, | ||
(sender, args) => { throw new XmlSchemaValidationException(args.Message, args.Exception); }); | ||
|
||
var xmlReaderSettings = new XmlReaderSettings(); | ||
xmlReaderSettings.Schemas.Add(schema); | ||
xmlReaderSettings.ValidationType = ValidationType.Schema; | ||
|
||
var veh = new ValidationEventHandler(this.XmlValidationEventHandler); | ||
|
||
xmlReaderSettings.ValidationEventHandler += veh; | ||
using (XmlReader reader = XmlReader.Create(xmlReader, xmlReaderSettings)) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
} | ||
} | ||
|
||
xmlReaderSettings.ValidationEventHandler -= veh; | ||
|
||
return this.failures.Any() == false; | ||
} | ||
|
||
private void XmlValidationEventHandler(object sender, ValidationEventArgs e) | ||
{ | ||
this.failures.Add(e.Exception); | ||
} | ||
} | ||
} |
Oops, something went wrong.