Organization of test methods - C #
I have a class at the moment and inside this class it has 15 private private methods that do certain tasks in a loop started by a timer. Some of these methods are called in the database and some are not.
The question is how ... can I organize them so that I can customize the class so that I can spoof the repository or runtime?
This is a simplified version of what I have.
public class Manager : IManager
{
System.Timers.Timer tm;
private bool runningAsService;
private List<Database> Databases = new List<Database>();
private LogClass Log;
public Manager(bool RunningAsService, LogClass log)
{
runningAsService = RunningAsService;
Log = log;
tm = new System.Timers.Timer(Settings.idle_time * 1000);
tm.Elapsed += new System.Timers.ElapsedEventHandler(delegate { PerformDuties(); });
}
public void Start()
{
tm.Start();
PerformDuties();
}
private PerformDuties()
{
//Call the other 10-15 private methods to perform all the tasks needed.
}
}
a source to share
Each Db operation would end either a CRUD operation. This way, you can retrieve the database from your database class, in other words, abstract from the data access layer, something like this:
public interface IDatabase<T>
{
T CreateItem();
T ReadItem(Id id);
bool UpdateItem(T item);
bool DeleteItem(T item)
}
And inject a list of databases using Dependency Injection using DI framework like Castle Windsor , Spring.NET or using Setter or Ctor Injection into the classManager
Hope this makes sense .. :)
a source to share
If I understand your question correctly, it sounds like a need for dependency injection where you provide Manager objects depends on getting your job done, They would be real objects (actual database connection) or fake one that just acts like it ...
Do I understand your question correctly?
a source to share