In my controller there is such a way of action
public ActionResult Index() { using (NorthwindDataContext db = new NorthwindDatacontext()) { var results = db.GetRecordSets(arg1, ....).ToList();
and I wanted to start doing tests for him (yes, after it was built, not before ... but the code was written before I started using TDD like that ...)
and I realized that adding a property like this to the controller
public delegate NorthwindDatacontext ContextBuilderDelegate(); public ContextBuilderDelegate ContextBuilder { get; set; }
I could add something like this to the constructor ...
ContextBuilder = () => new NorthwindDatacontext();
then I can verify that ActionMethod sets the ContextBuilder property with the NorthwindDatacontext layout
var controller = new MyController(); var mockDataContext = new Mock<NorthwindDatacontext>(); controller.ContextBuilder = () => mockDataContext.Object;
But ... I did not find a way to use this, because all NorthwindDatacontext methods use ISingleResult as returnType, and I cannot find a way to create an object with this interface. I tried this
var theResult = new List<GetRecordSetsResult>();
but this will not work, because when converting to ISingleResultResult it is null.
Is there a way to create an ISingleResult object to test this method, or am I doing the wrong way to do something here?
Thanks at Advance
asp.net-mvc moq
Eugenio mirror
source share