I have a class I'm trying to do unit tests on. A class is a WCF service class. (Making a generic class is not my goal.)
I have a data access level (DAL) type (called UserDAL) that is created in several ways. To test these methods, I need these local variables to laugh. (Each instance of UserDAL has a method value defined in it, so changing its class level variable will result in messy code, so I would not do that.)
What I think would be nice is to overload the constructor and pass in the type that will be used in local methods. An empty pair constructor will still create a regular UserDAL, but the overloaded one will have a layout of the type that implements IUserDAL.
I am not sure of the syntax to say that I want to pass a type. Please note that I am not trying to pass a variable, but a type.
Example:
public class MyWCFClass: IMyWCFClass
{
private TypeParam _myUserDALType;
public MyWCFClass()
{
_myUserDALType = UserDAL;
}
public MyWCFClass(TypeParam myUserDALType)
{
_myUserDALType = myUserDALType;
}
public MyMethod()
{
IUserDAL userDAL = new _myUserDALType();
userDAL.CreateUser();
}
.....
}
So, I do not know what type of TypeParam (I did this), or if such an approach is even possible.
If you have a non generics solution that would be great.
source
share