jeudi 22 janvier 2015

Write test cases for a partial class that extends another class in C#

I have a C# code as follows



public partial class ChildClass : ParentClass
{
...
...
public ChildClass() : base(SomeCore.Context.Item.Fields["Parameters Template Name"].ConvertToString())
{
this.memVarA = //reading from some Context
this.memVarA = //reading from some Context
}
}


I want to create a test cases for ChildClass. In the test class I have this code:



[TestMethod()]
public void ItemsListShouldHaveOnly4Items()
{
ChildClass ChildClass = new ChildClass();
PrivateObject privateObject = new PrivateObject(ChildClass);
privateObject.Invoke("aPrivateMethod");
var retVal = privateObject.Invoke("getItemsList");
Assert.AreEqual(4, retVal);
}


The test breaks with exception : System.NullReferenceException: Object reference not set to an instance of an Object.


How can I go about writing test cases for this class ?


Aucun commentaire:

Enregistrer un commentaire