I've been trying to figure out how to unit test my application but I don't quite understand how everything fits together.
I have followed John Papa's tutorial on PluralSight (SPA) and built my model, repository and unit of work in the exact same way. Unfortunately, he doesn't provide any examples on how we can unit test this.
I have played around with Moq and found very few links online that explain how to do so, but unfortunately I got nowhere.
Some code to provide context :
public interface IRepository<T> where T : class
{
IQueryable<T> GetAll();
T GetById(int id);
void Add(T entity);
void Update(T entity);
void Delete(T entity);
void Delete(int id);
}
public interface IFeedbackRepository : IRepository<Feedback>
{
IQueryable<Feedback> GetByFeedbackFor(int id);
}
public class FeedbackRepository : EFRepository<Feedback>, IFeedbackRepository
{
public FeedbackRepository(WebAppDbContext context) : base(context) { }
public IQueryable<Feedback> GetByFeedbackFor(int id)
{
return DbSet.Where(f => f.FeedbackForId == id);
}
}
public interface IWebAppUow
{
void Commit();
IFeedbackRepository Feedbacks { get; }
}
public void TestMethod1()
{
Mock<IWebAppUow> mockUnitOfWork = new Mock<IWebAppUow>();
// THEN ??
}
Edit: I have found this link ( http://msdn.microsoft.com/en-us/data/dn314429.aspx ) which explains how to do it but works directly on the DbSet. If someone could explain how we could modify this example to use UoW and Repository pattern that would be grand!
IWebAppUowif you are going to test some code that use it. So it's hard to answer your question not seeing whay actual code you want to test.