Validatation method seperated

pull/460/merge^2
Buddhika Chathuranga 2020-05-12 12:19:13 +05:30
parent a56f2290e9
commit fd961fec4d
2 changed files with 17 additions and 7 deletions

View File

@ -67,8 +67,11 @@ namespace winsw
try
{
string xmlstring = File.ReadAllText(BasePath + ".xml");
dom = ServiceDescriptor.FromXML(xmlstring).dom;
using(var reader = new StreamReader(BasePath + ".xml"))
{
string xml = reader.ReadToEnd();
dom = ServiceDescriptor.XmlValidation(xml);
}
}
catch (XmlException e)
{
@ -105,7 +108,12 @@ namespace winsw
// ReSharper disable once InconsistentNaming
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();
Assembly a = Assembly.GetExecutingAssembly();
@ -127,10 +135,12 @@ namespace winsw
var reader = XmlReader.Create(new StringReader(xml), settings);
dom.Load(reader);
return new ServiceDescriptor(dom);
var xmlDoc = new XmlDocument();
xmlDoc.Load(reader);
return xmlDoc;
}
private string SingleElement(string tagName)
{
return SingleElement(tagName, false)!;

View File

@ -446,7 +446,7 @@ $@"<service>
}
[Test]
public void FromXMLTest()
public void XmlValidationTest()
{
const string seedXml = @"<id>
<id>myapp</id>
@ -456,7 +456,7 @@ $@"<service>
</id>
";
Assert.That(() => ServiceDescriptor.FromXML(seedXml), Throws.Exception.TypeOf<XmlException>());
Assert.That(() => ServiceDescriptor.XmlValidation(seedXml), Throws.Exception.TypeOf<XmlException>());
}
}
}