├── .github
├── FUNDING.yml
├── workflows
│ ├── changelog.config
│ ├── sponsor.yml
│ ├── publish.yml
│ ├── includes.yml
│ ├── changelog.yml
│ ├── test
│ │ └── action.yml
│ └── build.yml
├── release.yml
└── dependabot.yml
├── src
├── Moq.snk
├── Moq
│ ├── icon.png
│ ├── readme.md
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Language
│ │ ├── Flow
│ │ │ ├── ICallBaseResult.cs
│ │ │ ├── IThrowsResult.cs
│ │ │ ├── IReturnsResult.cs
│ │ │ ├── ICallbackResult.cs
│ │ │ ├── IReturnsThrows.cs
│ │ │ ├── ISetup.cs
│ │ │ └── SetterSetupPhrase.cs
│ │ ├── ICallBase.cs
│ │ ├── GenericTypeParameters.tt
│ │ ├── ICallbackSetter.cs
│ │ ├── ICallbackGetter.cs
│ │ ├── IRaise.tt
│ │ ├── ISetupSequentialResult.cs
│ │ ├── IReturns.tt
│ │ ├── ISetupConditionResult.cs
│ │ ├── IThrows.tt
│ │ ├── IRaise.cs
│ │ ├── IReturnsGetter.cs
│ │ └── ISetupSequentialAction.cs
│ ├── MockExceptionReasons.cs
│ ├── ISetupList.cs
│ ├── IInvocationList.cs
│ ├── Range.cs
│ ├── Interception
│ │ ├── IProxy.cs
│ │ ├── Mock.cs
│ │ ├── IInterceptor.cs
│ │ └── ProxyFactory.cs
│ ├── Obsolete
│ │ ├── MockExtensions.cs
│ │ ├── SequenceExtensions.cs
│ │ └── IOccurrence.cs
│ ├── Expressions
│ │ └── Visitors
│ │ │ ├── Apply.cs
│ │ │ └── EvaluateCaptures.cs
│ ├── Behavior.cs
│ ├── IMatcher.cs
│ ├── MockBehavior.cs
│ ├── MockExtensions.cs
│ ├── IMocked.cs
│ ├── Switches.cs
│ ├── ITypeMatcher.cs
│ ├── Protected
│ │ └── ProtectedExtension.cs
│ ├── InvocationFunc.cs
│ ├── InvocationAction.cs
│ ├── Async
│ │ ├── IAwaitableFactory.cs
│ │ ├── Awaitable.cs
│ │ ├── TaskFactory.cs
│ │ ├── ValueTaskFactory.cs
│ │ ├── TaskFactory`1.cs
│ │ ├── ValueTaskFactory`1.cs
│ │ └── AwaitableFactory`1.cs
│ ├── IMock.cs
│ ├── MethodSetup.cs
│ ├── IInvocation.cs
│ ├── Behaviors
│ │ ├── NoOp.cs
│ │ ├── ReturnBase.cs
│ │ ├── ReturnValue.cs
│ │ ├── ThrowException.cs
│ │ ├── Callback.cs
│ │ ├── ReturnComputedValue.cs
│ │ └── ThrowComputedException.cs
│ ├── MatchExpression.cs
│ ├── DefaultValue.cs
│ ├── Matchers
│ │ ├── AnyMatcher.cs
│ │ ├── ExpressionMatcher.cs
│ │ ├── LazyEvalMatcher.cs
│ │ └── RefMatcher.cs
│ ├── Pair.cs
│ ├── Condition.cs
│ ├── Expectation.cs
│ ├── DefaultExpressionCompiler.cs
│ ├── ParameterTypes.cs
│ ├── MockSequence.cs
│ ├── Linq
│ │ └── Mock.cs
│ ├── ExpressionReconstructor.cs
│ ├── TypeMatcherAttribute.cs
│ └── InnerMockSetup.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
│ ├── SetupsFixture.cs
│ ├── Matchers
│ │ ├── AnyMatcherFixture.cs
│ │ └── ParamArrayMatcherFixture.cs
│ ├── StringBuilderExtensionsFixture.cs
│ ├── EventHandlerTypesMustMatchFixture.cs
│ ├── SequentialActionExtensionsFixture.cs
│ ├── Moq.Tests.csproj
│ ├── ProxyFactories
│ │ └── MostSpecificOverrideFixture.cs
│ ├── OccurrenceFixture.cs
│ └── MockedFixture.cs
├── Moq.Tests.VisualBasic
│ └── Moq.Tests.VisualBasic.vbproj
└── Directory.props
├── 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
├── .gitignore
├── .gitattributes
└── License.txt
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: devlooped
2 |
--------------------------------------------------------------------------------
/src/Moq.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/HEAD/src/Moq.snk
--------------------------------------------------------------------------------
/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/ImoutoChan/openmoq/HEAD/src/Moq/icon.png
--------------------------------------------------------------------------------
/assets/img/moq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/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/ImoutoChan/openmoq/HEAD/assets/img/moq-icon.png
--------------------------------------------------------------------------------
/assets/img/moq-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/HEAD/assets/img/moq-small.png
--------------------------------------------------------------------------------
/assets/img/moq-bigger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/HEAD/assets/img/moq-bigger.png
--------------------------------------------------------------------------------
/docs/assets/images/github-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/HEAD/docs/assets/images/github-32.png
--------------------------------------------------------------------------------
/docs/assets/images/moq-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImoutoChan/openmoq/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/ImoutoChan/openmoq/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
--------------------------------------------------------------------------------
/src/Moq/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.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,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/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 |
--------------------------------------------------------------------------------
/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.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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | app
3 | obj
4 | artifacts
5 | pack
6 | TestResults
7 | .vs
8 | .vscode
9 | .idea
10 |
11 | *.suo
12 | *.sdf
13 | *.userprefs
14 | *.user
15 | *.nupkg
16 | *.metaproj
17 | *.tmp
18 | *.log
19 | *.cache
20 | *.binlog
21 | *.zip
22 | __azurite*.*
23 | __*__
24 |
25 | .nuget
26 | *.lock.json
27 | *.nuget.props
28 | *.nuget.targets
29 |
30 | node_modules
31 | _site
32 | .jekyll-metadata
33 | .jekyll-cache
34 | Gemfile.lock
35 | package-lock.json
36 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.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/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/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 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # sln, csproj files (and friends) are always CRLF, even on linux
2 | *.sln text eol=crlf
3 | *.proj text eol=crlf
4 | *.csproj text eol=crlf
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 |
11 | # Opt in known filetypes to always normalize line endings on checkin
12 | # and always use native endings on checkout
13 | *.c text
14 | *.config text
15 | *.h text
16 | *.cs text
17 | *.md text
18 | *.tt text
19 | *.txt text
20 |
21 | # Some must always be checked out as lf so enforce that for those files
22 | # If these are not lf then bash/cygwin on windows will not be able to
23 | # excute the files
24 | *.sh text eol=lf
--------------------------------------------------------------------------------
/docs/_includes/header.html:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/.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 | - docs
12 | - techdebt
13 | authors:
14 | - devlooped-bot
15 | - dependabot
16 | - github-actions
17 | categories:
18 | - title: ✨ Implemented enhancements
19 | labels:
20 | - enhancement
21 | - title: 🐛 Fixed bugs
22 | labels:
23 | - bug
24 | - title: 📝 Documentation updates
25 | labels:
26 | - docs
27 | - title: 🔨 Other
28 | labels:
29 | - '*'
30 | exclude:
31 | labels:
32 | - dependencies
33 |
--------------------------------------------------------------------------------
/.github/workflows/sponsor.yml:
--------------------------------------------------------------------------------
1 | name: sponsor 💜
2 | on:
3 | issues:
4 | types: [opened, edited, reopened]
5 | pull_request:
6 | types: [opened, edited, synchronize, reopened]
7 |
8 | jobs:
9 | sponsor:
10 | runs-on: ubuntu-latest
11 | continue-on-error: true
12 | env:
13 | token: ${{ secrets.GH_TOKEN }}
14 | if: ${{ !endsWith(github.event.sender.login, '[bot]') && !endsWith(github.event.sender.login, 'bot') }}
15 | steps:
16 | - name: 🤘 checkout
17 | if: env.token != ''
18 | uses: actions/checkout@v2
19 |
20 | - name: 💜 sponsor
21 | if: env.token != ''
22 | uses: devlooped/actions-sponsor@main
23 | with:
24 | token: ${{ env.token }}
25 |
--------------------------------------------------------------------------------
/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/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.Tests.VisualBasic/Moq.Tests.VisualBasic.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;net6.0
5 | True
6 | portable
7 | False
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.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 | System:
16 | patterns:
17 | - "System*"
18 | Extensions:
19 | patterns:
20 | - "Microsoft.Extensions*"
21 | Web:
22 | patterns:
23 | - "Microsoft.AspNetCore*"
24 | Tests:
25 | patterns:
26 | - "Microsoft.NET.Tests*"
27 | - "xunit*"
28 | - "coverlet*"
29 | ThisAssembly:
30 | patterns:
31 | - "ThisAssembly*"
32 | ProtoBuf:
33 | patterns:
34 | - "protobuf-*"
35 |
--------------------------------------------------------------------------------
/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/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 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/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/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 |
7 | /* Unmerged change from project 'Moq(netstandard2.0)'
8 | Before:
9 | internal abstract class Behavior
10 | After:
11 | abstract class Behavior
12 | */
13 |
14 | /* Unmerged change from project 'Moq(netstandard2.1)'
15 | Before:
16 | internal abstract class Behavior
17 | After:
18 | abstract class Behavior
19 | */
20 |
21 | /* Unmerged change from project 'Moq(net6.0)'
22 | Before:
23 | internal abstract class Behavior
24 | After:
25 | abstract class Behavior
26 | */
27 | abstract class Behavior
28 | {
29 | protected Behavior()
30 | {
31 | }
32 |
33 | public abstract void Execute(Invocation invocation);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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 |
9 | /* Unmerged change from project 'Moq(netstandard2.0)'
10 | Before:
11 | internal interface IMatcher
12 | After:
13 | interface IMatcher
14 | */
15 |
16 | /* Unmerged change from project 'Moq(netstandard2.1)'
17 | Before:
18 | internal interface IMatcher
19 | After:
20 | interface IMatcher
21 | */
22 |
23 | /* Unmerged change from project 'Moq(net6.0)'
24 | Before:
25 | internal interface IMatcher
26 | After:
27 | interface IMatcher
28 | */
29 | interface IMatcher
30 | {
31 | bool Matches(object argument, Type parameterType);
32 |
33 | void SetupEvaluatedSuccessfully(object argument, Type parameterType);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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/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/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | # Builds a final release version and pushes to nuget.org
2 | # whenever a release is published.
3 | # Requires: secrets.NUGET_API_KEY
4 |
5 | name: publish
6 | on:
7 | release:
8 | types: [released]
9 |
10 | env:
11 | DOTNET_NOLOGO: true
12 | Configuration: Release
13 |
14 | defaults:
15 | run:
16 | shell: bash
17 |
18 | jobs:
19 | publish:
20 | runs-on: windows-latest
21 | steps:
22 | - name: 🤘 checkout
23 | uses: actions/checkout@v2
24 | with:
25 | submodules: recursive
26 | fetch-depth: 0
27 |
28 | - name: 🙏 build
29 | run: dotnet build -m:1 -p:version=${GITHUB_REF#refs/*/v}
30 |
31 | - name: 🧪 test
32 | uses: ./.github/workflows/test
33 |
34 | - name: 📦 pack
35 | run: dotnet pack -m:1 -p:version=${GITHUB_REF#refs/*/v}
36 |
37 | - name: 🚀 nuget
38 | run: dotnet nuget push bin/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}} --skip-duplicate
39 |
--------------------------------------------------------------------------------
/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/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/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 | /* Unmerged change from project 'Moq(netstandard2.0)'
8 | Before:
9 | internal interface IInterceptor
10 | After:
11 | interface IInterceptor
12 | */
13 |
14 | /* Unmerged change from project 'Moq(netstandard2.1)'
15 | Before:
16 | internal interface IInterceptor
17 | After:
18 | interface IInterceptor
19 | */
20 |
21 | /* Unmerged change from project 'Moq(net6.0)'
22 | Before:
23 | internal interface IInterceptor
24 | After:
25 | interface IInterceptor
26 | */
27 | ///
28 | /// This role interface represents a 's ability to intercept method invocations for its .
29 | /// It is meant for use by .
30 | ///
31 | interface IInterceptor
32 | {
33 | void Intercept(Invocation invocation);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.github/workflows/includes.yml:
--------------------------------------------------------------------------------
1 | name: +Mᐁ includes
2 | on:
3 | workflow_dispatch:
4 | push:
5 | branches:
6 | - 'main'
7 | paths:
8 | - '**.md'
9 | - '!changelog.md'
10 |
11 | jobs:
12 | includes:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: 🤖 defaults
16 | uses: devlooped/actions-bot@v1
17 | with:
18 | name: ${{ secrets.BOT_NAME }}
19 | email: ${{ secrets.BOT_EMAIL }}
20 | gh_token: ${{ secrets.GH_TOKEN }}
21 | github_token: ${{ secrets.GITHUB_TOKEN }}
22 |
23 | - name: 🤘 checkout
24 | uses: actions/checkout@v2
25 | with:
26 | token: ${{ env.GH_TOKEN }}
27 |
28 | - name: +Mᐁ includes
29 | uses: devlooped/actions-includes@v1
30 |
31 | - name: ✍ pull request
32 | uses: peter-evans/create-pull-request@v4
33 | with:
34 | base: main
35 | branch: markdown-includes
36 | delete-branch: true
37 | labels: docs
38 | author: ${{ env.BOT_AUTHOR }}
39 | committer: ${{ env.BOT_AUTHOR }}
40 | commit-message: +Mᐁ includes
41 | title: +Mᐁ includes
42 | body: +Mᐁ includes
43 | token: ${{ env.GH_TOKEN }}
44 |
--------------------------------------------------------------------------------
/.github/workflows/changelog.yml:
--------------------------------------------------------------------------------
1 | name: changelog
2 | on:
3 | workflow_dispatch:
4 | release:
5 | types: [released]
6 |
7 | jobs:
8 | changelog:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: 🤖 defaults
12 | uses: devlooped/actions-bot@v1
13 | with:
14 | name: ${{ secrets.BOT_NAME }}
15 | email: ${{ secrets.BOT_EMAIL }}
16 | gh_token: ${{ secrets.GH_TOKEN }}
17 | github_token: ${{ secrets.GITHUB_TOKEN }}
18 |
19 | - name: 🤘 checkout
20 | uses: actions/checkout@v2
21 | with:
22 | fetch-depth: 0
23 | ref: main
24 | token: ${{ env.GH_TOKEN }}
25 |
26 | - name: ⚙ ruby
27 | uses: ruby/setup-ruby@v1
28 | with:
29 | ruby-version: 3.0.3
30 |
31 | - name: ⚙ changelog
32 | run: |
33 | gem install github_changelog_generator
34 | github_changelog_generator --user ${GITHUB_REPOSITORY%/*} --project ${GITHUB_REPOSITORY##*/} --token $GH_TOKEN --o changelog.md --config-file .github/workflows/changelog.config
35 |
36 | - name: 🚀 changelog
37 | run: |
38 | git add changelog.md
39 | (git commit -m "🖉 Update changelog with ${GITHUB_REF#refs/*/}" && git push) || echo "Done"
--------------------------------------------------------------------------------
/src/Moq/Protected/ProtectedExtension.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.Protected
7 | {
8 | ///
9 | /// Enables the Protected() method on ,
10 | /// allowing setups to be set for protected members by using their
11 | /// name as a string, rather than strong-typing them which is not possible
12 | /// due to their visibility.
13 | ///
14 | [EditorBrowsable(EditorBrowsableState.Never)]
15 | public static class ProtectedExtension
16 | {
17 | ///
18 | /// Enable protected setups for the mock.
19 | ///
20 | /// Mocked object type. Typically omitted as it can be inferred from the mock instance.
21 | /// The mock to set the protected setups on.
22 | public static IProtectedMock Protected(this Mock mock)
23 | where T : class
24 | {
25 | Guard.NotNull(mock, nameof(mock));
26 |
27 | return new ProtectedMock(mock);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Moq/Language/ICallbackSetter.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 | using Moq.Language.Flow;
8 |
9 | namespace Moq.Language
10 | {
11 | ///
12 | /// Defines the Callback verb for property setter setups.
13 | ///
14 | /// Type of the property.
15 | [EditorBrowsable(EditorBrowsableState.Never)]
16 | public interface ICallbackSetter : IFluentInterface
17 | {
18 | ///
19 | /// Specifies a callback to invoke when the property is set that receives the
20 | /// property value being set.
21 | ///
22 | /// Callback method to invoke.
23 | ///
24 | /// Invokes the given callback with the property value being set.
25 | ///
26 | /// mock.SetupSet(x => x.Suspended)
27 | /// .Callback((bool state) => Console.WriteLine(state));
28 | ///
29 | ///
30 | ICallbackResult Callback(Action action);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Moq/InvocationFunc.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 | /// A delegate-like type for use with `setup.Returns` which instructs the `Returns` verb
10 | /// to provide the callback with the current , instead of
11 | /// with a list of arguments.
12 | ///
13 | /// This type is useful in scenarios involving generic type argument matchers (such as
14 | /// ) as allows the discovery of both
15 | /// arguments and type arguments.
16 | ///
17 | ///
18 | public readonly struct InvocationFunc
19 | {
20 | internal readonly Func Func;
21 |
22 | ///
23 | /// Initializes a new instance of the type.
24 | ///
25 | /// The delegate that should be wrapped by this instance.
26 | public InvocationFunc(Func func)
27 | {
28 | this.Func = func;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Moq/InvocationAction.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 | /// A delegate-like type for use with `setup.Callback` which instructs the `Callback` verb
10 | /// to provide the callback with the current , instead of
11 | /// with a list of arguments.
12 | ///
13 | /// This type is useful in scenarios involving generic type argument matchers (such as
14 | /// ) as allows the discovery of both
15 | /// arguments and type arguments.
16 | ///
17 | ///
18 | public readonly struct InvocationAction
19 | {
20 | internal readonly Action Action;
21 |
22 | ///
23 | /// Initializes a new instance of the type.
24 | ///
25 | /// The delegate that should be wrapped by this instance.
26 | public InvocationAction(Action action)
27 | {
28 | this.Action = action;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/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 |
11 | /* Unmerged change from project 'Moq(netstandard2.0)'
12 | Before:
13 | internal interface IAwaitableFactory
14 | After:
15 | interface IAwaitableFactory
16 | */
17 |
18 | /* Unmerged change from project 'Moq(netstandard2.1)'
19 | Before:
20 | internal interface IAwaitableFactory
21 | After:
22 | interface IAwaitableFactory
23 | */
24 |
25 | /* Unmerged change from project 'Moq(net6.0)'
26 | Before:
27 | internal interface IAwaitableFactory
28 | After:
29 | interface IAwaitableFactory
30 | */
31 | interface IAwaitableFactory
32 | {
33 | Type ResultType { get; }
34 |
35 | object CreateCompleted(object result = null);
36 |
37 | object CreateFaulted(Exception exception);
38 |
39 | object CreateFaulted(IEnumerable exceptions);
40 |
41 | Expression CreateResultExpression(Expression awaitableExpression);
42 |
43 | bool TryGetResult(object awaitable, out object result);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Moq/IMock.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 | /// Covariant interface for such that casts between IMock<Employee> to IMock<Person>
8 | /// are possible. Only covers the covariant members of .
9 | ///
10 | public interface IMock where T : class
11 | {
12 | ///
13 | /// Exposes the mocked object instance.
14 | ///
15 | T Object { get; }
16 |
17 | ///
18 | /// Behavior of the mock, according to the value set in the constructor.
19 | ///
20 | MockBehavior Behavior { get; }
21 |
22 | ///
23 | /// Whether the base member virtual implementation will be called for mocked classes if no setup is matched.
24 | /// Defaults to .
25 | ///
26 | bool CallBase { get; set; }
27 |
28 | ///
29 | /// Specifies the behavior to use when returning default values for unexpected invocations on loose mocks.
30 | ///
31 | DefaultValue DefaultValue { get; set; }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Moq.Tests.FSharpTypes/Moq.Tests.FSharpTypes.fsproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472;net6.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 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/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 | /* Unmerged change from project 'Moq(netstandard2.0)'
11 | Before:
12 | internal abstract class MethodSetup : Setup
13 | After:
14 | abstract class MethodSetup : Setup
15 | */
16 |
17 | /* Unmerged change from project 'Moq(netstandard2.1)'
18 | Before:
19 | internal abstract class MethodSetup : Setup
20 | After:
21 | abstract class MethodSetup : Setup
22 | */
23 |
24 | /* Unmerged change from project 'Moq(net6.0)'
25 | Before:
26 | internal abstract class MethodSetup : Setup
27 | After:
28 | abstract class MethodSetup : Setup
29 | */
30 | ///
31 | /// Abstract base class for setups that target a single, specific method.
32 | ///
33 | abstract class MethodSetup : Setup
34 | {
35 | protected MethodSetup(Expression originalExpression, Mock mock, MethodExpectation expectation)
36 | : base(originalExpression, mock, expectation)
37 | {
38 | }
39 |
40 | public MethodInfo Method => ((MethodExpectation)this.Expectation).Method;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Moq/Language/ICallbackGetter.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 | using Moq.Language.Flow;
8 |
9 | namespace Moq.Language
10 | {
11 | ///
12 | /// Defines the Callback verb for property getter setups.
13 | ///
14 | ///
15 | /// Mocked type.
16 | /// Type of the property.
17 | [EditorBrowsable(EditorBrowsableState.Never)]
18 | public interface ICallbackGetter : IFluentInterface
19 | where TMock : class
20 | {
21 | ///
22 | /// Specifies a callback to invoke when the property is retrieved.
23 | ///
24 | /// Callback method to invoke.
25 | ///
26 | /// Invokes the given callback with the property value being set.
27 | ///
28 | /// mock.SetupGet(x => x.Suspended)
29 | /// .Callback(() => called = true)
30 | /// .Returns(true);
31 | ///
32 | ///
33 | IReturnsThrowsGetter Callback(Action action);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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 |
10 | /* Unmerged change from project 'Moq(netstandard2.0)'
11 | Before:
12 | internal abstract class ProxyFactory
13 | After:
14 | abstract class ProxyFactory
15 | */
16 |
17 | /* Unmerged change from project 'Moq(netstandard2.1)'
18 | Before:
19 | internal abstract class ProxyFactory
20 | After:
21 | abstract class ProxyFactory
22 | */
23 |
24 | /* Unmerged change from project 'Moq(net6.0)'
25 | Before:
26 | internal abstract class ProxyFactory
27 | After:
28 | abstract class ProxyFactory
29 | */
30 | abstract class ProxyFactory
31 | {
32 | ///
33 | /// Gets the global instance used by Moq.
34 | ///
35 | public static ProxyFactory Instance { get; } = new CastleProxyFactory();
36 |
37 | public abstract object CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, object[] arguments);
38 |
39 | public abstract bool IsMethodVisible(MethodInfo method, out string messageIfNotVisible);
40 |
41 | public abstract bool IsTypeVisible(Type type);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Moq.Tests/CaptureMatchFixture.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 CaptureMatchFixture
9 | {
10 | [Fact]
11 | public void CanRunCaptureCallback()
12 | {
13 | var capturedValue = string.Empty;
14 | var captureMatch = new CaptureMatch(s => capturedValue = s);
15 |
16 | var mock = new Mock();
17 | mock.Setup(x => x.DoSomething(Capture.With(captureMatch)));
18 |
19 | mock.Object.DoSomething("Hello!");
20 |
21 | Assert.Equal("Hello!", capturedValue);
22 | }
23 |
24 | [Fact]
25 | public void CanRunCaptureCallbackWithPredicate()
26 | {
27 | var capturedValue = string.Empty;
28 | var captureMatch = new CaptureMatch(s => capturedValue += s, s => s.StartsWith("W"));
29 |
30 | var mock = new Mock();
31 | mock.Setup(x => x.DoSomething(Capture.With(captureMatch)));
32 |
33 | mock.Object.DoSomething("Hello!");
34 | mock.Object.DoSomething("World!");
35 |
36 | Assert.Equal("World!", capturedValue);
37 | }
38 |
39 | public interface IFoo
40 | {
41 | void DoSomething(string item);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Moq/Obsolete/SequenceExtensions.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 | using System.Linq.Expressions;
7 |
8 | using Moq.Language;
9 |
10 | namespace Moq
11 | {
12 | partial class SequenceExtensions
13 | {
14 | ///
15 | /// Return a sequence of values, once per call.
16 | ///
17 | [EditorBrowsable(EditorBrowsableState.Never)]
18 | [Obsolete("Please use instance method Mock.SetupSequence instead.")]
19 | public static ISetupSequentialResult SetupSequence(
20 | this Mock mock,
21 | Expression> expression)
22 | where TMock : class
23 | {
24 | return mock.SetupSequence(expression);
25 | }
26 |
27 | ///
28 | /// Performs a sequence of actions, one per call.
29 | ///
30 | [EditorBrowsable(EditorBrowsableState.Never)]
31 | [Obsolete("Please use instance method Mock.SetupSequence instead.")]
32 | public static ISetupSequentialAction SetupSequence(this Mock mock, Expression> expression)
33 | where TMock : class
34 | {
35 | return mock.SetupSequence(expression);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Moq.Tests/CallBaseFixture.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 CallBaseFixture
9 | {
10 | [Fact]
11 | public void Void_method_in_base_class_not_called_when_CallBase_not_specified()
12 | {
13 | var mock = new Mock();
14 |
15 | mock.Object.Method();
16 |
17 | Assert.False(mock.Object.MethodInvoked);
18 | }
19 |
20 | [Fact]
21 | public void Void_method_in_base_class_called_when_CallBase_specified_on_mock()
22 | {
23 | var mock = new Mock() { CallBase = true };
24 |
25 | mock.Object.Method();
26 |
27 | Assert.True(mock.Object.MethodInvoked);
28 | }
29 |
30 | [Fact]
31 | public void Void_method_in_base_class_called_when_CallBase_specified_on_setup()
32 | {
33 | var mock = new Mock();
34 | mock.Setup(m => m.Method()).CallBase();
35 |
36 | mock.Object.Method();
37 |
38 | Assert.True(mock.Object.MethodInvoked);
39 | }
40 |
41 | public class Base
42 | {
43 | public bool MethodInvoked { get; private set; }
44 |
45 | public virtual void Method()
46 | {
47 | this.MethodInvoked = true;
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Moq/Language/IRaise.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" language="C#" #>
2 | <#@ output extension=".Generated.cs" #>
3 | <#@ Assembly Name="System.Core" #>
4 | <#@ Import Namespace="System.Linq" #>
5 | // Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
6 | // All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
7 |
8 | using System;
9 | using System.ComponentModel;
10 |
11 | namespace Moq.Language
12 | {
13 | partial interface IRaise
14 | { <#
15 | for (var typeCount = 1; typeCount <= GenericTypeMax; typeCount++)
16 | {
17 | var typeList = GetGenericList(typeCount, GenericTypeFormat);
18 | #>
19 |
20 | ///
21 | /// Specifies the event that will be raised when the setup is matched.
22 | ///
23 | /// The expression that represents an event attach or detach action.
24 | /// The function that will build the
25 | /// to pass when raising the event.
26 | <#
27 | for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++)
28 | {
29 | #>
30 | /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument received by the expected invocation.
31 | <#
32 | }
33 | #>
34 | ///
35 | IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func);
36 | <#
37 | }
38 | #>
39 | }
40 | }
41 | <#@ Include File="GenericTypeParameters.tt" #>
42 |
--------------------------------------------------------------------------------
/.github/workflows/test/action.yml:
--------------------------------------------------------------------------------
1 | name: test
2 | description: runs dotnet tests with retry
3 | runs:
4 | using: "composite"
5 | steps:
6 | - name: 🧪 test
7 | shell: bash --noprofile --norc {0}
8 | env:
9 | LC_ALL: en_US.utf8
10 | run: |
11 | [ -f .bash_profile ] && source .bash_profile
12 | counter=0
13 | exitcode=0
14 | reset="\e[0m"
15 | warn="\e[0;33m"
16 | while [ $counter -lt 6 ]
17 | do
18 | # run test and forward output also to a file in addition to stdout (tee command)
19 | if [ $filter ]
20 | then
21 | echo -e "${warn}Retry $counter for $filter ${reset}"
22 | dotnet test --no-build -m:1 --blame-hang --blame-hang-timeout 5m --filter=$filter | tee ./output.log
23 | else
24 | dotnet test --no-build -m:1 --blame-hang --blame-hang-timeout 5m | tee ./output.log
25 | fi
26 | # capture dotnet test exit status, different from tee
27 | exitcode=${PIPESTATUS[0]}
28 | if [ $exitcode == 0 ]
29 | then
30 | exit 0
31 | fi
32 | # cat output, get failed test names, remove trailing whitespace, sort+dedupe, join as FQN~TEST with |, remove trailing |.
33 | filter=$(cat ./output.log | grep -o -P '(?<=\sFailed\s)[\w\._]*' | sed 's/ *$//g' | sort -u | awk 'BEGIN { ORS="|" } { print("FullyQualifiedName~" $0) }' | grep -o -P '.*(?=\|$)')
34 | ((counter++))
35 | done
36 | exit $exitcode
37 |
--------------------------------------------------------------------------------
/src/Moq/Language/Flow/ISetup.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 ISetup : ICallback, ICallbackResult, IRaise, IVerifies, IFluentInterface
13 | where TMock : class
14 | {
15 | }
16 |
17 | ///
18 | /// Implements the fluent API.
19 | ///
20 | [EditorBrowsable(EditorBrowsableState.Never)]
21 | public interface ISetup : ICallback, IReturnsThrows, IVerifies, IFluentInterface
22 | where TMock : class
23 | {
24 | }
25 |
26 | ///
27 | /// Implements the fluent API.
28 | ///
29 | [EditorBrowsable(EditorBrowsableState.Never)]
30 | public interface ISetupGetter : ICallbackGetter, IReturnsThrowsGetter, IVerifies, IFluentInterface
31 | where TMock : class
32 | {
33 | }
34 |
35 | ///
36 | /// Implements the fluent API.
37 | ///
38 | [EditorBrowsable(EditorBrowsableState.Never)]
39 | public interface ISetupSetter : ICallbackSetter, ICallbackResult, IRaise, IVerifies, IFluentInterface
40 | where TMock : class
41 | {
42 | }
43 | }
--------------------------------------------------------------------------------
/src/Moq/IInvocation.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.Reflection;
7 |
8 | namespace Moq
9 | {
10 | ///
11 | /// Provides information about an invocation of a mock object.
12 | ///
13 | public interface IInvocation
14 | {
15 | ///
16 | /// Gets the method of the invocation.
17 | ///
18 | MethodInfo Method { get; }
19 |
20 | ///
21 | /// Gets the arguments of the invocation.
22 | ///
23 | IReadOnlyList