I have a public void method, SaveCover2AData()
. How can I create a unit test for this type of method?
This is my public method, I am passing a model object as a parameter in this method.
Now I want to create unit test for this method:
public void SaveCover2AData(CASTabCover2a t2a)
{
CASCreateViewModel obj = (CASCreateViewModel)Session["CASQuote"];
t2a.Quote_Exposures = t2a.Quote_Exposures.Where(x => x.Exposure != null || x.ExposurePL != null).ToList();
t2a.Quote_Jurisdictions = t2a.Quote_Jurisdictions.Where(x => x.Jurisdiction_Name != null || x.Country_NamePL != null).ToList();
t2a.Quote_LimtOfIndemnitys = t2a.Quote_LimtOfIndemnitys.Where(x => x.Indemnity != null || x.IndemnityPL != null || x.LimitOfIndemnity_Currency != null).ToList();
t2a.Quote_SubLimitOfIndemnitys = t2a.Quote_SubLimitOfIndemnitys.Where(x => x.Indemnity != null || x.IndemnityPL != null || x.SubLimitOfIndemnity_Currency != null).ToList();
obj.TabCover2a = t2a;
Session.Add("CASQuote", obj);
ViewBag.Quote_Status_ID = JsonConvert.SerializeObject(obj.Quote_Status_ID);
}
The test method I've attempted so far is:
[TestMethod]
public void CASSaveCover2AData()
{
builder.InitializeController(controller);
var CASTabCover2a = new CASTabCover2a();
controller.SaveCover2AData(CASTabCover2a);
Assert.IsTrue(true);
}
When I am debugging this test case I am getting this error:
An exception of type 'System.NullReferenceException' occurred