KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am writing unit tests with C#, NUnit and Rhino Mocks. Here are the relevant parts of a class I am testing: public class ClassToBeTested { private IList<object> insertItems = new List<object>(); public bool OnSave(object entity, object id) { var auditable = entity as IAuditable; if (auditable != null) insertItems.Add(entity); return false; } } I want to test the values in insertItems after a call to OnSave: [Test] public void OnSave_Adds_Object_To_InsertItems_Array() { Setup(); myClassToBeTested.OnSave(auditableObject, null); // Check auditableObject has been added to insertItems array } What is the best practice for this? I have considered adding insertItems as a Property with a public get, or injecting a List into ClassToBeTested, but not sure I should be modifying the code for purposes of testing. I have read many posts on testing private methods and refactoring, but this is such a simple class I wondered what is the best option.
Tags (comma-separated)
Save Edits
Cancel