{"id":5480421,"url":"https://github.com/huysentruitw/entity-framework-core-mock","last_synced_at":"2025-04-29T11:32:00.583Z","repository":{"id":40402408,"uuid":"150160650","full_name":"huysentruitw/entity-framework-core-mock","owner":"huysentruitw","description":"Easy Mock wrapper for mocking EFCore5 DbContext and DbSet using Moq or NSubstitute","archived":false,"fork":false,"pushed_at":"2023-11-09T08:45:18.000Z","size":174,"stargazers_count":132,"open_issues_count":6,"forks_count":25,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-04-18T04:01:01.110Z","etag":null,"topics":["csharp","dbcontext","dbset","dotnet-standard","dotnetcore","efcore","efcore5","entity-framework-core","mock","moq","net50","nsubstitute","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huysentruitw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"huysentruitw"}},"created_at":"2018-09-24T19:57:37.000Z","updated_at":"2024-05-14T17:17:04.000Z","dependencies_parsed_at":"2024-03-02T13:08:19.661Z","dependency_job_id":"9021f652-b196-4a98-91ed-b9ed54f3ca62","html_url":"https://github.com/huysentruitw/entity-framework-core-mock","commit_stats":null,"previous_names":["huysentruitw/entity-framework-core-mock","cup-of-tea-dot-be/entity-framework-core-mock"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-core-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-core-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-core-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-core-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huysentruitw","download_url":"https://codeload.github.com/huysentruitw/entity-framework-core-mock/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251493984,"owners_count":21598208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dbcontext","dbset","dotnet-standard","dotnetcore","efcore","efcore5","entity-framework-core","mock","moq","net50","nsubstitute","unit-testing"],"created_at":"2024-03-02T13:04:06.133Z","updated_at":"2025-04-29T11:31:59.893Z","avatar_url":"https://github.com/huysentruitw.png","language":"C#","funding_links":["https://github.com/sponsors/huysentruitw"],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# EntityFrameworkCoreMock\n\n![Build status](https://github.com/cup-of-tea-dot-be/entity-framework-core-mock/actions/workflows/build-test-publish.yml/badge.svg?branch=master)\n\nEasy Mock wrapper for mocking EntityFrameworkCore 5 (EFCore5) DbContext and DbSet in your unit-tests. Integrates with Moq or NSubstitute.\n\n😢 Are you still stuck on EF Core 3.1? No worries, just visit [this repository](https://github.com/huysentruitw/entity-framework-core3-mock).\n\n😮 Wait, did you say EF6? You really should get worried! Anyway, visit [this repository](https://github.com/huysentruitw/entity-framework-mock).\n\n## Get it on NuGet\n\n### Moq integration\n\n    PM\u003e Install-Package EntityFrameworkCoreMock.Moq\n\n### NSubstitute integration\n\n    PM\u003e Install-Package EntityFrameworkCoreMock.NSubstitute\n\n## Supports\n\n* In-memory storage of test data\n* Querying of in-memory test data (synchronous or asynchronous)\n* Tracking of updates, inserts and deletes of in-memory test data\n* Emulation of `SaveChanges` and `SaveChangesAsync` (only saves tracked changes to the mocked in-memory DbSet when one of these methods are called)\n* Auto-increment identity columns, annotated by the `[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]` attribute\n* Primary key on multiple columns, annotated by the `[Key, Column(Order = X)]` attributes\n\n## TODO\n\n* Throwing a `DbUpdateException` when inserting 2 or more entities with the same primary key while calling `SaveChanges` / `SaveChangesAsync` (emulating EF behavior)\n* Throwing a `DbUpdateConcurrencyException` when removing a model that no longer exists (emulating EF behavior)\n\nFor the Moq version, you can use all known [Moq](https://github.com/Moq/moq4/wiki/Quickstart) features, since both `DbSetMock` and `DbContextMock` inherit from `Mock\u003cDbSet\u003e` and `Mock\u003cDbContext\u003e` respectively.\n\n## Example usage\n```C#\npublic class User\n{\n    [Key, Column(Order = 0)]\n    public Guid Id { get; set; }\n\n    public string FullName { get; set; }\n}\n\npublic class TestDbContext : DbContext\n{\n    public TestDbContext(DbContextOptions\u003cTestDbContext\u003e options)\n        : base(options)\n    {\n    }\n\n    public virtual DbSet\u003cUser\u003e Users { get; set; }\n}\n\npublic class MyTests\n{\n    [Fact]\n    public void DbSetTest()\n    {\n        var initialEntities = new[]\n            {\n                new User { Id = Guid.NewGuid(), FullName = \"Eric Cartoon\" },\n                new User { Id = Guid.NewGuid(), FullName = \"Billy Jewel\" },\n            };\n        \n        var dbContextMock = new DbContextMock\u003cTestDbContext\u003e(DummyOptions);\n        var usersDbSetMock = dbContextMock.CreateDbSetMock(x =\u003e x.Users, initialEntities);\n    \n        // Pass dbContextMock.Object to the class/method you want to test\n    \n        // Query dbContextMock.Object.Users to see if certain users were added or removed\n        // or use Mock Verify functionality to verify if certain methods were called: usersDbSetMock.Verify(x =\u003e x.Add(...), Times.Once);\n    }\n}\n\npublic DbContextOptions\u003cTestDbContext\u003e DummyOptions { get; } = new DbContextOptionsBuilder\u003cTestDbContext\u003e().Options;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuysentruitw%2Fentity-framework-core-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuysentruitw%2Fentity-framework-core-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuysentruitw%2Fentity-framework-core-mock/lists"}