{"id":22525235,"url":"https://github.com/tugberkugurlu/mongodb.testing","last_synced_at":"2025-08-03T21:32:23.224Z","repository":{"id":27289266,"uuid":"30762875","full_name":"tugberkugurlu/MongoDB.Testing","owner":"tugberkugurlu","description":"MongoDB integration testing helper from .NET projects","archived":false,"fork":false,"pushed_at":"2016-10-21T16:19:11.000Z","size":90,"stargazers_count":6,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-12T01:42:38.476Z","etag":null,"topics":["dotnet","dotnet-core","mongodb","random-database","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/tugberkugurlu.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}},"created_at":"2015-02-13T15:43:45.000Z","updated_at":"2019-12-02T08:16:54.000Z","dependencies_parsed_at":"2022-09-11T19:31:21.814Z","dependency_job_id":null,"html_url":"https://github.com/tugberkugurlu/MongoDB.Testing","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugberkugurlu%2FMongoDB.Testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugberkugurlu%2FMongoDB.Testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugberkugurlu%2FMongoDB.Testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugberkugurlu%2FMongoDB.Testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tugberkugurlu","download_url":"https://codeload.github.com/tugberkugurlu/MongoDB.Testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567024,"owners_count":17937986,"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":["dotnet","dotnet-core","mongodb","random-database","testing"],"created_at":"2024-12-07T06:09:03.151Z","updated_at":"2024-12-07T06:09:03.778Z","avatar_url":"https://github.com/tugberkugurlu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## MongoDB.Testing\r\n\r\nMongoDB integration testing helper from .NET projects that stands up a server and a random database on the fly. \r\nThe library is compatible with .NET 4.5.1 and [.NET Standard](https://docs.microsoft.com/en-us/dotnet/articles/standard/library) 1.6.\r\n\r\n## Quick Start\r\n\r\nInstall the library into your testing project through NuGet:\r\n\r\n```\r\nInstall-Package MongoDB.Testing -pre\r\n```\r\n\r\nWrite a `mongod` executable locator like below one for example (which is specific to Windows):\r\n\r\n```csharp\r\npublic class MongodExeLocator : IMongoExeLocator\r\n{\r\n    public string Locate()\r\n    {\r\n        return @\"C:\\Program Files\\MongoDB\\Server\\3.0\\bin\\mongod.exe\";\r\n    }\r\n}\r\n```\r\n\r\nIntegrate it into your tests:\r\n\r\n```csharp\r\n[Test]\r\npublic async Task HasEnoughRating_Should_Throw_InvalidOperationException_When_The_User_Is_Not_Found()\r\n{\r\n    using (MongoTestServer server = MongoTestServer.Start(27017, new MongodExeLocator()))\r\n    {\r\n        // ARRANGE\r\n        var collection = server.Database.GetCollection\u003cUserEntity\u003e(\"users\");\r\n        var service = new MyCounterService(collection);\r\n        await collection.InsertOneAsync(new UserEntity\r\n        {\r\n            Id = ObjectId.GenerateNewId().ToString(),\r\n            Name = \"foo\",\r\n            Rating = 23\r\n        });\r\n\r\n        // ACT, ASSERT\r\n        Assert.Throws\u003cInvalidOperationException\u003e(\r\n            () =\u003e service.HasEnoughRating(ObjectId.GenerateNewId().ToString()));\r\n    }\r\n}\r\n```\r\n\r\n`MongoTestServer.Start` will do the following:\r\n\r\n - Start a `mongod` instance and expose it through the specified port.\r\n - Creates a randomly named MongoDB database on the started instance and exposes it through the `MongoTestServer` instance returned from `MongoTestServer.Start` method.\r\n - Cleans up the resources, kills the mongod.exe instance when the `MongoTestServer` instance is disposed.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftugberkugurlu%2Fmongodb.testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftugberkugurlu%2Fmongodb.testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftugberkugurlu%2Fmongodb.testing/lists"}