{"id":27003688,"url":"https://github.com/moq/moq4","last_synced_at":"2025-04-04T06:01:14.039Z","repository":{"id":2696386,"uuid":"3689718","full_name":"devlooped/moq","owner":"devlooped","description":"The most popular and friendly mocking framework for .NET","archived":false,"fork":false,"pushed_at":"2024-10-28T15:47:21.000Z","size":23011,"stargazers_count":5924,"open_issues_count":58,"forks_count":801,"subscribers_count":189,"default_branch":"main","last_synced_at":"2024-10-29T10:53:32.352Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/devlooped.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"License.txt","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,"publiccode":null,"codemeta":null},"funding":{"github":"devlooped"}},"created_at":"2012-03-11T21:09:02.000Z","updated_at":"2024-10-29T08:26:51.000Z","dependencies_parsed_at":"2023-09-21T11:48:52.063Z","dependency_job_id":"8d469f92-231d-4150-ae2a-068f0cea78bc","html_url":"https://github.com/devlooped/moq","commit_stats":{"total_commits":2072,"total_committers":135,"mean_commits":"15.348148148148148","dds":0.5183397683397684,"last_synced_commit":"cb605f45609f87301a346baabd757f8582a42150"},"previous_names":["moq/moq4","moq/moq"],"tags_count":112,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlooped%2Fmoq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlooped%2Fmoq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlooped%2Fmoq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlooped%2Fmoq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlooped","download_url":"https://codeload.github.com/devlooped/moq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128747,"owners_count":20888235,"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":"2025-04-04T06:00:42.460Z","updated_at":"2025-04-04T06:01:14.024Z","avatar_url":"https://github.com/devlooped.png","language":"C#","funding_links":["https://github.com/sponsors/devlooped","https://github.com/sponsors"],"categories":["Testing and Mocking","Libraries","🗒️ Cheatsheets"],"sub_categories":["Testing","📦 Libraries"],"readme":"moq\n===\n\n[![Version](https://img.shields.io/nuget/vpre/Moq.svg)](https://www.nuget.org/packages/Moq)\n[![Downloads](https://img.shields.io/nuget/dt/Moq.svg)](https://www.nuget.org/packages/Moq)\n[![Sponsors](https://img.shields.io/github/sponsors/devlooped?style=social)](https://github.com/sponsors/devlooped)\n\n\u003c!-- #content --\u003e\nThe most popular and friendly mocking library for .NET\n\n```csharp\n  var mock = new Mock\u003cILoveThisLibrary\u003e();\n\n  // WOW! No record/replay weirdness?! :)\n  mock.Setup(library =\u003e library.DownloadExists(\"2.0.0.0\"))\n      .Returns(true);\n\n  // Use the Object property on the mock to get a reference to the object\n  // implementing ILoveThisLibrary, and then exercise it by calling\n  // methods on it\n  ILoveThisLibrary lovable = mock.Object;\n  bool download = lovable.DownloadExists(\"2.0.0.0\");\n\n  // Verify that the given method was indeed called with the expected value at most once\n  mock.Verify(library =\u003e library.DownloadExists(\"2.0.0.0\"), Times.AtMostOnce());\n```\n\nMoq also is the first and only library so far to provide Linq to Mocks, so that the \nsame behavior above can be achieved much more succinctly:\n\n```csharp\n  ILoveThisLibrary lovable = Mock.Of\u003cILoveThisLibrary\u003e(l =\u003e\n    l.DownloadExists(\"2.0.0.0\") == true);\n\n  // Exercise the instance returned by Mock.Of by calling methods on it...\n  bool download = lovable.DownloadExists(\"2.0.0.0\");\n\n  // Simply assert the returned state:\n  Assert.True(download);\n  \n  // If you want to go beyond state testing and want to \n  // verify the mock interaction instead...\n  Mock.Get(lovable).Verify(library =\u003e library.DownloadExists(\"2.0.0.0\"));\n```\n\nYou can think of Linq to Mocks as \"from the universe of mocks, give me one whose behavior \nmatches this expression\".\n\nCheck out the [Quickstart](https://github.com/devlooped/moq/wiki/Quickstart) for more examples!\n\n\u003c!-- #content --\u003e\n\n## What?\n\nMoq (pronounced \"Mock-you\" or just \"Mock\") is the only mocking library for .NET developed from scratch to take full advantage of .NET Linq expression trees and lambda expressions, which makes it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn't require any prior knowledge or experience with mocking concepts.\n\n## Why?\n\nThe library was created mainly for developers who aren't currently using any mocking library (or are displeased with the complexities of some other implementation), and who are typically [manually writing their own mocks](https://web.archive.org/web/20200920165817/http://blogs.clariusconsulting.net/kzu/mocks-stubs-and-fakes-its-a-continuum/) (with more or less \"fanciness\"). Most developers in this situation also happen to be [quite pragmatic and adhere to state](https://web.archive.org/web/20200414170510/http://blogs.clariusconsulting.net/kzu/state-testing-vs-interaction-testing/) (or classic) TDD. It's the result of feeling that the barrier of entry from other mocking libraries is a bit high, and a simpler, more lightweight and elegant approach is possible. Moq achieves all this by taking full advantage of the elegant and compact C# and VB language features collectively known as LINQ (they are not just for queries, as the acronym implies).\n\nMoq is designed to be a very practical, unobtrusive and straight-forward way to quickly setup dependencies for your tests. Its API design helps even novice users to fall in the \"pit of success\" and avoid most common misuses/abuses of mocking. \n\nWhen it was conceived, it was the only mocking library that went against the generalized and somewhat unintuitive (especially for novices) Record/Replay approach from all other libraries (and [that might have been a good thing](https://web.archive.org/web/20200920165939/http://blogs.clariusconsulting.net/kzu/whats-wrong-with-the-recordreplyverify-model-for-mocking-frameworks/) ;)).\n\nNot using Record/Replay also means that it's straightforward to move common expectations to a fixture setup method and even override those expectations when needed in a specific unit test.\n\nYou can read more about the \"why\" and see some nice screenshots at [kzu's blog](https://web.archive.org/web/20200920164302/http://blogs.clariusconsulting.net/kzu/why-do-we-need-yet-another-net-mocking-framework/).\n\n## Where?\n\nSee our [Quickstart](https://github.com/devlooped/moq/wiki/Quickstart) examples to get a feeling of the extremely simple API and install from [NuGet](http://nuget.org/packages/moq).\n\nRead about the announcement at [kzu's blog](https://web.archive.org/web/20201130233544/http://blogs.clariusconsulting.net/kzu/linq-to-mock-moq-is-born/). Get some background on [the state of mock libraries from Scott Hanselman](http://www.hanselman.com/blog/MoqLinqLambdasAndPredicatesAppliedToMockObjects.aspx).\n\n## Who?\n\nMoq was originally developed by [Clarius](http://www.clariusconsulting.net), [Manas](http://www.manas.com.ar) and [InSTEDD](http://www.instedd.org).\n\nMoq uses [Castle DynamicProxy](http://www.castleproject.org/projects/dynamicproxy/) internally as the interception mechanism to enable mocking.\n\n\u003c!-- #features --\u003e\n\n## Features at a glance\nMoq offers the following features:\n* Strong-typed: no strings for expectations, no object-typed return values or constraints\n* Unsurpassed VS IntelliSense integration: everything supports full VS IntelliSense, from setting expectations, to specifying method call arguments, return values, etc.\n* No Record/Replay idioms to learn. Just construct your mock, set it up, use it and optionally verify calls to it (you may not verify mocks when they act as stubs only, or when you are doing more classic state-based testing by checking returned values from the object under test)\n* VERY low learning curve as a consequence of the previous three points. For the most part, you don't even need to ever read the documentation.\n* Granular control over mock behavior with a simple [MockBehavior](https://www.fuget.org/packages/Moq/4.16.1/lib/netstandard2.1/Moq.dll/Moq/MockBehavior) enumeration (no need to learn what's the theoretical difference between a mock, a stub, a fake, a dynamic mock, etc.)\n* Mock both interfaces and classes\n* Override expectations: can set default expectations in a fixture setup, and override as needed on tests\n* Pass constructor arguments for mocked classes\n* Intercept and raise events on mocks\n* Intuitive support for ```out/ref``` arguments\n\nWe appreciate deeply any feedback that you may have! Feel free to participate in the [chat], or report an issue in the [issue tracker].\n\n [chat]:\n https://discord.gg/8PtpGdu\n \"Moq channel on Discord\"\n\n [issue tracker]:\n https://github.com/moq/moq/issues\n \"Moq issue tracker on GitHub\"\n\n\u003c!-- #features --\u003e\n\u003c!-- #sponsors --\u003e\n\u003c!-- include https://raw.githubusercontent.com/devlooped/sponsors/main/footer.md --\u003e\n# Sponsors \n\n\u003c!-- sponsors.md --\u003e\n[![Clarius Org](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/clarius.png \"Clarius Org\")](https://github.com/clarius)\n[![MFB Technologies, Inc.](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/MFB-Technologies-Inc.png \"MFB Technologies, Inc.\")](https://github.com/MFB-Technologies-Inc)\n[![Torutek](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/torutek-gh.png \"Torutek\")](https://github.com/torutek-gh)\n[![DRIVE.NET, Inc.](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/drivenet.png \"DRIVE.NET, Inc.\")](https://github.com/drivenet)\n[![Keith Pickford](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/Keflon.png \"Keith Pickford\")](https://github.com/Keflon)\n[![Thomas Bolon](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/tbolon.png \"Thomas Bolon\")](https://github.com/tbolon)\n[![Kori Francis](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/kfrancis.png \"Kori Francis\")](https://github.com/kfrancis)\n[![Toni Wenzel](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/twenzel.png \"Toni Wenzel\")](https://github.com/twenzel)\n[![Uno Platform](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/unoplatform.png \"Uno Platform\")](https://github.com/unoplatform)\n[![Dan Siegel](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/dansiegel.png \"Dan Siegel\")](https://github.com/dansiegel)\n[![Reuben Swartz](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/rbnswartz.png \"Reuben Swartz\")](https://github.com/rbnswartz)\n[![Jacob Foshee](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/jfoshee.png \"Jacob Foshee\")](https://github.com/jfoshee)\n[![](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/Mrxx99.png \"\")](https://github.com/Mrxx99)\n[![Eric Johnson](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/eajhnsn1.png \"Eric Johnson\")](https://github.com/eajhnsn1)\n[![Ix Technologies B.V.](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/IxTechnologies.png \"Ix Technologies B.V.\")](https://github.com/IxTechnologies)\n[![David JENNI](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/davidjenni.png \"David JENNI\")](https://github.com/davidjenni)\n[![Jonathan ](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/Jonathan-Hickey.png \"Jonathan \")](https://github.com/Jonathan-Hickey)\n[![Charley Wu](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/akunzai.png \"Charley Wu\")](https://github.com/akunzai)\n[![Jakob Tikjøb Andersen](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/jakobt.png \"Jakob Tikjøb Andersen\")](https://github.com/jakobt)\n[![Tino Hager](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/tinohager.png \"Tino Hager\")](https://github.com/tinohager)\n[![Ken Bonny](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/KenBonny.png \"Ken Bonny\")](https://github.com/KenBonny)\n[![Simon Cropp](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/SimonCropp.png \"Simon Cropp\")](https://github.com/SimonCropp)\n[![agileworks-eu](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/agileworks-eu.png \"agileworks-eu\")](https://github.com/agileworks-eu)\n[![sorahex](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/sorahex.png \"sorahex\")](https://github.com/sorahex)\n[![Zheyu Shen](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/arsdragonfly.png \"Zheyu Shen\")](https://github.com/arsdragonfly)\n[![Vezel](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/vezel-dev.png \"Vezel\")](https://github.com/vezel-dev)\n[![ChilliCream](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/ChilliCream.png \"ChilliCream\")](https://github.com/ChilliCream)\n[![4OTC](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/4OTC.png \"4OTC\")](https://github.com/4OTC)\n[![Vincent Limo](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/v-limo.png \"Vincent Limo\")](https://github.com/v-limo)\n[![Jordan S. Jones](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/jordansjones.png \"Jordan S. Jones\")](https://github.com/jordansjones)\n[![domischell](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/DominicSchell.png \"domischell\")](https://github.com/DominicSchell)\n[![Joseph Kingry](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/jkingry.png \"Joseph Kingry\")](https://github.com/jkingry)\n\n\n\u003c!-- sponsors.md --\u003e\n\n[![Sponsor this project](https://raw.githubusercontent.com/devlooped/sponsors/main/sponsor.png \"Sponsor this project\")](https://github.com/sponsors/devlooped)\n\u0026nbsp;\n\n[Learn more about GitHub Sponsors](https://github.com/sponsors)\n\n\u003c!-- https://raw.githubusercontent.com/devlooped/sponsors/main/footer.md --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoq%2Fmoq4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoq%2Fmoq4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoq%2Fmoq4/lists"}