Following is my generic base repository interface
public interface IRepository { IQueryable AllIncluding(params Expression>[] includeProperties); }
my entity
public class Sdk { public Sdk() { this.Identifier = Guid.NewGuid().ToString(); } public virtual ICollection AccessibleResources { get; set; } public string Identifier { get; set; } }
and following is the specific repo
public interface ISdkRepository : IRepository { }
now I am trying to test a controller, using moq
Following is the code I am trying to test
public ActionResult GetResources(string clientId) { var sdkObject = sdkRepository .AllIncluding(k => k.AccessibleResources) .SingleOrDefault(k => k.Identifier == clientId); if (sdkObject == null) throw new ApplicationException("Sdk Not Found"); return Json(sdkObject.AccessibleResources.ToList()); }
using following test
[Test] public void Can_Get_GetResources() { var cid = Guid.NewGuid().ToString(); var mockRepo = new Moq.Mock(); var sdks = new HashSet() { new Sdk() { Identifier = cid, AccessibleResources = new HashSet() { new Resource() { Id = Guid.NewGuid(), Description = "This is sdk" } } } }; mockRepo.Setup(k => k. AllIncluding(It.IsAny>[]>())) .Returns(sdks.AsQueryable); var sdkCtrl = new SdksController(mockRepo.Object); var returnedJson=sdkCtrl.GetResources(cid); returnedJson.ToString(); }
and it is throwing:
System.Reflection.TargetParameterCountException : Parameter count mismatch
Don't know why?