{"id":30252164,"url":"https://github.com/ipjohnson/simplefixture","last_synced_at":"2025-08-15T11:15:42.914Z","repository":{"id":23375827,"uuid":"26737241","full_name":"ipjohnson/SimpleFixture","owner":"ipjohnson","description":"Testing fixture for .Net","archived":false,"fork":false,"pushed_at":"2022-07-25T22:20:18.000Z","size":3456,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-01T02:01:17.316Z","etag":null,"topics":["c-sharp","data-generation","fixtures","testing"],"latest_commit_sha":null,"homepage":null,"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/ipjohnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-17T02:55:20.000Z","updated_at":"2023-10-06T18:06:02.000Z","dependencies_parsed_at":"2022-08-21T23:31:10.249Z","dependency_job_id":null,"html_url":"https://github.com/ipjohnson/SimpleFixture","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ipjohnson/SimpleFixture","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipjohnson%2FSimpleFixture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipjohnson%2FSimpleFixture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipjohnson%2FSimpleFixture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipjohnson%2FSimpleFixture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipjohnson","download_url":"https://codeload.github.com/ipjohnson/SimpleFixture/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipjohnson%2FSimpleFixture/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270559262,"owners_count":24606698,"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","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-sharp","data-generation","fixtures","testing"],"created_at":"2025-08-15T11:15:37.110Z","updated_at":"2025-08-15T11:15:42.901Z","avatar_url":"https://github.com/ipjohnson.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"SimpleFixture\n=============\n\nSimpleFixture is a .net library that helps provide test data for unit tests and integration tests. The fixture satisfies these three basic use cases. It supports .Net Standard 1.0, and PCL Profile 259.\n\n* **Locate** - Creates a new instance of the requested type. It does not populate public properies. \n```C#\nvar fixture = new Fixture();\n\nvar instance = fixture.Locate\u003cSomeClass\u003e();\n```\n* **Populate** - Populate all public properties with randomly created data for a given instance\n```C#\nvar fixture = new Fixture();\n\nfixture.Populate(instance);\n```\n* **Generate** - Create a new instance of a given type and populate all public properties.\n```C#\nvar fixture = new Fixture();\n\nvar instance = fixture.Generate\u003cSomeClass\u003e();\n```\n\n### Return\n\nIt's useful sometimes to control what values are returned from the fixture. The Return method offers a way to specify what to return for a give type. Below are some examples.\n\n```C#\nvar fixture = new Fixture();\n\n// return the value 1 whenever an int is needed\nfixture.Return(1);\n\n// return the sequence 1, 2, 3, 1, 2, 3 when an int is requested \nfixture.Return(1, 2, 3);\n\n// return incrementing sequence when an int is requested.\nint i = 1;\nfixture.Return(() =\u003e i++);\n```\n\nReturn also offers the ability to be more granular when returning as seen in the examples below. Note you can chain return filters together to be even more granular\n```C#\nvar fixture = new Fixture();\n\n// return the value 1 when being used to construct SomeClass\nfixture.Return(1).For\u003cSomeClass\u003e();\n\n// return incrementing value for int fields ending in Id\nint i = 1;\nfixture.Return(() =\u003e i++).WhenNamed(n =\u003e n.EndsWith(\"Id\"));\n\n// return \"SomeString\" for SomeClass and matchingMethod returns true\nfixture.Return(\"SomeString\").For\u003cSomeClass\u003e().WhenMatching(matchingMethod);\n\n```\n### Export\nSimilar to a depenedency injection container you can specify an implementation for a particular interface\n\n```C#\nvar fixture = new Fixture();\n\n// Export one class at a time\nfixture.ExportAs\u003cSomeClass, ISomeInterface\u003e();\nvar instance = fixture.Locate\u003cISomeInterface\u003e();\nAssert.InstanceOf\u003cSomeClass\u003e(instance);\n\n// Export all classes located in the same assmelby as SomeClass\nfixture.ExportAllByInterface().FromAssemblyContaining\u003cSomeClass\u003e();\nvar instance = fixture.Locate\u003cISomeInterface\u003e();\nAssert.InstanceOf\u003cSomeClass\u003e(instance);\n```\n\n### Constraints\n\nSometimes it's useful to have more control over how an object is created. The generate method takes a constraints object allowing to specify min,max, and other options.\n```C#\n// Generate an int between 10 and 100\nvar intValue = fixture.Generate\u003cint\u003e(constraints: new { min = 10, max = 100 });\n\n// Generate constrained date\nvar dateValue = fixture.Generate\u003cDateTime\u003e(constraints: new { min = dateMin, max = dateMax });\n\n// Set property SomeProperty to value 123 for any int property named SomeProperty\nvar instance = fixture.Generate\u003cSomeClass\u003e(constraints: new { SomeProperty = 123 });\n\n// _Values allows you to provide values based on type rather than on name\nvar someClass = new SomeClass { IntValue = 50, StringValue = \"Test\" };\nvar instance = fixture.Generate\u003cImportSomeClass\u003e(constraints: new { _Values = new[] { someClass } });\nAssert.Same(someClass, instance.SomeClass);\n```\n\n### Customization\n\nCustomization offers you the ability to control how an object gets constructed and populated when Return and Constraints aren't enough. \n\n```C#\nvar fixture = new Fixture();\n\n// customize how a new instance is created\nfixture.Customize\u003cSomeClass\u003e().New(r =\u003e new SomeClass());\n\n// customize creation for a new instance with a random int and string\nfixture.Customize\u003cSomeOtherClass\u003e().NewFactory\u003cint,string\u003e((i,s) = new SomeOtherClass(i,s,\"HardCoded\"));\n\n// call the Initialize method everytime a new instance is created\nfixture.Customize\u003cSomeClass\u003e().Apply(x =\u003e x.Initialize());\n```\n\n### Requested Name\n\nTo help provide more context on how a type should be create you can provide a request name. Below are some example of currently supported request names for strings\n\n```C#\nvar fixture = new Fixture();\n\n// generate a first name\nvar firstName = fixture.Generate\u003cstring\u003e(\"FirstName\");\n\n// generate a last name\nvar lastName = fixture.Generate\u003cstring\u003e(\"LastName\");\n\n// generate a random password with 1 Upper, 1 Lower, 1 Special character and a minimium of 8 characters\nvar password = fixture.Generate\u003cstring\u003e(\"Password\");\n\n// generate a random email for the specified domain\nvar email = fixture.Generate\u003cstring\u003e(\"EmailAddress\", constraints: new { domain = \"gmail.com\" });\n\n// generate an address line 1\nvar addressLine1 = fixture.Generate\u003cstring\u003e(\"AddressLine1\");\n```\n\n### Freeze\nSimilar to Autofixture there is a Freeze method that Generates a new instance and sets it as a Return value.\n\n```C#\n// Generate random int and set it as a Return\nint randomInt = fixture.Freeze\u003cint\u003e();\nAssert.Equal(randomInt, fixture.Generate\u003cint\u003e());\n\n// Freeze an int value for SomeClass\nint randomInt = fixture.Freeze\u003cint\u003e(value: i =\u003e i.For\u003cSomeClass\u003e());\n```\n\n### Behavior\nBehavior allows you to apply cross cutting logic to all objects created by the fixture. You can apply your logic to all objects or just to specific types.\n\n```C#\n// Execute SomeMethod on every object that is created by the fixture\nfixture.Behavior.Add(i =\u003e SomeMethod(i));\n\n// Execute behavior on every instance of ISomeType\nfixture.Behavior.Add\u003cISomeType\u003e(i =\u003e i.SomeMethodOnISomeType());\n```\n\n### Mocking\n\nCurrently Moq, NSubstitute and FakeItEasy are supported allowing you to automatically mock any missing interfaces\n```C#\n// MoqFixture is in SimpleFixture.Moq\nvar fixture = new MoqFixture();\n\n// SubFixture is in SimpleFixture.NSubstitute\nvar fixture = new SubFixture();\n\n// FakeFixture is in SimpleFixture.FakeItEasy\nvar fixture = new FakeFixture();\n```\n\n### Builds\n[![Build status](https://ci.appveyor.com/api/projects/status/6ml6ubwk7v8u4h9m?svg=true)](https://ci.appveyor.com/project/ipjohnson/simplefixture) [![Coverage Status](https://coveralls.io/repos/github/ipjohnson/SimpleFixture/badge.svg?branch=master)](https://coveralls.io/github/ipjohnson/SimpleFixture?branch=master)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipjohnson%2Fsimplefixture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipjohnson%2Fsimplefixture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipjohnson%2Fsimplefixture/lists"}