문제

I am writing a fixture for the PersonInfo class in HealthVault for use in unit tests. I have already taken the XML from an existing PersonInfo and stored it locally in a file. I am know attempting to use the PersonInfo.CreateFromXML but it is causing a null reference exception with no indicators as to what is causing it.

First of all is this the correct way of using this function and secondly what can i do to make it return a PersonInfo object

public class PersonInfoFixture
{
     Guid _app_Id = new Guid("00000000-0000-0000-0000-000000000000");
     string _app_name = "AppName";
     string _app_url = "https://platform.healthvault-ppe.co.uk/platform";
     string _shell_url = "https://account.healthvault-ppe.co.uk";

     string _person_xml_path = "C:/Work/MI-HV-TEST/Fixtures/HealthVault/XML/person.xml";

     public PersonInfo Get_person_fixture()
     {
         var hs = new HealthServiceInstance(_app_Id.ToString(), _app_name, "" , new Uri(_app_url), new Uri(_shell_url));
         var app = new ApplicationConnection(_app_Id, hs);
         var doc = new XPathDocument(_person_xml_path);
         var navigator = doc.CreateNavigator();

         return PersonInfo.CreateFromXml(app, navigator) as PersonInfo;
      }
}
도움이 되었습니까?

해결책

I have managed to solve this problem.

The problem was that the navigator was pointing to the wrong node.

It should have been set up like this:

var app = new ApplicationConnection();
var doc = new XPathDocument(_file_path);

var navigator = doc.CreateNavigator();
navigator = navigator.SelectSingleNode("person-info").CreateNavigator();

return PersonInfo.CreateFromXml(app, navigator) as PersonInfo;

So learn from this mistake. Now i can i do some unit testing that involves the PersonInfo object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top