{"id":13437852,"url":"https://github.com/huysentruitw/entity-framework-mock","last_synced_at":"2025-04-29T11:32:02.133Z","repository":{"id":65413894,"uuid":"110365207","full_name":"huysentruitw/entity-framework-mock","owner":"huysentruitw","description":"Easy Mock wrapper for mocking EF6 DbContext and DbSet using Moq or NSubstitute","archived":false,"fork":false,"pushed_at":"2024-02-28T19:22:00.000Z","size":140,"stargazers_count":49,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T15:11:18.264Z","etag":null,"topics":["csharp","dotnet","entity-framework","mock","moq","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":"apache-2.0","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":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2017-11-11T17:26:17.000Z","updated_at":"2024-11-15T08:45:08.000Z","dependencies_parsed_at":"2024-06-21T15:34:32.488Z","dependency_job_id":"352b7da1-a33b-4867-93d0-01a27b9971e7","html_url":"https://github.com/huysentruitw/entity-framework-mock","commit_stats":{"total_commits":88,"total_committers":9,"mean_commits":9.777777777777779,"dds":0.5909090909090908,"last_synced_commit":"5622f2c6a33f1efdd14c8c2a68631f680f0ad689"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huysentruitw%2Fentity-framework-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huysentruitw","download_url":"https://codeload.github.com/huysentruitw/entity-framework-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251493991,"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","dotnet","entity-framework","mock","moq","nsubstitute","unit-testing"],"created_at":"2024-07-31T03:01:00.691Z","updated_at":"2025-04-29T11:32:01.479Z","avatar_url":"https://github.com/huysentruitw.png","language":"C#","funding_links":[],"categories":["HarmonyOS","Supported Packages"],"sub_categories":["Windows Manager"],"readme":"# EntityFrameworkMock\n\n[![Build status](https://ci.appveyor.com/api/projects/status/5ung41elf64ahshg/branch/master?svg=true)](https://ci.appveyor.com/project/huysentruitw/entity-framework-mock/branch/master)\n\nEasy Mock wrapper for mocking EF6 DbContext and DbSet in your unit-tests. Integrates with Moq or NSubstitute.\n\nFor mocking Entity Framework Core (EF Core) see \u003chttps://github.com/huysentruitw/entity-framework-core-mock\u003e\n\n## Get it on NuGet\n\n### Moq integration\n\n```powershell\nPM\u003e Install-Package EntityFrameworkMock.Moq\n```\n\n### NSubstitute integration\n\n```powershell\nPM\u003e Install-Package EntityFrameworkMock.NSubstitute\n```\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* 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\n```csharp\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(string connectionString)\n        : base(connectionString)\n    {\n    }\n\n    public virtual DbSet\u003cUser\u003e Users { get; set; }\n}\n\n[TestFixture]\npublic class MyTests\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(\"fake connectionstring\");\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuysentruitw%2Fentity-framework-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuysentruitw%2Fentity-framework-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuysentruitw%2Fentity-framework-mock/lists"}