├── GitInfo.txt
├── .github
├── FUNDING.yml
└── workflows
│ ├── sponsor.yml
│ └── includes.yml
├── Moq.snk
├── moq.png
├── moq-bigger.png
├── moq-icon.png
├── moq-small.png
├── 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
│ │ ├── moq-icon.png
│ │ └── github-32.png
│ └── main.scss
├── user-guide
│ └── index.md
├── _config.yml
├── _layouts
│ ├── default.html
│ └── homepage.html
├── index.md
├── _includes
│ ├── head.html
│ └── header.html
└── Gemfile.lock
├── .gitignore
├── .gitattributes
├── tests
├── Moq.Tests.ComTypes
│ ├── Moq.Tests.ComTypes.dll
│ ├── BuildDLLFromIDL.cmd
│ ├── ComTypes.idl
│ └── README.md
├── Moq.Tests.FSharpTypes
│ ├── IHasIndexer.fs
│ ├── IHasProperty.fs
│ ├── HasAbstractIndexer.fs
│ ├── HasAbstractProperty.fs
│ ├── IHasActionEvent.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
│ ├── InterceptorFixture.cs
│ ├── SequentialActionExtensionsFixture.cs
│ ├── DefaultValueProviderFixture.cs
│ ├── EventHandlerTypesMustMatchFixture.cs
│ ├── OccurrenceFixture.cs
│ ├── MockedFixture.cs
│ ├── MethodExpectationFixture.cs
│ ├── CustomMatcherFixture.cs
│ ├── Moq.Tests.csproj
│ ├── AfterReturnCallbackDelegateValidationFixture.cs
│ └── ProxyFactories
│ │ └── MostSpecificOverrideFixture.cs
└── Moq.Tests.VisualBasic
│ └── Moq.Tests.VisualBasic.vbproj
├── Before.Moq.sln.targets
├── src
└── Moq
│ ├── Behavior.cs
│ ├── IMatcher.cs
│ ├── Behaviors
│ ├── NoOp.cs
│ ├── ReturnBase.cs
│ ├── ReturnValue.cs
│ ├── ThrowException.cs
│ ├── Callback.cs
│ ├── ReturnComputedValue.cs
│ ├── ThrowComputedException.cs
│ ├── VerifyInvocationCount.cs
│ └── RaiseEvent.cs
│ ├── MockExceptionReasons.cs
│ ├── Language
│ ├── Flow
│ │ ├── IThrowsResult.cs
│ │ ├── ICallBaseResult.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
│ ├── ISetupConditionResult.cs
│ ├── IRaise.cs
│ ├── IReturnsGetter.cs
│ ├── IReturns.tt
│ ├── IThrows.tt
│ ├── ISetupSequentialAction.cs
│ └── IVerifies.cs
│ ├── ISetupList.cs
│ ├── Interception
│ ├── IInterceptor.cs
│ ├── IProxy.cs
│ ├── Mock.cs
│ └── ProxyFactory.cs
│ ├── IInvocationList.cs
│ ├── Condition.cs
│ ├── Range.cs
│ ├── Matchers
│ ├── AnyMatcher.cs
│ ├── ExpressionMatcher.cs
│ ├── LazyEvalMatcher.cs
│ ├── RefMatcher.cs
│ ├── ConstantMatcher.cs
│ └── ParamArrayMatcher.cs
│ ├── Obsolete
│ ├── MockExtensions.cs
│ ├── SequenceExtensions.cs
│ └── IOccurrence.cs
│ ├── MethodSetup.cs
│ ├── Async
│ ├── IAwaitableFactory.cs
│ ├── Awaitable.cs
│ ├── ValueTaskFactory.cs
│ ├── TaskFactory.cs
│ ├── AwaitExpression.cs
│ ├── TaskFactory`1.cs
│ ├── ValueTaskFactory`1.cs
│ ├── AwaitableFactory.cs
│ ├── AwaitableFactory`1.cs
│ └── AwaitableFactory`2.cs
│ ├── DefaultExpressionCompiler.cs
│ ├── Expressions
│ └── Visitors
│ │ ├── Apply.cs
│ │ ├── EvaluateCaptures.cs
│ │ └── ConstructorCallVisitor.cs
│ ├── MockBehavior.cs
│ ├── MockExtensions.cs
│ ├── IMocked.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Switches.cs
│ ├── MatchExpression.cs
│ ├── ITypeMatcher.cs
│ ├── Pair.cs
│ ├── ParameterTypes.cs
│ ├── Protected
│ └── ProtectedExtension.cs
│ ├── InvocationFunc.cs
│ ├── InvocationAction.cs
│ ├── ImmutablePopOnlyStack.cs
│ ├── IMock.cs
│ ├── Expectation.cs
│ ├── IInvocation.cs
│ ├── ExpressionReconstructor.cs
│ ├── InnerMockSetup.cs
│ ├── EventHandlerCollection.cs
│ ├── CaptureMatch.cs
│ ├── DefaultValue.cs
│ ├── SequenceSetup.cs
│ ├── MockSequence.cs
│ ├── MockDefaultValueProvider.cs
│ ├── SetupWithOutParameterSupport.cs
│ ├── EmptyDefaultValueProvider.cs
│ ├── TypeMatcherAttribute.cs
│ ├── AsInterface.cs
│ ├── ExpressionCompiler.cs
│ ├── Linq
│ ├── MockQuery.cs
│ └── Mock.cs
│ └── Capture.cs
├── Directory.Build.props
├── .editorconfig
├── README.md
├── .netconfig
├── appveyor.yml
└── License.txt
/GitInfo.txt:
--------------------------------------------------------------------------------
1 | 4.19.0
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: devlooped
2 |
--------------------------------------------------------------------------------
/Moq.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/Moq.snk
--------------------------------------------------------------------------------
/moq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/moq.png
--------------------------------------------------------------------------------
/moq-bigger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/moq-bigger.png
--------------------------------------------------------------------------------
/moq-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/moq-icon.png
--------------------------------------------------------------------------------
/moq-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/moq-small.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | out
2 | bin
3 | obj
4 | *.suo
5 | *.user
6 | *.cache
7 | .vs
8 | */**/.*
9 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/docs/_sass/utility/text-alignment.scss:
--------------------------------------------------------------------------------
1 | .text-center {
2 | text-align: center;
3 | }
4 |
--------------------------------------------------------------------------------
/docs/assets/images/moq-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/docs/assets/images/moq-icon.png
--------------------------------------------------------------------------------
/docs/assets/images/github-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/docs/assets/images/github-32.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 |
--------------------------------------------------------------------------------
/tests/Moq.Tests.ComTypes/Moq.Tests.ComTypes.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stakx/moq/HEAD/tests/Moq.Tests.ComTypes/Moq.Tests.ComTypes.dll
--------------------------------------------------------------------------------
/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/_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 |
--------------------------------------------------------------------------------
/Before.Moq.sln.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/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/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | ---
3 |
4 | 
5 |
6 | Welcome to the documentation for version 4 of [stakx](https://github/stakx)' fork of Moq!
7 |
8 | [Quickstart for the parent project](https://github.com/moq/moq/wiki/Quickstart) \| [User Guide](user-guide/index.md)
9 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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/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 | internal abstract class Behavior
7 | {
8 | protected Behavior()
9 | {
10 | }
11 |
12 | public abstract void Execute(Invocation invocation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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/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 | internal interface IMatcher
9 | {
10 | bool Matches(object argument, Type parameterType);
11 |
12 | void SetupEvaluatedSuccessfully(object argument, Type parameterType);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/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/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 | internal sealed class NoOp : Behavior
7 | {
8 | public static readonly NoOp Instance = new NoOp();
9 |
10 | private NoOp()
11 | {
12 | }
13 |
14 | public override void Execute(Invocation invocation)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/tests/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/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 | internal 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/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/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/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 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildThisFileDirectory)
5 | $(RootDirectory)build\
6 | $(RootDirectory)out\
7 | Release
8 |
9 |
10 |
11 |
12 |
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 | }
--------------------------------------------------------------------------------
/tests/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/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/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 | internal sealed class ReturnBase : Behavior
7 | {
8 | public static readonly ReturnBase Instance = new ReturnBase();
9 |
10 | private ReturnBase()
11 | {
12 | }
13 |
14 | public override void Execute(Invocation invocation)
15 | {
16 | invocation.ReturnValue = invocation.CallBase();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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 | internal interface IInterceptor
11 | {
12 | void Intercept(Invocation invocation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/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/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 | internal sealed class ReturnValue : Behavior
7 | {
8 | private 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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | ; EditorConfig to support per-solution formatting.
2 | ; Use the EditorConfig VS add-in to make this work.
3 | ; http://editorconfig.org/
4 |
5 | ; This is the default for the codeline.
6 | root = true
7 |
8 | [*]
9 | end_of_line = CRLF
10 |
11 | [*.{cs,txt,md}]
12 | indent_style = tab
13 | indent_size = 4
14 |
15 | [*.{sln,proj,csproj,fsproj,vbproj,props,targets,xml,xdoc,config,nuspec}]
16 | indent_style = tab
17 | indent_size = 2
18 |
19 | [*.Designer.cs]
20 | indent_style = space
21 | indent_size = 4
22 |
23 | [*.resx]
24 | indent_style = space
25 | indent_size = 2
26 |
27 | [appveyor.yml]
28 | indent_style = space
29 | indent_size = 2
30 |
--------------------------------------------------------------------------------
/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 | internal 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 | internal sealed class Condition
9 | {
10 | private Func condition;
11 | private 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 |
--------------------------------------------------------------------------------
/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 | internal sealed class ThrowException : Behavior
10 | {
11 | private 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/docs/_includes/head.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{ page.title }}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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 | internal sealed class Callback : Behavior
10 | {
11 | private 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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # stakx.Moq (abandoned)
2 |
3 | This is an abandoned fork of [Moq®](https://github.com/moq/moq), a popular and friendly mocking library for .NET.
4 |
5 | I have decided to stop work on this project since I received a copyright / trademark infringement claim by the original project owner and was forced to take down the published NuGet package. While I _could_ rename this project and re-upload it under a different name, that would perhaps not make much sense for a small, mostly unused fork with respect to its discoverability. So I consider my work on this project concluded. It was good while it lasted!
6 |
7 | [](https://www.nuget.org/packages/stakx.Moq).
8 |
--------------------------------------------------------------------------------
/tests/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/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 | internal sealed class AnyMatcher : IMatcher
10 | {
11 | public static AnyMatcher Instance { get; } = new AnyMatcher();
12 |
13 | private 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 |
--------------------------------------------------------------------------------
/docs/_includes/header.html:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/Moq.Tests.VisualBasic/Moq.Tests.VisualBasic.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | net472;netcoreapp3.1;net6.0
9 | True
10 | portable
11 | False
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.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/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 | internal 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/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 | internal 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/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 | internal sealed class ReturnComputedValue : Behavior
10 | {
11 | private 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 |
--------------------------------------------------------------------------------
/tests/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/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 | internal sealed class ThrowComputedException : Behavior
10 | {
11 | private 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/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 | internal sealed class DefaultExpressionCompiler : ExpressionCompiler
10 | {
11 | new public static readonly DefaultExpressionCompiler Instance = new DefaultExpressionCompiler();
12 |
13 | private 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/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/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 | internal 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/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 |
--------------------------------------------------------------------------------
/tests/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 |
--------------------------------------------------------------------------------
/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/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 | internal class ExpressionMatcher : IMatcher
11 | {
12 | private 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/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 | internal class LazyEvalMatcher : IMatcher
11 | {
12 | private 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/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/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 | internal class RefMatcher : IMatcher
10 | {
11 | private readonly object reference;
12 | private 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 |
--------------------------------------------------------------------------------
/src/Moq/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | [assembly: ComVisible(false)]
7 |
8 | [assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")]
9 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
10 |
11 | [assembly: CLSCompliant(true)]
12 | [assembly: NeutralResourcesLanguage("en-US")]
13 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.netconfig:
--------------------------------------------------------------------------------
1 | [file ".github/workflows/includes.yml"]
2 | url = https://github.com/devlooped/oss/blob/main/.github/workflows/includes.yml
3 | sha = f08c3f28e46e28eb31e70846d65e57aa9553ce56
4 | etag = 884175b3f80b39edc1a23c6a34d58aa3c481432d4f20938f9a834dd918ef283d
5 | weak
6 | [file ".github/workflows/dotnet-file.yml"]
7 | url = https://github.com/devlooped/oss/blob/main/.github/workflows/dotnet-file.yml
8 | sha = f08c3f28e46e28eb31e70846d65e57aa9553ce56
9 | etag = 567444486383d032c1c5fbc538f07e860f92b1d08c66ac6ffb1db64ca539251c
10 | weak
11 | [file ".github/FUNDING.yml"]
12 | url = https://github.com/devlooped/.github/blob/main/.github/FUNDING.yml
13 | sha = 39f4c591716ff50dd035d2fade35e5822489ab7f
14 | etag = a944c728facd033bbdfb4ff8d0ef10d0b3a457c277dc499458df0ffc7e6409da
15 | weak
16 | [file ".github/workflows/sponsor.yml"]
17 | url = https://github.com/devlooped/oss/blob/main/.github/workflows/sponsor.yml
18 | sha = 8990ebb36199046e0b8098bad9e46dcef739c56e
19 | etag = e1dc114d2e8b57d50649989d32dbf0c9080ec77da3738a4cc79e9256d6ca5d3e
20 | weak
21 |
--------------------------------------------------------------------------------
/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 | internal 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/Async/Awaitable.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.Async
5 | {
6 | internal static class Awaitable
7 | {
8 | ///
9 | /// Recursively gets the result of (i.e. "unwraps") completed awaitables
10 | /// until a value is found that isn't a successfully completed awaitable.
11 | ///
12 | ///
13 | /// As an example, given := Task.FromResult(Task.FromResult(42)),
14 | /// this method will return 42.
15 | ///
16 | /// The (possibly awaitable) object to be "unwrapped".
17 | public static object TryGetResultRecursive(object obj)
18 | {
19 | if (obj != null
20 | && AwaitableFactory.TryGet(obj.GetType()) is { } awaitableFactory
21 | && awaitableFactory.TryGetResult(obj, out var result))
22 | {
23 | return Awaitable.TryGetResultRecursive(result);
24 | }
25 |
26 | return obj;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Moq/Pair.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 | internal readonly struct Pair : IEquatable>
9 | {
10 | public readonly T1 Item1;
11 | public readonly T2 Item2;
12 |
13 | public Pair(T1 item1, T2 item2)
14 | {
15 | this.Item1 = item1;
16 | this.Item2 = item2;
17 | }
18 |
19 | public void Deconstruct(out T1 item1, out T2 item2)
20 | {
21 | item1 = this.Item1;
22 | item2 = this.Item2;
23 | }
24 |
25 | public bool Equals(Pair other)
26 | {
27 | return object.Equals(this.Item1, other.Item1)
28 | && object.Equals(this.Item2, other.Item2);
29 | }
30 |
31 | public override bool Equals(object obj)
32 | {
33 | return obj is Pair other && this.Equals(other);
34 | }
35 |
36 | public override int GetHashCode()
37 | {
38 | return unchecked(1001 * this.Item1?.GetHashCode() ?? 101 + this.Item2?.GetHashCode() ?? 11);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/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 | internal sealed class ValueTaskFactory : AwaitableFactory
11 | {
12 | public static readonly ValueTaskFactory Instance = new ValueTaskFactory();
13 |
14 | private 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