{"id":26949408,"url":"https://github.com/rbengtsson/automoqer","last_synced_at":"2025-04-02T22:15:20.366Z","repository":{"id":48955037,"uuid":"73811317","full_name":"rbengtsson/Automoqer","owner":"rbengtsson","description":"Automatically creates services for unit testing with all constructor parameters as Moq-objects","archived":false,"fork":false,"pushed_at":"2021-07-03T15:59:48.000Z","size":38,"stargazers_count":17,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T16:49:57.362Z","etag":null,"topics":["moq","nuget","unit-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/rbengtsson.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":"2016-11-15T12:25:34.000Z","updated_at":"2022-12-16T16:07:49.000Z","dependencies_parsed_at":"2022-09-02T03:22:20.338Z","dependency_job_id":null,"html_url":"https://github.com/rbengtsson/Automoqer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbengtsson%2FAutomoqer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbengtsson%2FAutomoqer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbengtsson%2FAutomoqer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbengtsson%2FAutomoqer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbengtsson","download_url":"https://codeload.github.com/rbengtsson/Automoqer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246899668,"owners_count":20851898,"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":["moq","nuget","unit-testing"],"created_at":"2025-04-02T22:15:19.551Z","updated_at":"2025-04-02T22:15:20.351Z","avatar_url":"https://github.com/rbengtsson.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"This repository contains a nuget package called \"Automoqer\": https://www.nuget.org/packages/Automoqer/\n\n\n# About Automoqer #\n\nThe purpose of Automoqer is to ease the creation of services with constructor IoC in unit testing.\n\n\n## Basic usage ##\n\n1. Get Automoqer via NuGet: [![NuGet](https://img.shields.io/nuget/v/Automoqer.svg)](https://www.nuget.org/packages/Automoqer/)\n\n2. In your unit test, create an Automoqer instance like this:\n\n```csharp\nusing (var serviceMocker = new AutoMoqer\u003cServiceToCreate\u003e().Build())\n{\t\n\t//Example definition of a dependency mock setup:\n\tserviceMocker.Param\u003cICustomerRepository\u003e().Setup(m =\u003e m.FindCustomer(It.Is\u003cint\u003e(p =\u003e p == 1))).Returns(new Customer());\n\n\t//Access the service instance:\n\tvar service = serviceMocker.Service;\n\n\t//Example verification of a method call\n\tserviceMocker.Param\u003cILogger\u003e().Verify(m =\u003e m.Log(It.IsAny\u003cstring\u003e));\n}\n```\n\n## Why using Automoqer ##\n\nIf your services are defined like this:\n\n```csharp\npublic class CustomerService \n{\n\tprivate readonly ILogger _logger;\n\tprivate readonly IUnitOfWork _unitOfWork;\n\tprivate readonly IAnotherDependency _anotherDependency;\n\n\tpublic CustomerService(\n\t\tILogger logger,\n\t\tIUnitOfWork unitOfWork,\n\t\tIAnotherDependency anotherDependency\t\n\t) \n\t{\n\t\t_logger = logger;\n\t\t_unitOfWork = unitOfWork;\n\t\t_anotherDependency = anotherDependency;\n\t}\n\n\t//...\n}\n```\n\nThen chances are that you have a lot of unit tests that looks like this:\n\n```csharp\n[Fact]\npublic CreateNewCustomerSuccessfully()\n{\n\tvar loggerMock = new Mock\u003cILogger\u003e();\n\tvar unitOfWorkMock = new Mock\u003cIUnitOfWork\u003e();\n\tvar anotherDependencyMock = new Mock\u003cIAnotherDependency\u003e();\n\n\t//Your Moq .Setup are defined here..\n\n\tvar service = new CustomerService(\n\t\tloggerMock.Object,\n\t\tunitOfWorkMock.Object,\n\t\tanotherDependencyMock.Object\n\t);\n\n\t//Actual test-case goes here...\n\n\t//Your Moq .Verify are defined here...\n}\n```\n\nThis is quite tedious to write and if you need to change the service's dependencies, you'll have a lot of test cases to change.\n\nAutomoqer removes this boilerplate for you by automatically create a Service with its constructor parameters as Moq-objects:\n\n```csharp\n[Fact]\npublic CreateNewCustomerSuccessfully()\n{\n    using (var serviceMocker = new AutoMoqer\u003cCustomerService\u003e().Build())\n    {\n\t\t//Your Moq .Setup are defined here..\n\t\t//Mocks accessed by serviceMocker.Param\u003cILogger\u003e().Setup(...\n\n\t\t//Actual test-case goes here...\n\t\t//Service accessed by serviceMocker.Service\n\n\t\t//Your Moq .Verify are defined here...\n\t}\t\n}\n```\n\nIt also runs VerifyAll() on all Moq-objects in its Dispose-method (hence the IDisposable-pattern)\n\n\n## Advanced usage ##\n\n### Provide parameter instances ###\n\nYou can make exceptions from having Automoqer automatically create Moq-objects from all constructor parameters. This is done by using one of the `.With` methods available on the AutoMoqer instance. Please note that these exceptions will not be available through the `.Param` method on the Automoqer-container.\n\n#### By parameter type ####\n\nThis is how you provide your own instance of a parameter by it's type:\n\n```csharp\nvar logger = new TestLogger();\n\nusing (var serviceMocker = new AutoMoqer\u003cCustomerService\u003e()\n\t.With\u003cILogger\u003e(logger)\n\t.Build())\n{\n\t//...\n}\n```\t\n\n#### By parameter name ####\n\nThis is how you provide your own instance of a parameter by it's type:\n\n```csharp\nvar logger = new TestLogger();\n\nusing (var serviceMocker = new AutoMoqer\u003cCustomerService\u003e()\n\t.With(\"logger\", logger)\n\t.Build())\n{\n\t//...\n}\t\t\t\n```\n\n\n# Contributors #\n\n * Robert Bengtsson - https://github.com/rbengtsson\n * Stefan Matsson - https://github.com/smatsson\n * Manuel Pfemeter - https://github.com/manne\n\n\n# License and usage\n\nMIT License\n\nCopyright (c) 2016 Robert Bengtsson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbengtsson%2Fautomoqer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbengtsson%2Fautomoqer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbengtsson%2Fautomoqer/lists"}