This is my first question, so be kind! :)
What I'm trying to do is write some tests for the manager class, which during construction adds many new instances of the same element class to the list. When UpdateAllItems is called in this dispatcher class, it is assumed that it renames the list and calls Increment for each individual item.
The manager class is my code, but one element class is wrong, I cannot change it.
I am using NUnit as a testing framework and starting to work with Moq. Since the manager class uses a single element class, I would think that I need to use Moq, so I only test the manager, not the individual element.
How to write tests for my UpdateAllItems method? (Technically, I must first write the tests that I know).
Here is a sample code that gives a general idea of what I'm working with ...
public class SingleItem_CodeCantBeModified
{
public int CurrentValue { get; private set; }
public SingleItem_CodeCantBeModified(int startValue)
{
CurrentValue = startValue;
}
public void Increment()
{
CurrentValue++;
}
}
public class SingleItemManager
{
List<SingleItem_CodeCantBeModified> items = new List<SingleItem_CodeCantBeModified>();
public SingleItemManager()
{
items.Add(new SingleItem_CodeCantBeModified(100));
items.Add(new SingleItem_CodeCantBeModified(200));
}
public void UpdateAllItems()
{
items.ForEach(item => item.Increment());
}
}
Thanks in advance for your help!
source
share