{"id":17046491,"url":"https://github.com/tkellogg/trappings","last_synced_at":"2025-07-20T14:32:46.903Z","repository":{"id":3450211,"uuid":"4503590","full_name":"tkellogg/Trappings","owner":"tkellogg","description":"Test fixtures for C# and MongoDB","archived":false,"fork":false,"pushed_at":"2013-05-20T20:50:27.000Z","size":412,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-06T16:56:16.293Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkellogg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-31T03:51:57.000Z","updated_at":"2024-04-12T16:55:38.000Z","dependencies_parsed_at":"2022-09-08T12:30:38.943Z","dependency_job_id":null,"html_url":"https://github.com/tkellogg/Trappings","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tkellogg/Trappings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkellogg%2FTrappings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkellogg%2FTrappings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkellogg%2FTrappings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkellogg%2FTrappings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkellogg","download_url":"https://codeload.github.com/tkellogg/Trappings/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkellogg%2FTrappings/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266140112,"owners_count":23882610,"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":[],"created_at":"2024-10-14T09:46:28.097Z","updated_at":"2025-07-20T14:32:46.885Z","avatar_url":"https://github.com/tkellogg.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Trappings is a convenient way to setup integration tests with MongoDB. You\r\ndefine reusable sets of data (fixtures) that will also be cleaned out at\r\nthe end of a test.\r\n\r\nDefine Fixtures\r\n---------------\r\n\r\nThe cleanest way to setup a fixture is to create a class that implements \r\n`ITestFixtureData`:\r\n\r\n```csharp\r\nclass TheRaceTrack : ITestFixtureData\r\n{\r\n  // A convenient pattern to follow is to make static properties for things\r\n  // you'll access within the test. All of these are completely valid within\r\n  // the using block.\r\n  public static Car Cruze { get; set; }\r\n\r\n  public IEnumerable\u003cSetupObject\u003e Setup() \r\n  {\r\n    // Assign to static field for easy access later\r\n    Cruze = new Car { Make = \"Chevy\", Model = \"Cruze\" };\r\n\r\n    // cruze will be inserted into the database after this line\r\n    yield return new SetupObject { CollectionName = \"cars\", Value = Cruze };\r\n\r\n    // Since `cruze` has already been inserted, it's ID is already auto-assigned\r\n    var tim = new Driver { Name = \"Tim\", CarId = Cruze.Id };\r\n    yield return new SetupObject(\"drivers\", tim);\r\n  }\r\n}\r\n```\r\n\r\nEach item that is yielded into the Enumerable is immediately inserted into the \r\ndatabase. This is useful (as above) for setting up relationships between \r\ncollections. It's also sometimes useful to hold a reference to objects created\r\nin a static property or field - so you can access them during tests for verifying\r\nbehavior.\r\n\r\nUsing fixtures from a test\r\n--------------------------\r\n\r\n```csharp\r\n[Test]\r\npublic void ILoveCars()\r\n{\r\n  using(FixtureSession.Create\u003cTheRaceTrack\u003e())\r\n  {\r\n    // Database is now setup. You can use code that assumes that documents\r\n    // exist in db.cars and db.drivers\r\n\r\n    var driver = from driver in drivers.AsQueryable()\r\n                 where driver.CarId == TheRaceTrack.Cruze.Id\r\n                 select driver;\r\n\r\n    driver.Count().ShouldEqual(1);\r\n  }\r\n  // objects from TheRaceTrack are no longer accessible in Mongo\r\n}\r\n```\r\n\r\nYou can use this for inter-process tests -- like functional or regression\r\ntests that hit a website or web service. \r\n\r\nBuilding\r\n--------\r\n\r\n * Install [Visual Studio Visualization and Modeling SDK](http://archive.msdn.microsoft.com/vsvmsdk). This is required for the T4 templates. The project won't build without it.\r\n * Open `Trappings.sln` in Visual Studio 2010.\r\n * Build!\r\n\r\nTo build the NuGet package, you have to use the rakefile:\r\n * Install Ruby\r\n * run `gem install rake albacore`\r\n * `cd` into the root of your checkout root\r\n * run `rake package`\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkellogg%2Ftrappings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkellogg%2Ftrappings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkellogg%2Ftrappings/lists"}