The Method should only remove from my DataStructures everything from BoughtItems List and for some reason everytime i try to unit test the method it throws a NullReferenceException (in the actual program it works fine)
internal static bool DealAccepted(int amount)
{
foreach (var item in Manager.BoughtItems)
{
//Reduces Amount from Item and resets its LastTimeSold Property
if (item.Amount > amount)
{
item.Amount -= amount;
AddToTimeCheckListManager.AddToTimeCheckListBuy(item);
if (item.Amount < Manager.MinSupplyAmount)
{
return false;
}
}
//if we tried to order more or equal to the amount of current product
else
{
amount -= item.Amount;
TryRemoveItemFromDataStructures(item);
}
}
DeleteAllLists();
return true;
}
This is the unit test
[TestMethod]
public void BuyBox_BuyEntireAmountOfSingleProduct_ProductDeleted()
{
Manager manager = new Manager();
Box box = new Box(6, 6);
manager.AddItem(box, 10);
ValueData data = new ValueData(box);
Manager.BoughtItems.Add(data);
manager.DealAccepted(5);
}