I have the following test method:
[TestMethod]
public void TestHarvestMethod()
{
HarvestTargetTimeRangeUTC time = new HarvestTargetTimeRangeUTC();
time.StartTimeUTC = new DateTime(2008, 01, 01, 00, 00, 00, DateTimeKind.Utc);
time.EndTimeUTC = DateTime.UtcNow;
XElement lIntelexReport = XElement.Parse(rawXml);
Harvester target = new Harvester();
target.ConfigureHarvester((System.Configuration.Configuration)null);
var res = target.Harvest(time);
Console.WriteLine(res);
}
That works in conjunction with this method:
public void ConfigureHarvester(System.Configuration.Configuration configuration)
{
reportId = Int32.Parse(configuration.AppSettings.Settings["IncidentReport"].Value);
}
to test this method:
public XElement Harvest(HarvestTargetTimeRangeUTC ranges)
{
XElement lIntelexReport = IntelexServiceCall();
return XMLConversion(QueryData(ranges, lIntelexReport));
}
The problem is that I receive Null Exception error stating that “Object reference not set to an instance of an object.” on this line:
reportId = Int32.Parse(configuration.AppSettings.Settings["IncidentReport"].Value);
which I am almost positive is caused by the null value here:
target.ConfigureHarvester((System.Configuration.Configuration)null);
The System.Configuration in the above line is one used commonly in this shop, but normally for a method such as this:
public void ConfigureHarvester(System.Configuration.Configuration configuration)
{
context = new PlannedOutageFactorDataContext();
}
So my reportid field is obviously looking for something other than a null value, the problem is I don’t know exactly WHAT it’s looking for. Ive read the MSDN for System.Configuration but it was really no help. I would appreciate it if some one could point me in the right direction.
Its looking for you to pass it a copy of your web.config or app.config value so it can extract the information it requires from this (held in the AppSettings section)
For example
If your testing a webpage, a lot of the time you need to set the location of the webservice so that it can grab a copy of the web.config from your website.
If your developing a console/desktop app then make sure you have an app.config file
Alternativly you can manually pass it in using