Permalink
Browse files

Collect row errors into a List of ValidationErrors when parsing the u…

…pload attempt response
  • Loading branch information...
1 parent b83e2e4 commit 10bf492a07fbc0a869d497daa1e4a636a06141d6 @tism tism committed Oct 11, 2012
@@ -66,6 +66,7 @@
<Compile Include="Search.cs" />
<Compile Include="SearchResult.cs" />
<Compile Include="tests\ConfigurationTests.cs" />
+ <Compile Include="ValidationError.cs" />
<Compile Include="tests\IntegrityHttpServiceTests.cs" />
<Compile Include="tests\IntegrityInterfaceTests.cs" />
<Compile Include="tests\QualifierTest.cs" />
@@ -51,6 +51,7 @@ public bool IsPending
{
get { return _is_pending; }
}
+ public List<ValidationError> ValidationErrors = new List<ValidationError>();
public UploadAttemptResponse(string responseXml)
{
@@ -66,17 +67,17 @@ public UploadAttemptResponse(string responseXml)
_is_pending = false;
}
- if (xmld.ChildNodes.Count == 0)
- {
- _was_success = false;
- }
- else if (xmld.SelectSingleNode("//errors").ChildNodes.Count > 0)
- {
- _was_success = false;
- }
- else if (xmld.SelectSingleNode("//row-errors").ChildNodes.Count > 0)
+ if ((xmld.ChildNodes.Count == 0) || (xmld.SelectSingleNode("//errors").ChildNodes.Count > 0) || (xmld.SelectSingleNode("//row-errors").ChildNodes.Count > 0))
{
_was_success = false;
+
+ foreach (XmlNode node in xmld.SelectNodes("//row-error"))
+ {
+ int level = int.Parse(node.SelectSingleNode("level").InnerText);
+ string level_description = node.SelectSingleNode("level-description").InnerText;
+ string details = node.SelectSingleNode("details").InnerText;
+ this.ValidationErrors.Add(new ValidationError { level = level, level_description = level_description, details = details });
+ }
}
else
{
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 C3 Products
+
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to
+ * whom the Software is furnished to do so,
+ * subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+public class ValidationError
+{
+ public int level { get; set; }
+ public string level_description { get; set; }
+ public string details { get; set; }
+}
@@ -59,11 +59,17 @@ public void UploadAttempXmlCreatFailureTest()
[Test()]
public void UploadAttempXmlValidationFailureTest()
{
- string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<upload-attempt>" + Environment.NewLine + "<id>4048</id>" + Environment.NewLine + "<status>upload</status>" + Environment.NewLine + "<rows-uploaded>99</rows-uploaded>" + Environment.NewLine + "<uploaded-row-data><tbl_reg type=\"array\"></tbl_reg></uploaded-row-data>" + Environment.NewLine + "<row-errors type=\"array\"><row-error>bad data</row-error></row-errors>" + Environment.NewLine + "<errors><error>blah</error></errors>" + Environment.NewLine + "</upload-attempt>";
+ string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<upload-attempt>" + Environment.NewLine + "<id>4048</id>" + Environment.NewLine + "<status>upload</status>" + Environment.NewLine + "<rows-uploaded>99</rows-uploaded>" + Environment.NewLine + "<uploaded-row-data><tbl_reg type=\"array\"></tbl_reg></uploaded-row-data>" + Environment.NewLine + "<row-errors type=\"array\"><row-error><level>1</level><level-description>Upload prevented until fixed</level-description><details>bad data</details></row-error></row-errors>" + Environment.NewLine + "<errors><error>blah</error></errors>" + Environment.NewLine + "</upload-attempt>";
UploadAttemptResponse response = new UploadAttemptResponse(xml);
Assert.IsFalse(response.WasSuccess);
Assert.IsFalse(response.IsPending);
+
+ Assert.AreEqual(response.ValidationErrors.Count, 1);
+ ValidationError error = response.ValidationErrors[0];
+ Assert.AreEqual(error.level, 1);
+ Assert.AreEqual(error.level_description, "Upload prevented until fixed");
+ Assert.AreEqual(error.details, "bad data");
}
[Test()]

0 comments on commit 10bf492

Please sign in to comment.