How to mock up Blog and Post when one Blog contains many Posts <p>Say we have</p> <pre><code>public class BloggingContext : DbContext { public BloggingContext(DbContextOptions&lt;BloggingContext&gt; options) : base(options) { } public DbSet&lt;Blog&gt; Blogs { get; set; } public DbSet&lt;Post&gt; Posts { get; set; } } public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List&lt;Post&gt; Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } } </code></pre> <p>I want to seed data for <code>Blog</code> and <code>Post</code> in unit test. However Blog contains Posts and Post contains Blog.</p> <p><strong>[EDIT]</strong></p> <p>I want to pass the <code>DbContext</code> to the controller. Therefore I have to mock up <code>DbContext</code> and <code>DbSet</code>. For the <code>DbSet</code>, I need to seed some dummy data.</p> <p>For example:<br> In asp.net mvc controller</p> <pre><code>public IActionResult GetBlog(int id) { Blog blog = _context.Blog.FirstOrDefault(x =&gt; x.BlogId == id); return View(Blog); } </code></pre> <p>In the test </p> <pre><code>[Fact] public void Get_blog_1_returns_google() { // Act var result = _controller.GetBlog(1) as ViewResult; // Assert Assert.IsType(typeof(Blog), result.ViewData.Model); Blog model = (Blog)result.ViewData.Model; Assert.Equal("google", model.Url); } </code></pre> <p>But I have to seed data for the test first.</p> <pre><code>public class BlogControllerTest { private BloggingContext _context; private BlogController _controller; public BlogControllerTest() { // Seed data _context.Blog.Add(new Blog() { BlogId = 1, Url = "google", // how about Post }); //..other code... } //...other code removed for brevity } </code></pre> <p>How to mock up them?</p>