Unit testing Entity Framework with Mock IDbSet

前端 未结 1 1315
余生分开走
余生分开走 2020-12-16 02:40

I\'ve never really done unit testing before, and I\'ve stumbled and tripped on my first test. The problem is that the _repository.Golfers.Count(); always indica

相关标签:
1条回答
  • 2020-12-16 03:04

    You shouldn't need to implement the get/set, the following code should be enough to generate the context for you.

    public class MockGolfEntities : DbContext, IContext
    {
        public MockGolfEntities() {}
    
        public IDbSet<Golfer> Golfers { get; set;}
    
    }
    

    I've implemeted the code you had in your original post and everything seemed to work well for me - where did you get the source for the InMemoryDbSet? I'm using the NuGet package 1.3, maybe you should try that version?

    0 讨论(0)
提交回复
热议问题