Skip to content

Commit

Permalink
Include closing brace in partial repository code (#4327)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Apr 20, 2023
1 parent 0809a1b commit 67d2c6e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion entity-framework/core/testing/testing-without-the-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ If you've decided to write tests without involving your production database syst

... and here's a partial sample implementation for production use:

[!code-csharp[Main](../../../samples/core/Testing/BusinessLogic/BloggingRepository.cs?name=BloggingRepository)]
```csharp
public class BloggingRepository : IBloggingRepository
{
private readonly BloggingContext _context;

public BloggingRepository(BloggingContext context)
=> _context = context;

public Blog GetBlogByName(string name)
=> _context.Blogs.FirstOrDefault(b => b.Name == name);

// Other code...
}
```

There's not much to it: the repository simply wraps an EF Core context, and exposes methods which execute the database queries and updates on it. A key point to note is that our `GetAllBlogs` method returns `IEnumerable<Blog>`, and not `IQueryable<Blog>`. Returning the latter would mean that query operators can still be composed over the result, requiring that EF Core still be involved in translating the query; this would defeat the purpose of having a repository in the first place. `IEnumerable<Blog>` allows us to easily stub or mock what the repository returns.

Expand Down

0 comments on commit 67d2c6e

Please sign in to comment.