mirror of https://github.com/winsw/winsw
Validatation method seperated
parent
a56f2290e9
commit
fd961fec4d
|
@ -67,8 +67,11 @@ namespace winsw
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string xmlstring = File.ReadAllText(BasePath + ".xml");
|
using(var reader = new StreamReader(BasePath + ".xml"))
|
||||||
dom = ServiceDescriptor.FromXML(xmlstring).dom;
|
{
|
||||||
|
string xml = reader.ReadToEnd();
|
||||||
|
dom = ServiceDescriptor.XmlValidation(xml);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (XmlException e)
|
catch (XmlException e)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +108,12 @@ namespace winsw
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
public static ServiceDescriptor FromXML(string xml)
|
public static ServiceDescriptor FromXML(string xml)
|
||||||
{
|
{
|
||||||
var dom = new XmlDocument();
|
return new ServiceDescriptor(XmlValidation(xml));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static XmlDocument XmlValidation(string xml)
|
||||||
|
{
|
||||||
XmlReaderSettings settings = new XmlReaderSettings();
|
XmlReaderSettings settings = new XmlReaderSettings();
|
||||||
Assembly a = Assembly.GetExecutingAssembly();
|
Assembly a = Assembly.GetExecutingAssembly();
|
||||||
|
|
||||||
|
@ -127,10 +135,12 @@ namespace winsw
|
||||||
|
|
||||||
var reader = XmlReader.Create(new StringReader(xml), settings);
|
var reader = XmlReader.Create(new StringReader(xml), settings);
|
||||||
|
|
||||||
dom.Load(reader);
|
var xmlDoc = new XmlDocument();
|
||||||
return new ServiceDescriptor(dom);
|
xmlDoc.Load(reader);
|
||||||
|
return xmlDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string SingleElement(string tagName)
|
private string SingleElement(string tagName)
|
||||||
{
|
{
|
||||||
return SingleElement(tagName, false)!;
|
return SingleElement(tagName, false)!;
|
||||||
|
|
|
@ -446,7 +446,7 @@ $@"<service>
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FromXMLTest()
|
public void XmlValidationTest()
|
||||||
{
|
{
|
||||||
const string seedXml = @"<id>
|
const string seedXml = @"<id>
|
||||||
<id>myapp</id>
|
<id>myapp</id>
|
||||||
|
@ -456,7 +456,7 @@ $@"<service>
|
||||||
</id>
|
</id>
|
||||||
";
|
";
|
||||||
|
|
||||||
Assert.That(() => ServiceDescriptor.FromXML(seedXml), Throws.Exception.TypeOf<XmlException>());
|
Assert.That(() => ServiceDescriptor.XmlValidation(seedXml), Throws.Exception.TypeOf<XmlException>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue