├── .github
├── FUNDING.yml
├── workflows
│ ├── os-matrix.json
│ ├── dotnet.json
│ ├── changelog.config
│ ├── dotnet-file.yml
│ ├── changelog.yml
│ ├── includes.yml
│ └── publish.yml
├── release.yml
├── actions
│ └── dotnet
│ │ └── action.yml
└── dependabot.yml
├── src
├── Moq.snk
├── Moq
│ ├── icon.png
│ ├── readme.md
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Behavior.cs
│ ├── IMatcher.cs
│ ├── Behaviors
│ │ ├── NoOp.cs
│ │ ├── ReturnBase.cs
│ │ ├── ReturnValue.cs
│ │ ├── ThrowException.cs
│ │ ├── Callback.cs
│ │ ├── ReturnComputedValue.cs
│ │ ├── ThrowComputedException.cs
│ │ ├── VerifyInvocationCount.cs
│ │ └── RaiseEvent.cs
│ ├── Language
│ │ ├── Flow
│ │ │ ├── ICallBaseResult.cs
│ │ │ ├── IThrowsResult.cs
│ │ │ ├── IReturnsResult.cs
│ │ │ ├── ICallbackResult.cs
│ │ │ ├── SetterSetupPhrase.cs
│ │ │ ├── IReturnsThrows.cs
│ │ │ ├── ISetup.cs
│ │ │ └── WhenPhrase.cs
│ │ ├── ICallBase.cs
│ │ ├── GenericTypeParameters.tt
│ │ ├── ICallbackSetter.cs
│ │ ├── ICallbackGetter.cs
│ │ ├── IRaise.tt
│ │ ├── ISetupSequentialResult.cs
│ │ ├── IReturns.tt
│ │ ├── ISetupConditionResult.cs
│ │ ├── IThrows.tt
│ │ ├── IRaise.cs
│ │ └── IReturnsGetter.cs
│ ├── MockExceptionReasons.cs
│ ├── ISetupList.cs
│ ├── Interception
│ │ ├── IInterceptor.cs
│ │ ├── IProxy.cs
│ │ ├── ProxyFactory.cs
│ │ └── Mock.cs
│ ├── IInvocationList.cs
│ ├── Condition.cs
│ ├── Range.cs
│ ├── Matchers
│ │ ├── AnyMatcher.cs
│ │ ├── ExpressionMatcher.cs
│ │ ├── LazyEvalMatcher.cs
│ │ ├── RefMatcher.cs
│ │ ├── ConstantMatcher.cs
│ │ └── ParamArrayMatcher.cs
│ ├── MethodSetup.cs
│ ├── Obsolete
│ │ ├── MockExtensions.cs
│ │ ├── SequenceExtensions.cs
│ │ └── IOccurrence.cs
│ ├── Async
│ │ ├── IAwaitableFactory.cs
│ │ ├── ValueTaskFactory.cs
│ │ ├── Awaitable.cs
│ │ ├── TaskFactory.cs
│ │ ├── AwaitExpression.cs
│ │ ├── TaskFactory`1.cs
│ │ ├── AwaitableFactory.cs
│ │ ├── ValueTaskFactory`1.cs
│ │ ├── AwaitableFactory`1.cs
│ │ └── AwaitableFactory`2.cs
│ ├── DefaultExpressionCompiler.cs
│ ├── Expressions
│ │ └── Visitors
│ │ │ ├── Apply.cs
│ │ │ ├── EvaluateCaptures.cs
│ │ │ └── ConstructorCallVisitor.cs
│ ├── MockBehavior.cs
│ ├── MockExtensions.cs
│ ├── IMocked.cs
│ ├── Switches.cs
│ ├── MatchExpression.cs
│ ├── ITypeMatcher.cs
│ ├── ParameterTypes.cs
│ ├── Pair.cs
│ ├── Protected
│ │ └── ProtectedExtension.cs
│ ├── InvocationFunc.cs
│ ├── InvocationAction.cs
│ ├── IMock.cs
│ ├── ImmutablePopOnlyStack.cs
│ ├── Expectation.cs
│ ├── ExpressionReconstructor.cs
│ ├── IInvocation.cs
│ ├── InnerMockSetup.cs
│ ├── CaptureMatch.cs
│ ├── EventHandlerCollection.cs
│ ├── DefaultValue.cs
│ ├── SequenceSetup.cs
│ ├── MockSequence.cs
│ ├── MockDefaultValueProvider.cs
│ ├── EmptyDefaultValueProvider.cs
│ ├── TypeMatcherAttribute.cs
│ ├── ExpressionCompiler.cs
│ ├── SetupWithOutParameterSupport.cs
│ ├── AsInterface.cs
│ └── Linq
│ │ ├── MockQuery.cs
│ │ └── Mock.cs
├── Moq.Tests.ComTypes
│ ├── Moq.Tests.ComTypes.dll
│ ├── BuildDLLFromIDL.cmd
│ ├── ComTypes.idl
│ └── README.md
├── Moq.Tests.FSharpTypes
│ ├── IHasProperty.fs
│ ├── IHasIndexer.fs
│ ├── IHasActionEvent.fs
│ ├── HasAbstractIndexer.fs
│ ├── HasAbstractProperty.fs
│ ├── IHasEventHandlerEvent.fs
│ ├── HasAbstractActionEvent.fs
│ ├── HasActionEvent.fs
│ ├── HasAbstractEventHandlerEvent.fs
│ ├── HasProperty.fs
│ ├── HasIndexer.fs
│ └── Moq.Tests.FSharpTypes.fsproj
├── Moq.Tests
│ ├── StringExtensions.cs
│ ├── ReflectionExtensions.cs
│ ├── Async
│ │ └── AwaitableFixture.cs
│ ├── RecordsFixture.cs
│ ├── HidePropertyFixture.cs
│ ├── Regressions
│ │ ├── StreamFixture.cs
│ │ └── FluentMockIssues.cs
│ ├── CaptureMatchFixture.cs
│ ├── CallBaseFixture.cs
│ ├── IsValueTypeFixture.cs
│ ├── IsSubtypeFixture.cs
│ ├── UnmatchableMatchersFixture.cs
│ ├── Matchers
│ │ ├── AnyMatcherFixture.cs
│ │ └── ParamArrayMatcherFixture.cs
│ ├── SetupsFixture.cs
│ ├── StringBuilderExtensionsFixture.cs
│ ├── DefaultValueProviderFixture.cs
│ ├── InterceptorFixture.cs
│ ├── EventHandlerTypesMustMatchFixture.cs
│ ├── SequentialActionExtensionsFixture.cs
│ ├── OccurrenceFixture.cs
│ └── Moq.Tests.csproj
├── Directory.props
└── Moq.Tests.VisualBasic
│ └── Moq.Tests.VisualBasic.vbproj
├── docs
├── Gemfile
├── _sass
│ ├── utility
│ │ ├── max-width.scss
│ │ ├── text-alignment.scss
│ │ ├── padding.scss
│ │ ├── margin.scss
│ │ ├── width.scss
│ │ ├── position.scss
│ │ ├── height.scss
│ │ ├── flex.scss
│ │ └── space-between.scss
│ └── reset.scss
├── assets
│ ├── images
│ │ ├── github-32.png
│ │ └── moq-icon.png
│ └── main.scss
├── user-guide
│ └── index.md
├── index.md
├── _config.yml
├── _layouts
│ ├── default.html
│ └── homepage.html
├── _includes
│ ├── head.html
│ └── header.html
└── Gemfile.lock
├── assets
├── img
│ ├── moq.png
│ ├── moq-icon.png
│ ├── moq-small.png
│ └── moq-bigger.png
└── css
│ └── style.scss
├── _config.yml
├── Directory.Build.rsp
├── .gitattributes
├── .gitignore
└── License.txt
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: devlooped
2 |
--------------------------------------------------------------------------------
/.github/workflows/os-matrix.json:
--------------------------------------------------------------------------------
1 | ["windows-latest"]
--------------------------------------------------------------------------------
/src/Moq.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/src/Moq.snk
--------------------------------------------------------------------------------
/.github/workflows/dotnet.json:
--------------------------------------------------------------------------------
1 | [
2 | "6.x",
3 | "8.x",
4 | "9.x"
5 | ]
--------------------------------------------------------------------------------
/docs/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'jekyll-relative-links'
4 |
--------------------------------------------------------------------------------
/docs/_sass/utility/max-width.scss:
--------------------------------------------------------------------------------
1 | .max-w-650 {
2 | max-width: 650px;
3 | }
4 |
--------------------------------------------------------------------------------
/src/Moq/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/src/Moq/icon.png
--------------------------------------------------------------------------------
/assets/img/moq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/assets/img/moq.png
--------------------------------------------------------------------------------
/docs/_sass/utility/text-alignment.scss:
--------------------------------------------------------------------------------
1 | .text-center {
2 | text-align: center;
3 | }
4 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-slate
2 |
3 | exclude: [ 'src/', '*.sln', 'Gemfile*', '*.rsp' ]
--------------------------------------------------------------------------------
/assets/img/moq-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/assets/img/moq-icon.png
--------------------------------------------------------------------------------
/assets/img/moq-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/assets/img/moq-small.png
--------------------------------------------------------------------------------
/assets/img/moq-bigger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/assets/img/moq-bigger.png
--------------------------------------------------------------------------------
/docs/assets/images/github-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/docs/assets/images/github-32.png
--------------------------------------------------------------------------------
/docs/assets/images/moq-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/docs/assets/images/moq-icon.png
--------------------------------------------------------------------------------
/docs/user-guide/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | ---
3 |
4 | # User Guide
5 |
6 | This is work in progress and currently under construction.
7 |
--------------------------------------------------------------------------------
/docs/_sass/utility/padding.scss:
--------------------------------------------------------------------------------
1 | .p {
2 |
3 | &x-8 {
4 | padding-left: 4px;
5 | padding-right: 4px;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Moq.Tests.ComTypes/Moq.Tests.ComTypes.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devlooped/moq/HEAD/src/Moq.Tests.ComTypes/Moq.Tests.ComTypes.dll
--------------------------------------------------------------------------------
/Directory.Build.rsp:
--------------------------------------------------------------------------------
1 | # See https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-response-files
2 | -nr:false
3 | -m:1
4 | -v:m
5 | -clp:Summary;ForceNoAlign
6 |
--------------------------------------------------------------------------------
/docs/_sass/utility/margin.scss:
--------------------------------------------------------------------------------
1 | .mx-auto {
2 | margin-left: auto;
3 | margin-right: auto;
4 | }
5 |
6 | .my-36 {
7 | margin-top: 36px;
8 | margin-bottom: 36px;
9 | }
10 |
--------------------------------------------------------------------------------
/src/Moq/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | ---
3 |
4 | 
5 |
6 | Welcome to the documentation for Moq!
7 |
8 | [Quickstart](https://github.com/moq/moq/wiki/Quickstart) \| [User Guide](user-guide/index.md)
9 |
--------------------------------------------------------------------------------
/docs/_sass/utility/width.scss:
--------------------------------------------------------------------------------
1 | .w {
2 |
3 | &-full {
4 | width: 100%;
5 | }
6 |
7 | &-24 {
8 | width: 24px;
9 | }
10 |
11 | &-42 {
12 | width: 42px;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/docs/_sass/utility/position.scss:
--------------------------------------------------------------------------------
1 | .absolute {
2 | position: absolute;
3 | }
4 |
5 | .relative {
6 | position: relative;
7 | }
8 |
9 | .sticky {
10 | position: sticky;
11 | }
12 |
13 | .top-0 {
14 | top: 0;
15 | }
16 |
--------------------------------------------------------------------------------
/src/Moq/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Resources;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: ComVisible(false)]
6 | [assembly: CLSCompliant(true)]
7 | [assembly: NeutralResourcesLanguage("en-US")]
8 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # normalize by default
2 | * text=auto encoding=UTF-8
3 | *.sh text eol=lf
4 | *.sbn eol=lf
5 |
6 | # These are windows specific files which we may as well ensure are
7 | # always crlf on checkout
8 | *.bat text eol=crlf
9 | *.cmd text eol=crlf
10 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | baseurl: /moq
2 |
3 | defaults:
4 | - scope:
5 | path: ""
6 | values:
7 | layout: "default"
8 | - scope:
9 | path: "index.md"
10 | values:
11 | layout: "homepage"
12 |
13 | plugins:
14 | - jekyll-relative-links
15 |
--------------------------------------------------------------------------------
/docs/_sass/utility/height.scss:
--------------------------------------------------------------------------------
1 | .h {
2 |
3 | &-full {
4 | height: 100%;
5 | }
6 |
7 | &-24 {
8 | height: 24px;
9 | }
10 |
11 | &-42 {
12 | height: 42px;
13 | }
14 |
15 | &-64 {
16 | height: 64px;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Moq.Tests.ComTypes/BuildDLLFromIDL.cmd:
--------------------------------------------------------------------------------
1 | midl /mktyplib203 /env win32 /tlb ComTypes.tlb ComTypes.idl
2 | tlbimp ComTypes.tlb /out:Moq.Tests.ComTypes.dll /namespace:Moq.Tests.ComTypes /keyfile:..\..\Moq.snk /asmversion:4.0.0.0
3 | peverify Moq.Tests.ComTypes.dll
4 | del ComTypes.tlb
5 |
--------------------------------------------------------------------------------
/docs/_layouts/default.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {% include head.html %}
4 |
5 | {% include header.html %}
6 |
7 | {{ content }}
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/docs/_layouts/homepage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {% include head.html %}
4 |
5 | {% include header.html %}
6 |
7 | {{ content }}
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/docs/_sass/utility/flex.scss:
--------------------------------------------------------------------------------
1 | .flex {
2 | display: flex;
3 |
4 | &-grow {
5 | flex-grow: 1;
6 | }
7 | }
8 |
9 | .items {
10 |
11 | &-center {
12 | align-items: center;
13 | }
14 | }
15 |
16 | .justify {
17 |
18 | &-stretch {
19 | justify-content: stretch;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/docs/_sass/utility/space-between.scss:
--------------------------------------------------------------------------------
1 | .space-x {
2 |
3 | &-4 > * + * {
4 | margin-left: 4px;
5 | }
6 |
7 | &-8 > * + * {
8 | margin-left: 8px;
9 | }
10 |
11 | &-12 > * + * {
12 | margin-left: 12px;
13 | }
14 |
15 | &-16 > * + * {
16 | margin-left: 16px;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/IHasProperty.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type IHasProperty =
9 | abstract member Property: obj with get, set
10 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/IHasIndexer.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type IHasIndexer =
9 | abstract member Item: int -> obj with get, set
10 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/IHasActionEvent.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type IHasActionEvent =
9 | []
10 | abstract member Event: IDelegateEvent
11 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasAbstractIndexer.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | []
9 | type HasAbstractIndexer() =
10 | abstract Item: int -> obj with get, set
11 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasAbstractProperty.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | []
9 | type HasAbstractProperty() =
10 | abstract Property: obj with get, set
11 |
--------------------------------------------------------------------------------
/.github/workflows/changelog.config:
--------------------------------------------------------------------------------
1 | usernames-as-github-logins=true
2 | issues_wo_labels=true
3 | pr_wo_labels=true
4 | exclude-labels=bydesign,dependencies,duplicate,discussion,question,invalid,wontfix,need info,docs
5 | enhancement-label=:sparkles: Implemented enhancements:
6 | bugs-label=:bug: Fixed bugs:
7 | issues-label=:hammer: Other:
8 | pr-label=:twisted_rightwards_arrows: Merged:
9 | unreleased=false
10 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/IHasEventHandlerEvent.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type IHasEventHandlerEvent =
9 | []
10 | abstract member Event: IEvent
11 |
--------------------------------------------------------------------------------
/src/Moq/Behavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq
5 | {
6 | abstract class Behavior
7 | {
8 | protected Behavior()
9 | {
10 | }
11 |
12 | public abstract void Execute(Invocation invocation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasAbstractActionEvent.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | []
9 | type HasAbstractActionEvent =
10 | []
11 | abstract member Event: IDelegateEvent
12 |
--------------------------------------------------------------------------------
/docs/_sass/reset.scss:
--------------------------------------------------------------------------------
1 | *,
2 | *::before,
3 | *::after {
4 | box-sizing: border-box;
5 | }
6 |
7 | footer,
8 | header,
9 | main {
10 | display: block;
11 | }
12 |
13 | blockquote,
14 | body,
15 | figure,
16 | h1,
17 | h2,
18 | h3,
19 | h4,
20 | img,
21 | p,
22 | pre {
23 | margin: 0;
24 | padding: 0;
25 | }
26 |
27 | :root,
28 | body {
29 | min-height: 100%;
30 | }
31 |
32 | img {
33 | display: inline-block;
34 | }
35 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasActionEvent.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type HasActionEvent() =
9 | let event = new DelegateEvent();
10 |
11 | []
12 | member this.Event = event.Publish
13 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasAbstractEventHandlerEvent.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | []
9 | type HasAbstractEventHandlerEvent =
10 | []
11 | abstract member Event: IEvent
12 |
--------------------------------------------------------------------------------
/src/Moq/IMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq
7 | {
8 | interface IMatcher
9 | {
10 | bool Matches(object argument, Type parameterType);
11 |
12 | void SetupEvaluatedSuccessfully(object argument, Type parameterType);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/assets/css/style.scss:
--------------------------------------------------------------------------------
1 | ---
2 | ---
3 |
4 | @import "jekyll-theme-slate";
5 |
6 | .inner {
7 | max-width: 960px;
8 | }
9 |
10 | pre, code {
11 | background-color: unset;
12 | font-size: unset;
13 | }
14 |
15 | code {
16 | font-size: 0.80em;
17 | }
18 |
19 | h1 > img {
20 | border: unset;
21 | box-shadow: unset;
22 | vertical-align: middle;
23 | -moz-box-shadow: unset;
24 | -o-box-shadow: unset;
25 | -ms-box-shadow: unset;
26 | }
27 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasProperty.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type HasProperty() =
9 | let mutable property = new obj()
10 | abstract Property: obj with get, set
11 | default this.Property with get() = property and set(value: obj) = property <- value
12 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/HasIndexer.fs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.FSharpTypes
5 |
6 | open System;
7 |
8 | type HasIndexer() =
9 | let mutable item = new obj()
10 | abstract Item: int -> obj with get, set
11 | default this.Item with get(index: int) = item and set (index: int) (value: obj) = item <- value
12 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/NoOp.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Behaviors
5 | {
6 | sealed class NoOp : Behavior
7 | {
8 | public static readonly NoOp Instance = new NoOp();
9 |
10 | NoOp()
11 | {
12 | }
13 |
14 | public override void Execute(Invocation invocation)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/ICallBaseResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | ///
9 | /// Implements the fluent API.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface ICallBaseResult : IThrows, IThrowsResult, IFluentInterface
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/IThrowsResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | ///
9 | /// Implements the fluent API.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface IThrowsResult : IOccurrence, IVerifies, IFluentInterface
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Moq/MockExceptionReasons.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq
7 | {
8 | [Flags]
9 | enum MockExceptionReasons
10 | {
11 | IncorrectNumberOfCalls = 1,
12 | NoMatchingCalls = 4,
13 | NoSetup = 8,
14 | ReturnValueRequired = 16,
15 | UnmatchedSetup = 32,
16 | UnverifiedInvocations = 64,
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | obj
3 | artifacts
4 | pack
5 | TestResults
6 | results
7 | BenchmarkDotNet.Artifacts
8 | /app
9 | .vs
10 | .vscode
11 | .genaiscript
12 | .idea
13 | local.settings.json
14 |
15 | *.suo
16 | *.sdf
17 | *.userprefs
18 | *.user
19 | *.nupkg
20 | *.metaproj
21 | *.tmp
22 | *.log
23 | *.cache
24 | *.binlog
25 | *.zip
26 | __azurite*.*
27 | __*__
28 |
29 | .nuget
30 | *.lock.json
31 | *.nuget.props
32 | *.nuget.targets
33 |
34 | node_modules
35 | _site
36 | .jekyll-metadata
37 | .jekyll-cache
38 | .sass-cache
39 | Gemfile.lock
40 | package-lock.json
41 |
--------------------------------------------------------------------------------
/src/Moq/ISetupList.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.Collections.Generic;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// A list of setups that have been configured on a mock,
10 | /// in chronological order (that is, oldest setup first, most recent setup last).
11 | ///
12 | public interface ISetupList : IReadOnlyList
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet-file.yml:
--------------------------------------------------------------------------------
1 | # Synchronizes .netconfig-configured files with dotnet-file
2 | name: dotnet-file
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: "0 0 * * *"
7 | push:
8 | branches: [ 'dotnet-file' ]
9 |
10 | env:
11 | DOTNET_NOLOGO: true
12 |
13 | jobs:
14 | run:
15 | permissions:
16 | contents: write
17 | uses: devlooped/oss/.github/workflows/dotnet-file-core.yml@main
18 | secrets:
19 | BOT_NAME: ${{ secrets.BOT_NAME }}
20 | BOT_EMAIL: ${{ secrets.BOT_EMAIL }}
21 | GH_TOKEN: ${{ secrets.GH_TOKEN }}
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/IReturnsResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | ///
9 | /// Implements the fluent API.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface IReturnsResult : ICallback, IOccurrence, IRaise, IVerifies, IFluentInterface
13 | {
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/ICallbackResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | ///
9 | /// Implements the fluent API.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface ICallbackResult : ICallBase, ICallBaseResult, IThrows, IThrowsResult, IFluentInterface
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Moq/Interception/IInterceptor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq
5 | {
6 | ///
7 | /// This role interface represents a 's ability to intercept method invocations for its .
8 | /// It is meant for use by .
9 | ///
10 | interface IInterceptor
11 | {
12 | void Intercept(Invocation invocation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Moq.Tests/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests
5 | {
6 | public static class StringExtensions
7 | {
8 | public static bool ContainsConsecutiveLines(this string str, params string[] lines)
9 | {
10 | var haystack = str.Replace("\r\n", "\n");
11 | var needle = string.Join("\n", lines);
12 | return haystack.Contains(needle);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/ReturnBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Behaviors
5 | {
6 | sealed class ReturnBase : Behavior
7 | {
8 | public static readonly ReturnBase Instance = new ReturnBase();
9 |
10 | ReturnBase()
11 | {
12 | }
13 |
14 | public override void Execute(Invocation invocation)
15 | {
16 | invocation.ReturnValue = invocation.CallBase();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Moq/IInvocationList.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.Collections.Generic;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// A list of invocations which have been performed on a mock.
10 | ///
11 | public interface IInvocationList : IReadOnlyList
12 | {
13 | ///
14 | /// Resets all invocations recorded for this mock.
15 | ///
16 | void Clear();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Moq.Tests/ReflectionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.Collections.Generic;
5 | using System.Reflection;
6 |
7 | namespace Moq.Tests
8 | {
9 | public static class ReflectionExtensions
10 | {
11 | public static IEnumerable GetAccessors(this EventInfo @event, bool nonPublic = false)
12 | {
13 | yield return @event.GetAddMethod(nonPublic);
14 | yield return @event.GetRemoveMethod(nonPublic);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/ReturnValue.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Behaviors
5 | {
6 | sealed class ReturnValue : Behavior
7 | {
8 | readonly object value;
9 |
10 | public ReturnValue(object value)
11 | {
12 | this.value = value;
13 | }
14 |
15 | public object Value => this.value;
16 |
17 | public override void Execute(Invocation invocation)
18 | {
19 | invocation.ReturnValue = this.value;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Moq/Language/ICallBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | using Moq.Language.Flow;
7 |
8 | namespace Moq.Language
9 | {
10 | ///
11 | /// Defines the CallBase verb.
12 | ///
13 | [EditorBrowsable(EditorBrowsableState.Never)]
14 | public interface ICallBase : IFluentInterface
15 | {
16 | ///
17 | /// Calls the real method of the object.
18 | ///
19 | ICallBaseResult CallBase();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/docs/_includes/head.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{ page.title }}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/SetterSetupPhrase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | class SetterSetupPhrase : VoidSetupPhrase, ISetupSetter where T : class
9 | {
10 | public SetterSetupPhrase(MethodCall setup) : base(setup)
11 | {
12 | }
13 |
14 | public ICallbackResult Callback(Action callback)
15 | {
16 | this.Setup.SetCallbackBehavior(callback);
17 | return this;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Moq/Condition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq
7 | {
8 | sealed class Condition
9 | {
10 | Func condition;
11 | Action success;
12 |
13 | public Condition(Func condition, Action success = null)
14 | {
15 | this.condition = condition;
16 | this.success = success;
17 | }
18 |
19 | public bool IsTrue => this.condition?.Invoke() == true;
20 |
21 | public void SetupEvaluatedSuccessfully() => this.success?.Invoke();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/docs/_includes/header.html:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/ThrowException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Behaviors
8 | {
9 | sealed class ThrowException : Behavior
10 | {
11 | readonly Exception exception;
12 |
13 | public ThrowException(Exception exception)
14 | {
15 | Debug.Assert(exception != null);
16 |
17 | this.exception = exception;
18 | }
19 |
20 | public override void Execute(Invocation invocation)
21 | {
22 | throw this.exception;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/.github/release.yml:
--------------------------------------------------------------------------------
1 | changelog:
2 | exclude:
3 | labels:
4 | - bydesign
5 | - dependencies
6 | - duplicate
7 | - question
8 | - invalid
9 | - wontfix
10 | - need info
11 | - techdebt
12 | authors:
13 | - devlooped-bot
14 | - dependabot
15 | - github-actions
16 | categories:
17 | - title: ✨ Implemented enhancements
18 | labels:
19 | - enhancement
20 | - title: 🐛 Fixed bugs
21 | labels:
22 | - bug
23 | - title: 📝 Documentation updates
24 | labels:
25 | - docs
26 | - documentation
27 | - title: 🔨 Other
28 | labels:
29 | - '*'
30 | exclude:
31 | labels:
32 | - dependencies
33 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/Callback.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Behaviors
8 | {
9 | sealed class Callback : Behavior
10 | {
11 | readonly Action callback;
12 |
13 | public Callback(Action callback)
14 | {
15 | Debug.Assert(callback != null);
16 |
17 | this.callback = callback;
18 | }
19 |
20 | public override void Execute(Invocation invocation)
21 | {
22 | this.callback.Invoke(invocation);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Moq/Range.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq
5 | {
6 | ///
7 | /// Kind of range to use in a filter specified through
8 | /// .
9 | ///
10 | public enum Range
11 | {
12 | ///
13 | /// The range includes the to and
14 | /// from values.
15 | ///
16 | Inclusive,
17 |
18 | ///
19 | /// The range does not include the to and
20 | /// from values.
21 | ///
22 | Exclusive
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Moq.Tests/Async/AwaitableFixture.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq.Tests.Async
5 | {
6 | using System.Threading.Tasks;
7 |
8 | using Moq.Async;
9 |
10 | using Xunit;
11 |
12 | public class AwaitableFixture
13 | {
14 | [Fact]
15 | public void TryGetResultRecursive_is_recursive()
16 | {
17 | const int expectedResult = 42;
18 | var obj = Task.FromResult(Task.FromResult(expectedResult));
19 | var result = Awaitable.TryGetResultRecursive(obj);
20 | Assert.Equal(expectedResult, result);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Moq/Matchers/AnyMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Matchers
8 | {
9 | sealed class AnyMatcher : IMatcher
10 | {
11 | public static AnyMatcher Instance { get; } = new AnyMatcher();
12 |
13 | AnyMatcher()
14 | {
15 | }
16 |
17 | public bool Matches(object argument, Type parameterType) => true;
18 |
19 | public void SetupEvaluatedSuccessfully(object argument, Type parameterType)
20 | {
21 | Debug.Assert(this.Matches(argument, parameterType));
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Moq/MethodSetup.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.Linq.Expressions;
5 | using System.Reflection;
6 |
7 | namespace Moq
8 | {
9 | ///
10 | /// Abstract base class for setups that target a single, specific method.
11 | ///
12 | abstract class MethodSetup : Setup
13 | {
14 | protected MethodSetup(Expression originalExpression, Mock mock, MethodExpectation expectation)
15 | : base(originalExpression, mock, expectation)
16 | {
17 | }
18 |
19 | public MethodInfo Method => ((MethodExpectation)this.Expectation).Method;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Moq/Interception/IProxy.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Internals
7 | {
8 | /// Do not use. (Moq requires this interface so that methods can be set up on interface mocks.)
9 | // NOTE: This type is actually specific to our DynamicProxy implementation of `ProxyFactory`.
10 | // It is directly related to `InterfaceProxy`, see the comment there.
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface IProxy
13 | {
14 | ///
15 | object Interceptor { get; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Moq/Obsolete/MockExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.ComponentModel;
6 |
7 | namespace Moq
8 | {
9 | static partial class MockExtensions
10 | {
11 | ///
12 | /// Resets all invocations recorded for this mock.
13 | ///
14 | /// The mock whose recorded invocations should be reset.
15 | [Obsolete("Use `mock.Invocations.Clear()` instead.")]
16 | [EditorBrowsable(EditorBrowsableState.Never)]
17 | public static void ResetCalls(this Mock mock) => mock.Invocations.Clear();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Moq/Async/IAwaitableFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq.Expressions;
7 |
8 | namespace Moq.Async
9 | {
10 | interface IAwaitableFactory
11 | {
12 | Type ResultType { get; }
13 |
14 | object CreateCompleted(object result = null);
15 |
16 | object CreateFaulted(Exception exception);
17 |
18 | object CreateFaulted(IEnumerable exceptions);
19 |
20 | Expression CreateResultExpression(Expression awaitableExpression);
21 |
22 | bool TryGetResult(object awaitable, out object result);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Moq.Tests/RecordsFixture.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using Xunit;
5 |
6 | namespace Moq.Tests
7 | {
8 | public class RecordsFixture
9 | {
10 | [Fact]
11 | public void Can_mock_EmptyRecord()
12 | {
13 | _ = new Mock().Object;
14 | }
15 |
16 | [Fact]
17 | public void Can_mock_DerivedEmptyRecord()
18 | {
19 | _ = new Mock().Object;
20 | }
21 |
22 | public record EmptyRecord
23 | {
24 | }
25 |
26 | public record DerivedEmptyRecord : EmptyRecord
27 | {
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/ReturnComputedValue.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Behaviors
8 | {
9 | sealed class ReturnComputedValue : Behavior
10 | {
11 | readonly Func valueFactory;
12 |
13 | public ReturnComputedValue(Func valueFactory)
14 | {
15 | Debug.Assert(valueFactory != null);
16 |
17 | this.valueFactory = valueFactory;
18 | }
19 |
20 | public override void Execute(Invocation invocation)
21 | {
22 | invocation.ReturnValue = this.valueFactory.Invoke(invocation);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Moq/Behaviors/ThrowComputedException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Behaviors
8 | {
9 | sealed class ThrowComputedException : Behavior
10 | {
11 | readonly Func exceptionFactory;
12 |
13 | public ThrowComputedException(Func exceptionFactory)
14 | {
15 | Debug.Assert(exceptionFactory != null);
16 |
17 | this.exceptionFactory = exceptionFactory;
18 | }
19 |
20 | public override void Execute(Invocation invocation)
21 | {
22 | throw this.exceptionFactory.Invoke(invocation);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Moq/Interception/ProxyFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Reflection;
6 |
7 | namespace Moq
8 | {
9 | abstract class ProxyFactory
10 | {
11 | ///
12 | /// Gets the global instance used by Moq.
13 | ///
14 | public static ProxyFactory Instance { get; } = new CastleProxyFactory();
15 |
16 | public abstract object CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, object[] arguments);
17 |
18 | public abstract bool IsMethodVisible(MethodInfo method, out string messageIfNotVisible);
19 |
20 | public abstract bool IsTypeVisible(Type type);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Moq/DefaultExpressionCompiler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Linq.Expressions;
6 |
7 | namespace Moq
8 | {
9 | sealed class DefaultExpressionCompiler : ExpressionCompiler
10 | {
11 | new public static readonly DefaultExpressionCompiler Instance = new DefaultExpressionCompiler();
12 |
13 | DefaultExpressionCompiler()
14 | {
15 | }
16 |
17 | public override Delegate Compile(LambdaExpression expression)
18 | {
19 | return expression.Compile();
20 | }
21 |
22 | public override TDelegate Compile(Expression expression)
23 | {
24 | return expression.Compile();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Moq.Tests/HidePropertyFixture.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using Xunit;
5 |
6 | namespace Moq.Tests
7 | {
8 | public class HidePropertyFixture
9 | {
10 | public class A
11 | {
12 | public string Prop { get; }
13 | }
14 |
15 | public class B : A
16 | {
17 | public new virtual int Prop { get; }
18 | }
19 |
20 | public class C : B
21 | {
22 | }
23 |
24 | [Fact]
25 | public void SetupsDerivedProperty()
26 | {
27 | var mock = new Mock();
28 | var value = 5;
29 |
30 | mock.Setup(m => m.Prop).Returns(value);
31 |
32 | Assert.Equal(value, mock.Object.Prop);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/IReturnsThrows.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq.Language.Flow
7 | {
8 | ///
9 | /// Implements the fluent API.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface IReturnsThrows : IReturns, IThrows, IFluentInterface
13 | where TMock : class
14 | {
15 | }
16 |
17 | ///
18 | /// Implements the fluent API.
19 | ///
20 | [EditorBrowsable(EditorBrowsableState.Never)]
21 | public interface IReturnsThrowsGetter : IReturnsGetter, IThrows, IFluentInterface
22 | where TMock : class
23 | {
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Moq/Expressions/Visitors/Apply.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.Linq.Expressions;
5 |
6 | namespace Moq
7 | {
8 | static partial class ExpressionExtensions
9 | {
10 | ///
11 | /// Applies the specified to this expression tree.
12 | ///
13 | /// The to which should be applied.
14 | /// The that should be applied to .
15 | public static Expression Apply(this Expression expression, ExpressionVisitor visitor)
16 | {
17 | return visitor.Visit(expression);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Moq/Interception/Mock.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq
5 | {
6 | partial class Mock : IInterceptor
7 | {
8 | void IInterceptor.Intercept(Invocation invocation)
9 | {
10 | if (HandleWellKnownMethods.Handle(invocation, this))
11 | {
12 | return;
13 | }
14 |
15 | RecordInvocation.Handle(invocation, this);
16 |
17 | if (FindAndExecuteMatchingSetup.Handle(invocation, this))
18 | {
19 | return;
20 | }
21 |
22 | if (HandleEventSubscription.Handle(invocation, this))
23 | {
24 | return;
25 | }
26 |
27 | FailForStrictMock.Handle(invocation, this);
28 |
29 | Return.Handle(invocation, this);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Directory.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | annotations
5 | Moq
6 | Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors
7 | $(MSBuildThisFileDirectory)Moq.snk
8 | true
9 | 00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc
10 | 69f491c39445e920
11 |
12 | $(MSBuildThisFileDirectory)..\
13 | IDE0040;$(WarningsNotAsErrors)
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Moq.Tests/Regressions/StreamFixture.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.IO;
5 |
6 | using Xunit;
7 |
8 | namespace Moq.Tests
9 | {
10 | public class StreamFixture
11 | {
12 | [Fact]
13 | public void ShouldMockStream()
14 | {
15 | var mockStream = new Mock();
16 |
17 | mockStream.Setup(stream => stream.Seek(0, SeekOrigin.Begin)).Returns(0L);
18 |
19 | var position = mockStream.Object.Seek(0, SeekOrigin.Begin);
20 |
21 | Assert.Equal(0, position);
22 |
23 | mockStream.Setup(stream => stream.Flush());
24 | mockStream.Setup(stream => stream.SetLength(100));
25 |
26 | mockStream.Object.Flush();
27 | mockStream.Object.SetLength(100);
28 |
29 | mockStream.VerifyAll();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.github/actions/dotnet/action.yml:
--------------------------------------------------------------------------------
1 | name: ⚙ dotnet
2 | description: Configures dotnet if the repo/org defines the DOTNET custom property
3 |
4 | runs:
5 | using: composite
6 | steps:
7 | - name: 🔎 dotnet
8 | id: dotnet
9 | shell: bash
10 | run: |
11 | if [ -f .github/workflows/dotnet.json ]; then
12 | VERSIONS=$(jq -r '.[]' .github/workflows/dotnet.json)
13 | else
14 | VERSIONS=$(gh api repos/${{ github.repository }}/properties/values | jq -r '[.[] | select(.property_name == "DOTNET") | .value] | join(",") | split(",")[] | gsub("^\\s+|\\s+$"; "")')
15 | fi
16 | # Write multiline output to $GITHUB_OUTPUT
17 | {
18 | echo 'versions<> $GITHUB_OUTPUT
22 |
23 | - name: ⚙ dotnet
24 | if: steps.dotnet.outputs.versions != ''
25 | uses: actions/setup-dotnet@v4
26 | with:
27 | dotnet-version: |
28 | ${{ steps.dotnet.outputs.versions }}
29 |
--------------------------------------------------------------------------------
/src/Moq/Matchers/ExpressionMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 | using System.Linq.Expressions;
7 |
8 | namespace Moq.Matchers
9 | {
10 | class ExpressionMatcher : IMatcher
11 | {
12 | Expression expression;
13 |
14 | public ExpressionMatcher(Expression expression)
15 | {
16 | this.expression = expression;
17 | }
18 |
19 | public bool Matches(object argument, Type parameterType)
20 | {
21 | return argument is Expression valueExpression
22 | && ExpressionComparer.Default.Equals(this.expression, valueExpression);
23 | }
24 |
25 | public void SetupEvaluatedSuccessfully(object argument, Type parameterType)
26 | {
27 | Debug.Assert(this.Matches(argument, parameterType));
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Moq/MockBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | namespace Moq
5 | {
6 | ///
7 | /// Options to customize the behavior of the mock.
8 | ///
9 | public enum MockBehavior
10 | {
11 | ///
12 | /// Causes the mock to always throw
13 | /// an exception for invocations that don't have a
14 | /// corresponding setup.
15 | ///
16 | Strict,
17 | ///
18 | /// Will never throw exceptions, returning default
19 | /// values when necessary (null for reference types,
20 | /// zero for value types or empty enumerables and arrays).
21 | ///
22 | Loose,
23 | ///
24 | /// Default mock behavior, which equals .
25 | ///
26 | Default = Loose,
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Moq/MockExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// Provides additional methods on mocks.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public static partial class MockExtensions
13 | {
14 | ///
15 | /// Resets this mock's state. This includes its setups, configured default return values, registered event handlers, and all recorded invocations.
16 | ///
17 | /// The mock whose state should be reset.
18 | public static void Reset(this Mock mock)
19 | {
20 | mock.ConfiguredDefaultValues.Clear();
21 | mock.MutableSetups.Clear();
22 | mock.EventHandlers.Clear();
23 | mock.Invocations.Clear();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Moq/Matchers/LazyEvalMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 | using System.Linq.Expressions;
7 |
8 | namespace Moq.Matchers
9 | {
10 | class LazyEvalMatcher : IMatcher
11 | {
12 | Expression expression;
13 |
14 | public LazyEvalMatcher(Expression expression)
15 | {
16 | this.expression = expression;
17 | }
18 |
19 | public bool Matches(object argument, Type parameterType)
20 | {
21 | var eval = Evaluator.PartialEval(this.expression);
22 | return eval is ConstantExpression ce && new ConstantMatcher(ce.Value).Matches(argument, parameterType);
23 | }
24 |
25 | public void SetupEvaluatedSuccessfully(object argument, Type parameterType)
26 | {
27 | Debug.Assert(this.Matches(argument, parameterType));
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Moq.Tests.VisualBasic/Moq.Tests.VisualBasic.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;net8.0
5 | True
6 | portable
7 | False
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Moq/IMocked.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// Implemented by all generated mock object instances.
10 | ///
11 | [EditorBrowsable(EditorBrowsableState.Never)]
12 | public interface IMocked : IMocked
13 | where T : class
14 | {
15 | ///
16 | /// Reference the Mock that contains this as the mock.Object value.
17 | ///
18 | new Mock Mock { get; }
19 | }
20 |
21 | ///
22 | /// Implemented by all generated mock object instances.
23 | ///
24 | [EditorBrowsable(EditorBrowsableState.Never)]
25 | public interface IMocked
26 | {
27 | ///
28 | /// Reference the Mock that contains this as the mock.Object value.
29 | ///
30 | Mock Mock { get; }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Moq/Switches.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// Represents a switch, or a combination of switches, that can be either enabled or disabled.
10 | /// When set via or , they determine how a mock will operate.
11 | ///
12 | [Flags]
13 | public enum Switches
14 | {
15 | ///
16 | /// The default set of switches. The switches covered by this enumeration value may change between different versions of Moq.
17 | ///
18 | Default = 0,
19 |
20 | ///
21 | /// When enabled, specifies that source file information should be collected for each setup.
22 | /// This results in more helpful error messages, but may affect performance.
23 | ///
24 | CollectDiagnosticFileInfoForSetups = 1 << 0,
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Moq/Language/GenericTypeParameters.tt:
--------------------------------------------------------------------------------
1 | <#+
2 | private const int GenericTypeMax = 16;
3 | private const int GenericTypeMin = 5;
4 |
5 | private const string GenericTypeFormat = "T{0}";
6 | private const string GenericArgumentFormat = "T{0} arg{0}";
7 |
8 | private static readonly string[] ordinalNumbers = new[] { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth" };
9 | private static readonly string[] wordNumbers = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen" };
10 |
11 | public static string ConvertToWord(int number)
12 | {
13 | return wordNumbers[number - 1];
14 | }
15 |
16 | public static string ConvertToOrdinal(int number)
17 | {
18 | return ordinalNumbers[number - 1];
19 | }
20 |
21 | private static string GetGenericList(int typeCount, string format, string separator = ", ")
22 | {
23 | return string.Join(separator, Enumerable.Range(1, typeCount).Select(n => string.Format(format, n)).ToArray());
24 | }
25 | #>
--------------------------------------------------------------------------------
/src/Moq/Matchers/RefMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Diagnostics;
6 |
7 | namespace Moq.Matchers
8 | {
9 | class RefMatcher : IMatcher
10 | {
11 | readonly object reference;
12 | readonly bool referenceIsValueType;
13 |
14 | public RefMatcher(object reference)
15 | {
16 | this.reference = reference;
17 | this.referenceIsValueType = reference?.GetType().IsValueType ?? false;
18 | }
19 |
20 | public bool Matches(object argument, Type parameterType)
21 | {
22 | return this.referenceIsValueType ? object.Equals(this.reference, argument)
23 | : object.ReferenceEquals(this.reference, argument);
24 | }
25 |
26 | public void SetupEvaluatedSuccessfully(object value, Type parameterType)
27 | {
28 | Debug.Assert(this.Matches(value, parameterType));
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Please see the documentation for all configuration options:
2 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3 |
4 | version: 2
5 | updates:
6 | - package-ecosystem: nuget
7 | directory: /
8 | schedule:
9 | interval: daily
10 | groups:
11 | Azure:
12 | patterns:
13 | - "Azure*"
14 | - "Microsoft.Azure*"
15 | Identity:
16 | patterns:
17 | - "System.IdentityModel*"
18 | - "Microsoft.IdentityModel*"
19 | System:
20 | patterns:
21 | - "System*"
22 | exclude-patterns:
23 | - "System.IdentityModel*"
24 | Extensions:
25 | patterns:
26 | - "Microsoft.Extensions*"
27 | Web:
28 | patterns:
29 | - "Microsoft.AspNetCore*"
30 | Tests:
31 | patterns:
32 | - "Microsoft.NET.Test*"
33 | - "xunit*"
34 | - "coverlet*"
35 | ThisAssembly:
36 | patterns:
37 | - "ThisAssembly*"
38 | ProtoBuf:
39 | patterns:
40 | - "protobuf-*"
41 | Spectre:
42 | patterns:
43 | - "Spectre.Console*"
44 |
--------------------------------------------------------------------------------
/src/Moq/MatchExpression.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Linq.Expressions;
6 |
7 | namespace Moq
8 | {
9 | sealed class MatchExpression : Expression
10 | {
11 | public readonly Match Match;
12 |
13 | public MatchExpression(Match match)
14 | {
15 | this.Match = match;
16 | }
17 |
18 | public override ExpressionType NodeType => ExpressionType.Extension;
19 |
20 | public override Type Type => this.Match.RenderExpression.Type;
21 |
22 | // This node type is irreducible in order to prevent compilation.
23 | // The best possible reduction would involve `RenderExpression`,
24 | // which isn't intended to be used for that purpose.
25 | public override bool CanReduce => false;
26 |
27 | protected override Expression VisitChildren(ExpressionVisitor visitor) => this;
28 |
29 | public override string ToString() => this.Match.RenderExpression.ToString();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Moq/ITypeMatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 |
6 | namespace Moq
7 | {
8 | ///
9 | /// Types that implement this interface represent a criterion against which generic type arguments are matched.
10 | ///
11 | /// To be used in combination with .
12 | ///
13 | ///
14 | public interface ITypeMatcher
15 | {
16 | ///
17 | /// Matches the provided type argument against the criterion represented by this type matcher.
18 | ///
19 | ///
20 | /// The generic type argument that should be matched.
21 | ///
22 | ///
23 | /// if the provided type argument matched the criterion represented by this instance;
24 | /// otherwise, .
25 | ///
26 | bool Matches(Type typeArgument);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Moq/ParameterTypes.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 | using System.Reflection;
8 |
9 | namespace Moq
10 | {
11 | ///
12 | /// Allocation-free adapter type for treating a `ParameterInfo[]` array like a `Type[]` array.
13 | ///
14 | readonly struct ParameterTypes : IReadOnlyList
15 | {
16 | readonly ParameterInfo[] parameters;
17 |
18 | public ParameterTypes(ParameterInfo[] parameters)
19 | {
20 | this.parameters = parameters;
21 | }
22 |
23 | public Type this[int index] => this.parameters[index].ParameterType;
24 |
25 | public int Count => this.parameters.Length;
26 |
27 | public IEnumerator GetEnumerator()
28 | {
29 | for (int i = 0, n = this.Count; i < n; ++i)
30 | {
31 | yield return this[i];
32 | }
33 | }
34 |
35 | IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Moq/Async/ValueTaskFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
2 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Threading.Tasks;
7 |
8 | namespace Moq.Async
9 | {
10 | sealed class ValueTaskFactory : AwaitableFactory
11 | {
12 | public static readonly ValueTaskFactory Instance = new ValueTaskFactory();
13 |
14 | ValueTaskFactory()
15 | {
16 | }
17 |
18 | public override ValueTask CreateCompleted()
19 | {
20 | return default;
21 | }
22 |
23 | public override ValueTask CreateFaulted(Exception exception)
24 | {
25 | var tcs = new TaskCompletionSource