I'm trying to write a unit test that calculates the total of an Order. However, there is another method that is called from the CalculateOrder() method that I'm testing and my test keeps failing saying "Object reference not set to an instance of an object."
This is the CalculateOrder method I'm testing...
public App_OrderForm CalculateOrder(App_OrderForm form)
{
try
{
// Get the possible fees for the form group
short? orderGroupId = form.Ref_OrderType == null
? GetOrderGroup(form.OrderTypeId)
: form.Ref_OrderType.orderGroupId;
Dictionary<Ref_OrderType, List<short>> fees =
GetFeeTypeForOrderGroup((OrderGroup)orderGroupId);
It is the last line of code there that is creating the error.
This is my unit test...
// Arrange
_mockUnitOfWork = new Mock<IUnitOfWork>();
_feeCalculator = new FeeCalculator(_mockUnitOfWork.Object);
App_OrderForm form = GenerateMockedForm(OrderFormType.Wholesaler);
form.Ref_OrderFormType = new Ref_OrderFormType
{
OrderFormTypeId = 1,
OrderGroupId = 1
};
foreach (var item in form.App_OrderFormItem)
{
// add calculated fees
item.App_OrderFormItemCalculatedFee = new List<App_OrderFormItemCalculatedFee>
{
new App_OrderFormItemCalculatedFee()
{
OrderFormItemCalculatedFeeId = 1,
FeeTypeId = 1,
Amount = 0.044M,
NumberOfFees = 1
},
};
}
// Act
Mock<IReferenceDataService> rds = new Mock<IReferenceDataService>();
rds.Setup(x => x.GetAllPayableStatus())
.Returns(new List<Ref_Status> {new Ref_Status() {StatusId = (short) Status.ReadyForPayment}});
_feeCalculator.CalculateForm(form, false);
Am I supposed to setup the method GetFeeTypeForOrderGroup()? At the start of my unit test I've set up an Order Form and given the OrderGroupId a value so why doesn't the method GetFeeTypeForOrderGroup() not get run or why is it returning the error?
Hope that made sense,
Thanks