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 a null reference), not a reference to the variable named _pos. The effect is that the new POSImplementation instance is assigned to the local variable pos in the InitPOS method, but the _pos variable remains unchanged.
Change your code to
_pos = Utilities.InitPOS(trans);
Assert.IsNotNull(_pos);
where
public static POSImplementation InitPOS(Transaction newTransaction)
{
POSImplementation pos = new POSImplementation();
// ...
return pos;
}
pos = new POSImplementation();
Just what are you doing there, if someone is passing pos into the method already? Are you missing a ref attribute on that parameter maybe?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With