{"id":24124865,"url":"https://github.com/serg046/autofake","last_synced_at":"2025-09-18T15:32:44.916Z","repository":{"id":10282537,"uuid":"65227187","full_name":"Serg046/AutoFake","owner":"Serg046","description":"Mock any type members including static and non-virtual ones","archived":false,"fork":false,"pushed_at":"2024-07-04T12:28:06.000Z","size":1374,"stargazers_count":53,"open_issues_count":41,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-11T06:32:11.540Z","etag":null,"topics":["fake","fake-data","faker","faker-library","mock","mocking","mocking-library","monkey-patching","testing-tools"],"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/Serg046.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}},"created_at":"2016-08-08T18:04:32.000Z","updated_at":"2024-12-28T00:37:40.000Z","dependencies_parsed_at":"2024-03-14T00:24:40.756Z","dependency_job_id":"55eecd7f-9643-4eb7-8c2d-b1373579dbbc","html_url":"https://github.com/Serg046/AutoFake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Serg046%2FAutoFake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Serg046%2FAutoFake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Serg046%2FAutoFake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Serg046%2FAutoFake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Serg046","download_url":"https://codeload.github.com/Serg046/AutoFake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233493855,"owners_count":18684553,"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":["fake","fake-data","faker","faker-library","mock","mocking","mocking-library","monkey-patching","testing-tools"],"created_at":"2025-01-11T14:36:36.504Z","updated_at":"2025-09-18T15:32:44.891Z","avatar_url":"https://github.com/Serg046.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoFake\n[![Build](https://img.shields.io/github/check-runs/Serg046/AutoFake/master?label=build)](https://github.com/Serg046/AutoFake/actions/workflows/ci.yml)\n[![NuGet](https://img.shields.io/nuget/v/AutoFake)](https://www.nuget.org/packages/AutoFake)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/AutoFake.svg?label=downloads)](https://www.nuget.org/packages/AutoFake)\n[![.NET Framework 4](https://img.shields.io/badge/.NET%20%20Framework-4.5+-brightgreen)](https://www.nuget.org/packages/AutoFake)\n[![.NET Standard 2](https://img.shields.io/badge/.NET%20%20Standard-2+-brightgreen)](https://www.nuget.org/packages/AutoFake)   \n[![Telegram](https://img.shields.io/badge/telegram-AutoFakeLib-brightgreen)](https://t.me/AutoFakeLib)\n[![Codecov](https://img.shields.io/codecov/c/github/Serg046/AutoFake?flag=functional_tests\u0026label=coverage%20by%20functional%20tests\u0026token=j95lb948sw02nqqd)](https://codecov.io/gh/Serg046/AutoFake)\n[![Code Climate](https://img.shields.io/codeclimate/maintainability/Serg046/AutoFake)](https://codeclimate.com/github/Serg046/AutoFake)\n[![Code Climate](https://img.shields.io/codeclimate/issues/Serg046/AutoFake?label=code%20smells)](https://codeclimate.com/github/Serg046/AutoFake)\n[![Code Climate](https://img.shields.io/codeclimate/tech-debt/Serg046/AutoFake)](https://codeclimate.com/github/Serg046/AutoFake)\n\nImagine you have the following `Calendar` class and you want to replace some members which are not overridable via classic mocking libraries...\n```csharp\npublic class Calendar\n{\n    public static DateTime Yesterday =\u003e DateTime.Now.AddDays(-1);\n    internal Task\u003cDateTime\u003e AddSomeMinutesAsync(DateTime date) =\u003e Task.Run(() =\u003e AddSomeMinutes(date));\n    public static DateTime AddSomeMinutes(DateTime date) =\u003e date.AddMinutes(new Random().Next(1, 10));\n}\n```\nStatic `DateTime.Now` property (run it on [.NET Fiddle](https://dotnetfiddle.net/0YHkD8)):\n```csharp\n[Fact]\npublic void Yesterday_SomeDay_ThePrevDay()\n{\n    var fake = new Fake\u003cCalendar\u003e();\n\n    var sut = fake.Rewrite(() =\u003e Calendar.Yesterday);\n    sut.Replace(() =\u003e DateTime.Now).Return(new DateTime(2016, 8, day: 8));\n\n    Assert.Equal(new DateTime(2016, 8, 7), sut.Execute());\n}\n```\nNon-static and virtual `Random.Next(int, int)` method but instantiated right inside the `AddSomeMinutes` method (run it on [.NET Fiddle](https://dotnetfiddle.net/mTcg95)):\n```csharp\n[Fact]\npublic async Task AddSomeMinutesAsync_SomeDay_MinutesAdded()\n{\n    var randomValue = 7;\n    var date = new DateTime(2016, 8, 8, hour: 0, minute: 0, second: 0);\n    var fake = new Fake\u003cCalendar\u003e();\n\n    var sut = fake.Rewrite(f =\u003e f.AddSomeMinutesAsync(date));\n    sut.Replace((Random r) =\u003e r.Next(1, 10)) // Arg.Is\u003cint\u003e(i =\u003e i == 10) is also possible\n                           // r.Next(1, 11) fails with \"Expected - 11, actual - 10\"\n        .ExpectedCalls(1) // c =\u003e c \u003e 1 fails with \"Actual value - 1\"\n        .Return(randomValue);\n\n    Assert.Equal(date.AddMinutes(randomValue), await sut.Execute());\n}\n```\nYou can also add additional statements at specific places that could be helpful for non-trivial scenarios like race-condition testing (run it on [.NET Fiddle](https://dotnetfiddle.net/F44Xv0)):\n```csharp\n[Fact]\npublic void AddSomeMinutes_SomeDay_EventsRecorded()\n{\n    var events = new List\u003cstring\u003e();\n    var fake = new Fake\u003cCalendar\u003e();\n\n    var sut = fake.Rewrite(() =\u003e Calendar.AddSomeMinutes(new DateTime(2016, 8, 8)));\n\n    sut.Prepend(() =\u003e events.Add(\"The first line\"));\n    sut.Prepend(() =\u003e events.Add(\"The line before AddMinutes(...) call\"))\n        .Before((DateTime date) =\u003e date.AddMinutes(Arg.IsAny\u003cint\u003e()));\n\n    sut.Append(() =\u003e events.Add(\"The line after new Random() call\"))\n        .After(() =\u003e new Random());\n    sut.Append(() =\u003e events.Add(\"The last line\"));\n\n    sut.Execute();\n    Assert.Equal(new[]\n        {\n            \"The first line\",\n            \"The line after new Random() call\", // indeed, this call is earlier\n            \"The line before AddMinutes(...) call\",\n            \"The last line\"\n        },\n        events);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserg046%2Fautofake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserg046%2Fautofake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserg046%2Fautofake/lists"}