I have this strange problem in my unit tests. See the following code
_pos = null;
Utilities.InitPOS(_pos, trans);
Assert.IsNotNull(_pos); //fails
The InitPOS functions looks like
public static void InitPOS(POSImplementation pos, Transaction newTransaction)
{
pos = new POSImplementation();
pos.SomeProp = new SomeProp();
pos.SomeProp.SetTransaction(newTransaction);
Assert.IsNotNull(pos);
Assert.IsNotNull(pos.SomeProp);
}
The object POSImplementation is an implementation of some interface and it is a class, so it is a reference type…
Any idea?
You’re passing a reference to an object to
InitPOS(namely anullreference), not a reference to the variable named_pos. The effect is that the newPOSImplementationinstance is assigned to the local variableposin theInitPOSmethod, but the_posvariable remains unchanged.Change your code to
where