开发者

Moq & nUnit to test EntityFramework MVC3 C#

Can anybody provide a good starting point or example of using Moq and nUnit to perform tests against the entity framework ins开发者_开发技巧ide MVC. I have a DomainModel which contains "MyModel.edmx" which contains a table "Posts". I want to perform a test populating a fake repository of this.

I have been following this: http://blogs.msdn.com/b/adonet/archive/2009/12/17/walkthrough-test-driven-development-with-the-entity-framework-4-0.aspx

But I am unsure how to use Moq/nUnit instead of the inbuilt tests


This is another way of creating Moq Object (for testing purpose) assuming you implemented a datarepository.

public static class UnitTestHelpers
        {
            public static MyModelRepository MockMyModelRepository(params Posts[] post)
            {
                // Generate an implementer of MyModelRepository at runtime using Moq
                var mockPosts = new Mock<MyModelRepository>();
                mockPosts.Setup(x => x.Posts).Returns(post.AsQueryable());
                return mockPosts.Object;
            }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜