{"id":23431286,"url":"https://github.com/akamud/fakeiteasy.autofakeit","last_synced_at":"2025-04-12T23:33:05.734Z","repository":{"id":60205871,"uuid":"379067268","full_name":"akamud/FakeItEasy.AutoFakeIt","owner":"akamud","description":"A very simple, yet flexible, \"AutoFaker\" for FakeItEasy to easily auto generate classes with faked dependencies.","archived":false,"fork":false,"pushed_at":"2022-09-26T16:54:43.000Z","size":33,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T20:13:15.697Z","etag":null,"topics":["csharp","fakeiteasy","mstest","nunit","unit-testing","xunit"],"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/akamud.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},"funding":{"github":"akamud"}},"created_at":"2021-06-21T21:28:43.000Z","updated_at":"2023-08-23T18:55:51.000Z","dependencies_parsed_at":"2022-09-26T18:00:21.271Z","dependency_job_id":null,"html_url":"https://github.com/akamud/FakeItEasy.AutoFakeIt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamud%2FFakeItEasy.AutoFakeIt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamud%2FFakeItEasy.AutoFakeIt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamud%2FFakeItEasy.AutoFakeIt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamud%2FFakeItEasy.AutoFakeIt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akamud","download_url":"https://codeload.github.com/akamud/FakeItEasy.AutoFakeIt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647259,"owners_count":21139081,"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","fakeiteasy","mstest","nunit","unit-testing","xunit"],"created_at":"2024-12-23T09:53:57.808Z","updated_at":"2025-04-12T23:33:05.715Z","avatar_url":"https://github.com/akamud.png","language":"C#","funding_links":["https://github.com/sponsors/akamud"],"categories":[],"sub_categories":[],"readme":"# FakeItEasy.AutoFakeIt\n\n![Build](https://github.com/akamud/FakeItEasy.AutoFakeIt/workflows/Build/badge.svg)\n[![codecov](https://codecov.io/gh/akamud/FakeItEasy.AutoFakeIt/branch/main/graph/badge.svg?token=6V0YZL6II9)](https://codecov.io/gh/akamud/FakeItEasy.AutoFakeIt)\n[![Nuget](https://img.shields.io/nuget/v/FakeItEasy.AutoFakeIt.svg?style=flat)](https://www.nuget.org/packages/FakeItEasy.AutoFakeIt)\n\nA very simple, yet flexible, \"AutoFaker\" for [FakeItEasy](https://fakeiteasy.github.io/) to easily auto generate classes with faked dependencies.\n\n## Getting started\n\n[NuGet package](https://www.nuget.org/packages/FakeItEasy.AutoFakeIt) available:\n```\nPM\u003e Install-Package FakeItEasy.AutoFakeIt\n```\n\nI focused on providing a familiar and very simple-to-use API, without any unnecessary limitations, so you can automatically generate your [System Under Test (SUT)](https://en.wikipedia.org/wiki/System_under_test) with all the dependencies faked, whether they are classes or interfaces. You can also customize and retrieve any dependency you want.\n\n```csharp\nusing FakeItEasy;\nusing FakeItEasy.AutoFakeIt;\nusing NUnit.Framework;\n\nnamespace UnitTests\n{\n    public interface IMyDependency\n    {\n        string MyMethod();\n    }\n\n    public class MyDependency : IMyDependency\n    {\n        public string MyMethod() =\u003e \"Hello\";\n    }\n\n    public class MyOtherDependency\n    {\n        public virtual string MyMethod() =\u003e \"World\";\n    }\n\n    public class MySut\n    {\n        public IMyDependency MyDependency { get; }\n        public MyOtherDependency MyOtherDependency { get; }\n\n        public MySut(IMyDependency myDependency, MyOtherDependency myOtherDependency)\n        {\n            MyDependency = myDependency;\n            MyOtherDependency = myOtherDependency;\n        }\n    }\n\n    public class SampleTest\n    {\n        [Test]\n        public void MyTest()\n        {\n            // the main entrypoint, you can put this on a base class, as long\n            // as you always create a new one for each test to make sure that\n            // your tests are idempotent and isolated\n            var autoFakeIt = new AutoFakeIt();\n\n            // you can optionally provide a dependency for any type\n            autoFakeIt.Provide\u003cIMyDependency\u003e(new MyDependency());\n\n            // it will respect any objects you've provided before\n            // you can also just let the Generate provide FakeItEasy's fakes\n            // for all missing dependencies\n            var mySut = autoFakeIt.Generate\u003cMySut\u003e();\n\n            // you can get any dependency used/generated\n            var theAutoFakedDependency = autoFakeIt.Resolve\u003cMyOtherDependency\u003e();\n\n            // you can setup or assert the generated fakes since it is\n            // just an ordinary FakeItEasy's fake object\n            A.CallTo(() =\u003e theAutoFakedDependency.MyMethod()).Returns(\"Faked\");\n        }\n    }\n}\n\n```\n\nThat's all you probably need from an autofaker. If you want, you can look at this project's [tests](https://github.com/akamud/FakeItEasy.AutoFakeIt/blob/main/tests/FakeItEasy.AutoFakeIt.UnitTests/Specs/AutoFakeItTests.cs) to see all the possibilites.\n\n## Other options\n\nThere are many other alternatives to this package, why did I make yet another autofaker for FakeItEasy? While all the other alternatives worked, many of them had a few shortcomings related to how **I** expected it to work. I grew accustomed to the automocker from Moq that had a very similar API to this package.  \nThat doesn't mean that this is the best implementation available, it just means that this is the implementation that was the most familiar to **me**. Hopefully some of you will find it familiar too. \n\nMy goal with this package was to provide all the features I wanted, that were missing in all the other alternatives I've tested:\n\n* Have a way of providing a concrete class instead of relying on a faked dependency\n* Automatically provide a fake for a concrete class (with virtual methods) instead of requiring an interface\n* Allow changing a dependency after instantiating the `AutoFakeIt` object\n* Allow passing dependencies or requesting generated dependencies any time\n\nAll the other packages missed some of the above.\n\n### Available alternatives\n- [Autofac.Extras.FakeItEasy](https://github.com/autofac/Autofac.Extras.FakeItEasy)\n- [FakeItEasy.Auto](https://github.com/jamiehumphries/FakeItEasy.Auto)\n- [FakeItEasy.AutoFake](https://github.com/fkthat/FakeItEasy.AutoFake)\n\n## Contributing\n\nIf you have a scenario that isn't supported, please open an issue so we can discuss it :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamud%2Ffakeiteasy.autofakeit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakamud%2Ffakeiteasy.autofakeit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamud%2Ffakeiteasy.autofakeit/lists"}