895
C# Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, simple and refactoring-friendly mocking library available. See the online quickstarts for more examples than those available in this code documentation. The Mock<T> class is the core of the library, so it's a good place to start. You can also read blog entries from around the world about Moq.

C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMoqNamespaceSendFeedbackRootnamespaceofMoq(pronounced"Mock-you"orjust"Mock"),theonlymockinglibraryfor.NETdevelopedfromscratchtotakefulladvantageof.NET3.5(i.e.Linqexpressiontrees)andC#3.0features(i.e.lambdaexpressions)thatmakeitthemostproductive,simpleandrefactoring-friendlymockinglibraryavailable.

Seetheonlinequickstartsformoreexamplesthanthoseavailableinthiscodedocumentation.

TheMock<T>classisthecoreofthelibrary,soit'sagoodplacetostart.

YoucanalsoreadblogentriesfromaroundtheworldaboutMoq.

Page 2: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Classes Class Description

It

Allowsthespecificationofamatchingconditionforanargumentinamethodinvocation,ratherthanaspecificargumentvalue."It"referstotheargumentbeingmatched.

MatcherAttributeMarksamethodasamatcher,whichallowscompletereplacementofthebuilt-inItclasswithyourownargumentmatchingrules.

Mock

Baseclassformocksandstatichelperclasswithmethodsthatapplytomockedobjects,suchasGet<(Of<(T>)>)(T)toretrieveaMock<(Of<(T>)>)fromanobjectinstance.

Mock<(Of<(T>)>)

CoreimplementationoftheIMock<(Of<(T>)>)interface.

MockedEvent Representsagenericeventthathasbeenmockedandcanberised.

MockedEvent<(Of<(TEventArgs>)>)

ProvidesatypedMockedEventforaspecifictypeofEventArgs.

MockException Exceptionthrownbymockswhenexpectationsarenotmet,themockisnotproperlysetup,etc.

MockFactoryUtilityfactoryclasstousetoconstructmultiplemockswhenconsistentverificationisdesiredforallofthem.

Page 3: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Interfaces Interface Description

IMock Basemockinterfaceexposingnon-genericmembers.

IMock<(Of<(T>)>) ProvidesamockimplementationofT.

Page 4: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Enumerations Enumeration Description

DefaultValue Determinesthewaydefaultvaluesaregeneratedcalculatedforloosemocks.

MockBehavior Optionstocustomizethebehaviorofthemock.

Range KindofrangetouseinafilterspecifiedthroughIsInRange<(Of<(TValue>)>)(TValue,TValue,Range).

[email protected]

Page 5: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqDefaultValueEnumerationSeeAlsoSendFeedbackDeterminesthewaydefaultvaluesaregeneratedcalculatedforloosemocks.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 6: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicenumDefaultValue

Page 7: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

MembersMembername Description

EmptyDefaultbehavior,whichgeneratesemptyvaluesforvaluetypes(i.e.default(int)),emptyarrayandenumerables,andnullsforallotherreferencetypes.

Mock WheneverthedefaultvaluegeneratedbyEmptyisnull,replacesthisvaluewithamock(ifthetypecanbemocked).

Page 9: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMockInterfaceMembersSeeAlsoSendFeedbackBasemockinterfaceexposingnon-genericmembers.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 10: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIMock

Page 12: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMockMembersIMockInterfaceMethodsPropertiesSeeAlsoSendFeedback

TheIMocktypeexposesthefollowingmembers.

Page 13: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

CreateEventHandler Overloaded.

Verify Verifiesthatallverifiableexpectationshavebeenmet.

VerifyAll Verifiesallexpectationsregardlessofwhethertheyhavebeenflaggedasverifiable.

Page 14: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

DefaultValue Determineshowtogeneratedefaultvaluesforloosemocksonunexpectedinvocations.Object Themockedobjectinstance.

Page 15: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 16: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMockMethodsIMockInterfaceSeeAlsoSendFeedback

TheIMocktypeexposesthefollowingmembers.

Page 17: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

CreateEventHandler Overloaded.

Verify Verifiesthatallverifiableexpectationshavebeenmet.

VerifyAll Verifiesallexpectationsregardlessofwhethertheyhavebeenflaggedasverifiable.

Page 18: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 19: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock..::.CreateEventHandlerMethodIMockInterfaceSeeAlsoSendFeedback

Page 20: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

CreateEventHandler<(Of<(TEventArgs>)>)()()()

CreatesahandlerthatcanbeassociatedtoaneventreceivingthegivenTEventArgsandcanbeusedtoraisetheevent.

CreateEventHandler()()()CreatesahandlerthatcanbeassociatedtoaneventreceivingagenericEventArgsandcanbeusedtoraisetheevent.

Page 21: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceIMockMembersMoqNamespace

[email protected]

Page 22: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.CreateEventHandler<(Of<(TEventArgs>)>)MethodIMockInterfaceExampleSeeAlsoSendFeedbackCreatesahandlerthatcanbeassociatedtoaneventreceivingthegivenTEventArgsandcanbeusedtoraisetheevent.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 23: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

MockedEvent<TEventArgs>CreateEventHandler<TEventArgs>()

whereTEventArgs:EventArgs

Page 24: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTEventArgs

TypeofEventArgsdatapassedintotheevent.

Page 25: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleshowshowtoinvokeaneventwithacustomeventargumentsclassinaviewthatwillcauseitscorrespondingpresentertoreactbychangingitsstate:

C#

varmockView=newMock<IOrdersView>();

varmockedEvent=mockView.CreateEventHandler<OrderEventArgs>();

varpresenter=newOrdersPresenter(mockView.Object);

//Checkthatthepresenterhasnoselectionbydefault

Assert.Null(presenter.SelectedOrder);

//Createamockeventhandleroftheappropriatetype

varhandler=mockView.CreateEventHandler<OrderEventArgs>();

//Associateitwiththeeventwewanttoraise

mockView.Object.Cancel+=handler;

//Finallyraisetheeventwithaspecificargumentsdata

handler.Raise(newOrderEventArgs{Order=newOrder("moq",500)});

//Nowthepresenterreactedtotheevent,andwehaveaselectedorder

Assert.NotNull(presenter.SelectedOrder);

Assert.Equal("moq",presenter.SelectedOrder.ProductName);

Page 26: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceCreateEventHandlerOverloadMoqNamespace

[email protected]

Page 27: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.CreateEventHandlerMethodIMockInterfaceExampleSeeAlsoSendFeedbackCreatesahandlerthatcanbeassociatedtoaneventreceivingagenericEventArgsandcanbeusedtoraisetheevent.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 28: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

MockedEvent<EventArgs>CreateEventHandler()

Page 29: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleshowshowtoinvokeagenericeventinaviewthatwillcauseitscorrespondingpresentertoreactbychangingitsstate:

C#

varmockView=newMock<IOrdersView>();

varmockedEvent=mockView.CreateEventHandler();

varpresenter=newOrdersPresenter(mockView.Object);

//Checkthatthepresenterisnotinthe"Canceled"state

Assert.False(presenter.IsCanceled);

//Createamockeventhandleroftheappropriatetype

varhandler=mockView.CreateEventHandler();

//Associateitwiththeeventwewanttoraise

mockView.Object.Cancel+=handler;

//Finallyraisetheevent

handler.Raise(EventArgs.Empty);

//Nowthepresenterreactedtotheevent,andchangeditsstate

Assert.True(presenter.IsCanceled);

Page 30: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceCreateEventHandlerOverloadMoqNamespace

[email protected]

Page 31: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.VerifyMethodIMockInterfaceExampleSeeAlsoSendFeedbackVerifiesthatallverifiableexpectationshavebeenmet.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 32: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerify()

Page 33: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexamplesetsupanexpectationandmarksitasverifiable.Afterthemockisused,aVerify()()()callisissuedonthemocktoensurethemethodintheexpectationwasinvoked:

C#

varmock=newMock<IWarehouse>();

mock.Expect(x=>x.HasInventory(TALISKER,50)).Verifiable().Returns(

...

//othertestcode

...

//Willthrowifthetestcodehasdidn'tcallHasInventory.

mock.Verify();

Page 34: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Notallverifiableexpectationsweremet.

Page 35: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 36: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.VerifyAllMethodIMockInterfaceExampleSeeAlsoSendFeedbackVerifiesallexpectationsregardlessofwhethertheyhavebeenflaggedasverifiable.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 37: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifyAll()

Page 38: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexamplesetsupanexpectationwithoutmarkingitasverifiable.Afterthemockisused,aVerifyAll()()()callisissuedonthemocktoensurethatallexpectationsaremet:

C#

varmock=newMock<IWarehouse>();

mock.Expect(x=>x.HasInventory(TALISKER,50)).Returns(true);

...

//othertestcode

...

//Willthrowifthetestcodehasdidn'tcallHasInventory,even

//thatexpectationwasnotmarkedasverifiable.

mock.VerifyAll();

Page 39: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Atleastoneexpectationwasnotmet.

Page 40: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 41: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMockPropertiesIMockInterfaceSeeAlsoSendFeedback

TheIMocktypeexposesthefollowingmembers.

Page 42: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

DefaultValue Determineshowtogeneratedefaultvaluesforloosemocksonunexpectedinvocations.Object Themockedobjectinstance.

Page 43: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 44: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.CallBasePropertyIMockInterfaceSeeAlsoSendFeedbackWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 45: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

boolCallBase{get;set;}

Page 46: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 47: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.DefaultValuePropertyIMockInterfaceSeeAlsoSendFeedbackDetermineshowtogeneratedefaultvaluesforloosemocksonunexpectedinvocations.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 48: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

DefaultValueDefaultValue{get;set;}

Page 49: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 50: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock..::.ObjectPropertyIMockInterfaceSeeAlsoSendFeedbackThemockedobjectinstance.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 51: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ObjectObject{get;}

Page 52: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMockInterfaceMoqNamespace

[email protected]

Page 53: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)InterfaceMembersExampleSeeAlsoSendFeedbackProvidesamockimplementationofT.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 54: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIMock<T>

whereT:class

Page 55: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock,whichcanbeaninterfaceoraclass.

Page 56: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksOnlyabstractandvirtualmembersofclassescanbemocked.

ThebehaviorofthemockwithregardstotheexpectationsandtheactualcallsisdeterminedbytheoptionalMockBehaviorthatcanbepassedtotheMock<(Of<(T>)>)(MockBehavior)constructor.

Page 57: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesThefollowingexampleshowssettingexpectationswithspecificvaluesformethodinvocations:

C#

//setup-data

varorder=newOrder(TALISKER,50);

varmock=newMock<IWarehouse>();

//setup-expectations

mock.Expect(x=>x.HasInventory(TALISKER,50)).Returns(true);

//exercise

order.Fill(mock.Object);

//verify

Assert.True(order.IsFilled);

ThefollowingexampleshowshowtousetheItclasstospecifyconditionsforargumentsinsteadofspecificvalues:

C#

//setup-data

varorder=newOrder(TALISKER,50);

varmock=newMock<IWarehouse>();

//setup-expectations

//showshowtoexpectavaluewithinarange

mock.Expect(x=>x.HasInventory(

It.IsAny<string>(),

It.IsInRange(0,100,Range.Inclusive)))

.Returns(false);

//showshowtothrowforunexpectedcalls.contrastwiththe"verify"approachofothermocklibraries.

mock.Expect(x=>x.Remove(

It.IsAny<string>(),

It.IsAny<int>()))

.Throws(newInvalidOperationException());

//exercise

order.Fill(mock.Object);

Page 58: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

//verify

Assert.False(order.IsFilled);

Page 59: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 60: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)MembersIMock<(Of<(T>)>)InterfaceMethodsPropertiesSeeAlsoSendFeedback

TheIMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 61: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

As<(Of<(TInterface>)>)

Addsaninterfaceimplementationtothemock,allowingexpectationstobesetforit.

Expect Overloaded.ExpectGet<(Of<(TProperty>)>)

Setsanexpectationonthemockedtypeforacalltotoapropertygetter.

ExpectSet Overloaded.Verify Overloaded.VerifyAll ImplementsVerifyAll()()().VerifyGet<(Of<(TProperty>)>)

Verifiesthatapropertywasreadonthemock.UseinconjuntionwiththedefaultLoose.

VerifySet Overloaded.

Page 62: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior Behaviorofthemock,accordingtothevaluesetintheconstructor.

DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocations.Object Exposesthemockedobjectinstance.

Page 63: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 64: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)MethodsIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

TheIMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 65: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

As<(Of<(TInterface>)>)

Addsaninterfaceimplementationtothemock,allowingexpectationstobesetforit.

Expect Overloaded.ExpectGet<(Of<(TProperty>)>)

Setsanexpectationonthemockedtypeforacalltotoapropertygetter.

ExpectSet Overloaded.Verify Overloaded.VerifyAll ImplementsVerifyAll()()().VerifyGet<(Of<(TProperty>)>)

Verifiesthatapropertywasreadonthemock.UseinconjuntionwiththedefaultLoose.

VerifySet Overloaded.

Page 66: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 67: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.As<(Of<(TInterface>)>)MethodIMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackAddsaninterfaceimplementationtothemock,allowingexpectationstobesetforit.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 68: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IMock<TInterface>As<TInterface>()

whereTInterface:class

Page 69: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTInterface

Typeofinterfacetocastthemockto.

Page 70: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThismethodcanonlybecalledbeforethefirstuseofthemockObjectproperty,atwhichpointtheruntimetypehasalreadybeengeneratedandnomoreinterfacescanbeaddedtoit.

Also,TInterfacemustbeaninterfaceandnotaclass,whichmustbespecifiedwhencreatingthemockinstead.

Page 71: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexamplecreatesamockforthemaininterfaceandlateraddsIDisposabletoittoverifyit'scalledbytheconsumercode:

C#

varmock=newMock<IProcessor>();

mock.Expect(x=>x.Execute("ping"));

//addIDisposableinterface

vardisposable=mock.As<IDisposable>();

disposable.Expect(d=>d.Dispose()).Verifiable();

Page 72: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

InvalidOperationException ThemocktypehasalreadybeengeneratedbyaccessingtheObjectproperty.ArgumentException TheTInterfacespecifiedisnotaninterface.

Page 73: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 74: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)..::.ExpectMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

Page 75: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Expect(Expression<(Of<(Action<(Of<(T>)>)>)>))

Setsanexpectationonthemockedtypeforacalltotoavoidmethod.

Expect<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>))

Setsanexpectationonthemockedtypeforacalltotoavaluereturningmethod.

Page 76: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 77: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.ExpectMethod(<(Of<(<(Of<(T>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackSetsanexpectationonthemockedtypeforacalltotoavoidmethod.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 78: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectExpect(

Expression<Action<T>>expression

)

Parameters

expressionType:Expression<(Of<(Action<(Of<(T>)>)>)>)Lambdaexpressionthatspecifiestheexpectedmethodinvocation.

Page 79: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfmorethanoneexpectationissetforthesamemethodorproperty,thelatestonewinsandistheonethatwillbeexecuted.

Page 80: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<IProcessor>();

mock.Expect(x=>x.Execute("ping"));

Page 81: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceExpectOverloadMoqNamespace

[email protected]

Page 82: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.Expect<(Of<(TResult>)>)Method(<(Of<(<(Of<(T,TResult>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackSetsanexpectationonthemockedtypeforacalltotoavaluereturningmethod.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 83: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpect<TResult>Expect<TResult>(

Expression<Func<T,TResult>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)Lambdaexpressionthatspecifiestheexpectedmethodinvocation.

Page 84: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofthereturnvalue.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 85: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfmorethanoneexpectationissetforthesamemethodorproperty,thelatestonewinsandistheonethatwillbeexecuted.

Page 86: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

mock.Expect(x=>x.HasInventory("Talisker",50)).Returns(true);

Page 87: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceExpectOverloadMoqNamespace

[email protected]

Page 88: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.ExpectGet<(Of<(TProperty>)>)MethodIMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackSetsanexpectationonthemockedtypeforacalltotoapropertygetter.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 89: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectGetter<TProperty>ExpectGet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertygetter.

Page 90: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 91: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfmorethanoneexpectationissetforthesamepropertygetter,thelatestonewinsandistheonethatwillbeexecuted.

Page 92: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

mock.ExpectGet(x=>x.Suspended)

.Returns(true);

Page 93: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 94: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)..::.ExpectSetMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

Page 95: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

Setsanexpectationonthemockedtypeforacalltotoapropertysetter.

ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

Setsanexpectationonthemockedtypeforacalltotoapropertysetterwithaspecificvalue.

Page 96: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 97: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackSetsanexpectationonthemockedtypeforacalltotoapropertysetter.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 98: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectSetter<TProperty>ExpectSet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertysetter.

Page 99: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 100: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfmorethanoneexpectationissetforthesamepropertysetter,thelatestonewinsandistheonethatwillbeexecuted.

Page 101: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

mock.ExpectSet(x=>x.Suspended);

Page 102: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceExpectSetOverloadMoqNamespace

[email protected]

Page 103: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>),TProperty)IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackSetsanexpectationonthemockedtypeforacalltotoapropertysetterwithaspecificvalue.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 104: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectSetter<TProperty>ExpectSet<TProperty>(

Expression<Func<T,TProperty>>expression,

TPropertyvalue

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertysetter.

valueType:TPropertyThevalueexpectedtobesetfortheproperty.

Page 105: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 106: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksMorethanoneexpectationcanbesetforthesetterwithdifferentvalues.

Page 107: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

mock.ExpectSet(x=>x.Suspended,true);

Page 108: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceExpectSetOverloadMoqNamespace

[email protected]

Page 109: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)..::.VerifyMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

Page 110: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Verify()()() ImplementsVerify()()().

Verify(Expression<(Of<(Action<(Of<(T>)>)>)>))

Verifiesthataspecificinvocationmatchingthegivenexpressionwasperformedonthemock.UseinconjuntionwiththedefaultLoose.

Verify<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>))

Verifiesthataspecificinvocationmatchingthegivenexpressionwasperformedonthemock.UseinconjuntionwiththedefaultLoose.

Page 111: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 112: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifyMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedbackImplementsVerify()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 113: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerify()

Page 114: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace

[email protected]

Page 115: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifyMethod(<(Of<(<(Of<(T>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackVerifiesthataspecificinvocationmatchingthegivenexpressionwasperformedonthemock.UseinconjuntionwiththedefaultLoose.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 116: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerify(

Expression<Action<T>>expression

)

Parameters

expressionType:Expression<(Of<(Action<(Of<(T>)>)>)>)Expressiontoverify.

Page 117: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleassumesthatthemockhasbeenused,andlaterwewanttoverifythatagiveninvocationwithspecificparameterswasperformed:

C#

varmock=newMock<IProcessor>();

//exercisemock

//...

//Willthrowifthetestcodedidn'tcallExecutewitha"ping"stringargument.

mock.Verify(proc=>proc.Execute("ping"));

Page 118: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Theinvocationwasnotperformedonthemock.

Page 119: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace

[email protected]

Page 120: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.Verify<(Of<(TResult>)>)Method(<(Of<(<(Of<(T,TResult>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackVerifiesthataspecificinvocationmatchingthegivenexpressionwasperformedonthemock.UseinconjuntionwiththedefaultLoose.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 121: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerify<TResult>(

Expression<Func<T,TResult>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)Expressiontoverify.

Page 122: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofreturnvaluefromtheexpression.

Page 123: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleassumesthatthemockhasbeenused,andlaterwewanttoverifythatagiveninvocationwithspecificparameterswasperformed:

C#

varmock=newMock<IWarehouse>();

//exercisemock

//...

//Willthrowifthetestcodedidn'tcallHasInventory.

mock.Verify(warehouse=>warehouse.HasInventory(TALISKER,50));

Page 124: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Theinvocationwasnotperformedonthemock.

Page 125: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace

[email protected]

Page 126: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifyAllMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedbackImplementsVerifyAll()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 127: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifyAll()

Page 128: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 129: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifyGet<(Of<(TProperty>)>)MethodIMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackVerifiesthatapropertywasreadonthemock.UseinconjuntionwiththedefaultLoose.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 130: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifyGet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

Page 131: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Page 132: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleassumesthatthemockhasbeenused,andlaterwewanttoverifythatagivenpropertywasretrievedfromit:

C#

varmock=newMock<IWarehouse>();

//exercisemock

//...

//Willthrowifthetestcodedidn'tretrievetheIsClosedproperty.

mock.VerifyGet(warehouse=>warehouse.IsClosed);

Page 133: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Theinvocationwasnotperformedonthemock.

Page 134: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 135: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)..::.VerifySetMethodIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

Page 136: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

Verifiesthatapropertyhasbeensetonthemock.UseinconjuntionwiththedefaultLoose.

VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

Verifiesthatapropertyhasbeensetonthemocktothegivenvalue.UseinconjuntionwiththedefaultLoose.

Page 137: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 138: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>))IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackVerifiesthatapropertyhasbeensetonthemock.UseinconjuntionwiththedefaultLoose.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 139: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifySet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

Page 140: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Page 141: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleassumesthatthemockhasbeenused,andlaterwewanttoverifythatagiveninvocationwithspecificparameterswasperformed:

C#

varmock=newMock<IWarehouse>();

//exercisemock

//...

//Willthrowifthetestcodedidn'tsettheIsClosedproperty.

mock.VerifySet(warehouse=>warehouse.IsClosed);

Page 142: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Theinvocationwasnotperformedonthemock.

Page 143: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceVerifySetOverloadMoqNamespace

[email protected]

Page 144: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>),TProperty)IMock<(Of<(T>)>)InterfaceExampleSeeAlsoSendFeedbackVerifiesthatapropertyhasbeensetonthemocktothegivenvalue.UseinconjuntionwiththedefaultLoose.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 145: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifySet<TProperty>(

Expression<Func<T,TProperty>>expression,

TPropertyvalue

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

valueType:TPropertyThevaluethatshouldhavebeensetontheproperty.

Page 146: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Page 147: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleassumesthatthemockhasbeenused,andlaterwewanttoverifythatagiveninvocationwithspecificparameterswasperformed:

C#

varmock=newMock<IWarehouse>();

//exercisemock

//...

//Willthrowifthetestcodedidn'tsettheIsClosedpropertytotrue

mock.VerifySet(warehouse=>warehouse.IsClosed,true);

Page 148: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Theinvocationwasnotperformedonthemock.

Page 149: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceVerifySetOverloadMoqNamespace

[email protected]

Page 150: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIMock<(Of<(T>)>)PropertiesIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedback

TheIMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 151: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior Behaviorofthemock,accordingtothevaluesetintheconstructor.

DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocations.Object Exposesthemockedobjectinstance.

Page 152: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 153: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.BehaviorPropertyIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedbackBehaviorofthemock,accordingtothevaluesetintheconstructor.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 154: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

MockBehaviorBehavior{get;}

Page 155: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 156: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.DefaultValuePropertyIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedbackSpecifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocations.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 157: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

DefaultValueDefaultValue{get;set;}

Page 158: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 159: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIMock<(Of<(T>)>)..::.ObjectPropertyIMock<(Of<(T>)>)InterfaceSeeAlsoSendFeedbackExposesthemockedobjectinstance.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 160: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

TObject{get;}

Page 161: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace

[email protected]

Page 162: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItClassMembersSeeAlsoSendFeedbackAllowsthespecificationofamatchingconditionforanargumentinamethodinvocation,ratherthanaspecificargumentvalue."It"referstotheargumentbeingmatched.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 163: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticclassIt

Page 164: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThisclassallowstheexpectationtomatchamethodinvocationwithanarbitraryvalue,withavalueinaspecifiedrange,orevenonethatmatchesagivenpredicate.

Page 165: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.It

Page 167: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqItMembersItClassMethodsSeeAlsoSendFeedback

TheIttypeexposesthefollowingmembers.

Page 168: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Is<(Of<(TValue>)>) Matchesanyvaluethatsatisfiesthegivenpredicate.

IsAny<(Of<(TValue>)>) MatchesanyvalueofthegivenTValuetype.IsInRange<(Of<(TValue>)>)

Matchesanyvaluethatisintherangespecified.

IsRegex Overloaded.

Page 170: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqItMethodsItClassSeeAlsoSendFeedback

TheIttypeexposesthefollowingmembers.

Page 171: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Is<(Of<(TValue>)>) Matchesanyvaluethatsatisfiesthegivenpredicate.

IsAny<(Of<(TValue>)>) MatchesanyvalueofthegivenTValuetype.IsInRange<(Of<(TValue>)>)

Matchesanyvaluethatisintherangespecified.

IsRegex Overloaded.

Page 173: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIt..::.Is<(Of<(TValue>)>)MethodItClassExampleSeeAlsoSendFeedbackMatchesanyvaluethatsatisfiesthegivenpredicate.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 174: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticTValueIs<TValue>(

Expression<Predicate<TValue>>match

)

Parameters

matchType:Expression<(Of<(Predicate<(Of<(TValue>)>)>)>)Thepredicateusedtomatchthemethodargument.

Page 175: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeoftheargumenttocheck.

Page 176: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksAllowsthespecificationofapredicatetoperformmatchingofmethodcallarguments.

Page 177: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesThisexampleshowshowtoreturnthevalue1whenevertheargumenttotheDomethodisanevennumber.

C#

mock.Expect(x=>x.Do(It.Is<int>(i=>i%2==0)))

.Returns(1);

Thisexampleshowshowtothrowanexceptioniftheargumenttothemethodisanegativenumber:

C#

mock.Expect(x=>x.GetUser(It.Is<int>(i=>i<0)))

.Throws(newArgumentException());

Page 179: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIt..::.IsAny<(Of<(TValue>)>)MethodItClassExampleSeeAlsoSendFeedbackMatchesanyvalueofthegivenTValuetype.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 180: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticTValueIsAny<TValue>()

Page 181: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeofthevalue.

Page 182: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksTypicallyusedwhentheactualargumentvalueforamethodcallisnotrelevant.

Page 183: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

//ThrowsanexceptionforacalltoRemovewithanystringvalue.

mock.Expect(x=>x.Remove(It.IsAny<string>())).Throws(newInvalidOperationException());

Page 185: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIt..::.IsInRange<(Of<(TValue>)>)MethodItClassExampleSeeAlsoSendFeedbackMatchesanyvaluethatisintherangespecified.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 186: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticTValueIsInRange<TValue>(

TValuefrom,

TValueto,

RangerangeKind

)

whereTValue:IComparable

Parameters

fromType:TValueThelowerboundoftherange.

toType:TValueTheupperboundoftherange.

rangeKindType:Moq..::.RangeThekindofrange.SeeRange.

Page 187: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeoftheargumenttocheck.

Page 188: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectamethodcallwithanintegerargumentwithinthe0..100range.

C#

mock.Expect(x=>x.HasInventory(

It.IsAny<string>(),

It.IsInRange(0,100,Range.Inclusive)))

.Returns(false);

Page 190: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIt..::.IsRegexMethodItClassSeeAlsoSendFeedback

Page 191: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

IsRegex(String) Matchesastringargumentifitmatchesthegivenregularexpressionpattern.

IsRegex(String,RegexOptions)

Matchesastringargumentifitmatchesthegivenregularexpressionpattern.

Page 192: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItClassItMembersMoqNamespace

[email protected]

Page 193: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIt..::.IsRegexMethod()ItClassExampleSeeAlsoSendFeedbackMatchesastringargumentifitmatchesthegivenregularexpressionpattern.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 194: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticstringIsRegex(

stringregex

)

Parameters

regexType:StringThepatterntousetomatchthestringargumentvalue.

Page 195: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectacalltoamethodwherethestringargumentmatchesthegivenregularexpression:

C#

mock.Expect(x=>x.Check(It.IsRegex("[a-z]+"))).Returns(1);

Page 196: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItClassIsRegexOverloadMoqNamespace

[email protected]

Page 197: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIt..::.IsRegexMethod(,)ItClassExampleSeeAlsoSendFeedbackMatchesastringargumentifitmatchesthegivenregularexpressionpattern.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 198: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticstringIsRegex(

stringregex,

RegexOptionsoptions

)

Parameters

regexType:StringThepatterntousetomatchthestringargumentvalue.

optionsType:RegexOptionsTheoptionsusedtointerpretthepattern.

Page 199: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectacalltoamethodwherethestringargumentmatchesthegivenregularexpression,inacaseinsensitiveway:

C#

mock.Expect(x=>x.Check(It.IsRegex("[a-z]+",RegexOptions.IgnoreCase))).Returns(

Page 200: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItClassIsRegexOverloadMoqNamespace

[email protected]

Page 201: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMatcherAttributeClassMembersExampleSeeAlsoSendFeedbackMarksamethodasamatcher,whichallowscompletereplacementofthebuilt-inItclasswithyourownargumentmatchingrules.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 202: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicclassMatcherAttribute:Attribute

Page 203: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

RemarksTheargumentmatchingisusedtodeterminewhetheraconcreteinvocationinthemockmatchesagivenexpectation.Thismatchingmechanismisfullyextensible.

Therearetwopartsofamatcher:thecompilermatcherandtheruntimematcher.

CompilermatcherUsedtosatisfythecompilerrequirementsfortheargument.Needstobeamethodoptionallyreceivinganyargumentsyoumightneedforthematching,butwithareturntypethatmatchesthatoftheargument.

Let'ssayIwanttomatchalistsofordersthatcontainsaparticularone.Imightcreateacompilermatcherlikethefollowing:

C#

publicstaticclassOrders

{

[Matcher]

publicstaticIEnumerable<Order>Contains(Orderorder)

{

returnnull;

}

}

Nowwecaninvokethisstaticmethodinsteadofanargumentinaninvocation:

C#

varorder=newOrder{...};

varmock=newMock<IRepository<Order>>();

mock.Expect(x=>x.Save(Orders.Contains(order)))

.Throws<ArgumentException>();

Notethatthereturnvaluefromthecompilermatcherisirrelevant.Thismethodwillneverbecalled,andisjustusedtosatisfythecompilerandtosignalMoqthatthisisnotamethodthatwewanttobeinvokedatruntime.

Page 204: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

RuntimematcherTheruntimematcheristheonethatwillactuallyperformevaluationwhenthetestisrun,andisdefinedbyconventiontohavethesamesignatureasthecompilermatcher,butwherethereturnvalueisthefirstargumenttothecall,whichcontainstheobjectreceivedbytheactualinvocationatruntime:

C#

publicstaticboolContains(IEnumerable<Order>orders,Orderorder)

{

returnorders.Contains(order);

}

Atruntime,themockedmethodwillbeinvokedwithaspecificlistoforders.Thisvaluewillbepassedtothisruntimematcherasthefirstargument,whilethesecondargumentistheonespecifiedintheexpectation(x.Save(Orders.Contains(order))).

Thebooleanreturneddetermineswhetherthegivenargumenthasbeenmatched.Ifallargumentstotheexpectedmethodarematched,thentheexpectationisverified.

Usingthisextensibleinfrastructure,youcaneasilyreplacetheentireItsetofmatcherswithyourown.Youcanalsoavoidthetypical(andannoying)lengthyexpressionsthatresultwhenyouhavemultipleargumentsthatusegenerics.

Page 205: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesThefollowingisthecompleteexampleexplainedabove:

C#

publicstaticclassOrders

{

[Matcher]

publicstaticIEnumerable<Order>Contains(Orderorder)

{

returnnull;

}

publicstaticboolContains(IEnumerable<Order>orders,Orderorder)

{

returnorders.Contains(order);

}

}

Andtheconcretetestusingthismatcher:

C#

varorder=newOrder{...};

varmock=newMock<IRepository<Order>>();

mock.Expect(x=>x.Save(Orders.Contains(order)))

.Throws<ArgumentException>();

//usemock,invokeSave,andhavethematcherfilter.

Page 206: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectAttributeMoq..::.MatcherAttribute

Page 207: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMatcherAttributeMembersMoqNamespace

[email protected]

Page 208: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMatcherAttributeMembersMatcherAttributeClassConstructorsSeeAlsoSendFeedback

TheMatcherAttributetypeexposesthefollowingmembers.

Page 209: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Constructors Name Description

MatcherAttribute InitializesanewinstanceoftheMatcherAttributeclass

Page 210: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMatcherAttributeClassMoqNamespace

[email protected]

Page 211: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMatcherAttributeConstructorMatcherAttributeClassSeeAlsoSendFeedbackInitializesanewinstanceoftheMatcherAttributeclass

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 212: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMatcherAttribute()

Page 213: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMatcherAttributeClassMoqNamespace

[email protected]

Page 214: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockClassMembersSeeAlsoSendFeedbackBaseclassformocksandstatichelperclasswithmethodsthatapplytomockedobjects,suchasGet<(Of<(T>)>)(T)toretrieveaMock<(Of<(T>)>)fromanobjectinstance.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 215: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicabstractclassMock:IMock

Page 216: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.MockMoq..::.Mock<(Of<(T>)>)

Page 218: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockMembersMockClassConstructorsMethodsPropertiesSeeAlsoSendFeedback

TheMocktypeexposesthefollowingmembers.

Page 219: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Constructors Name DescriptionMock Initializesthemock

Page 220: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

CreateEventHandler Overloaded.

Get<(Of<(T>)>) Retrievesthemockobjectforthegivenobjectinstance.

GetObject Returnsthemockedobjectvalue.Verify ImplementsVerify()()().VerifyAll ImplementsVerifyAll()()().

Page 221: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior ImplementsBehavior.CallBase ImplementsCallBase.DefaultValue ImplementsDefaultValue.

ImplementedInterfaces Exposesthelistofextrainterfacesimplementedbythemock.

Object Themockedobjectinstance.ImplementsObject.

Page 223: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockConstructorMockClassSeeAlsoSendFeedbackInitializesthemock

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 224: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedMock()

Page 226: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockMethodsMockClassSeeAlsoSendFeedback

TheMocktypeexposesthefollowingmembers.

Page 227: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

CreateEventHandler Overloaded.

Get<(Of<(T>)>) Retrievesthemockobjectforthegivenobjectinstance.

GetObject Returnsthemockedobjectvalue.Verify ImplementsVerify()()().VerifyAll ImplementsVerifyAll()()().

Page 229: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock..::.CreateEventHandlerMethodMockClassSeeAlsoSendFeedback

Page 230: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

CreateEventHandler<(Of<(TEventArgs>)>)()()()

ImplementsCreateEventHandler<(Of<(TEventArgs>)>)()()().

CreateEventHandler()()() ImplementsCreateEventHandler()()()

Page 231: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockClassMockMembersMoqNamespace

[email protected]

Page 232: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.CreateEventHandler<(Of<(TEventArgs>)>)MethodMockClassSeeAlsoSendFeedbackImplementsCreateEventHandler<(Of<(TEventArgs>)>)()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 233: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMockedEvent<TEventArgs>CreateEventHandler<TEventArgs>()

whereTEventArgs:EventArgs

Page 234: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTEventArgs

Typeofeventargumentclass.

Page 235: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockClassCreateEventHandlerOverloadMoqNamespace

[email protected]

Page 236: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.CreateEventHandlerMethodMockClassSeeAlsoSendFeedbackImplementsCreateEventHandler()()()

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 237: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMockedEvent<EventArgs>CreateEventHandler()

Page 238: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockClassCreateEventHandlerOverloadMoqNamespace

[email protected]

Page 239: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.Get<(Of<(T>)>)MethodMockClassExampleSeeAlsoSendFeedbackRetrievesthemockobjectforthegivenobjectinstance.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 240: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticIMock<T>Get<T>(

Tmocked

)

whereT:class

Parameters

mockedType:TTheinstanceofthemockedobject.

Page 241: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typeofthemocktoretrieve.Canbeomittedasit'sinferredfromtheobjectinstancepassedinasthemockedinstance.

ReturnValue

Themockassociatedwiththemockedobject.

Page 242: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoaddanewexpectationtoanobjectinstancewhichisnottheoriginalMock<(Of<(T>)>)butrathertheobjectassociatedwithit:

C#

//Typedinstance,notthemock,isretrievedfromsometestAPI.

HttpContextBasecontext=GetMockContext();

//context.Requestisthetypedobjectfromthe"real"API

//soinordertoaddanexpectationtoit,weneedtoget

//themockthat"owns"it

Mock<HttpRequestBase>request=Mock.Get(context.Request);

mock.Expect(req=>req.AppRelativeCurrentExecutionFilePath)

.Returns(tempUrl);

Page 243: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

ArgumentException ThereceivedmockedinstancewasnotcreatedbyMoq.

Page 245: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.GetObjectMethodMockClassSeeAlsoSendFeedbackReturnsthemockedobjectvalue.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 246: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedabstractObjectGetObject()

Page 248: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.VerifyMethodMockClassSeeAlsoSendFeedbackImplementsVerify()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 249: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicabstractvoidVerify()

Implements

IMock..::.Verify()()()

Page 251: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.VerifyAllMethodMockClassSeeAlsoSendFeedbackImplementsVerifyAll()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 252: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicabstractvoidVerifyAll()

Implements

IMock..::.VerifyAll()()()

Page 254: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockPropertiesMockClassSeeAlsoSendFeedback

TheMocktypeexposesthefollowingmembers.

Page 255: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior ImplementsBehavior.CallBase ImplementsCallBase.DefaultValue ImplementsDefaultValue.

ImplementedInterfaces Exposesthelistofextrainterfacesimplementedbythemock.

Object Themockedobjectinstance.ImplementsObject.

Page 257: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.BehaviorPropertyMockClassSeeAlsoSendFeedbackImplementsBehavior.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 258: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMockBehaviorBehavior{get;internalset;}

Page 260: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.CallBasePropertyMockClassSeeAlsoSendFeedbackImplementsCallBase.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 261: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicboolCallBase{get;set;}

Implements

IMock..::.CallBase

Page 263: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.DefaultValuePropertyMockClassSeeAlsoSendFeedbackImplementsDefaultValue.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 264: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicDefaultValueDefaultValue{get;set;}

Implements

IMock..::.DefaultValue

Page 266: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.ImplementedInterfacesPropertyMockClassSeeAlsoSendFeedbackExposesthelistofextrainterfacesimplementedbythemock.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 267: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedinternalList<Type>ImplementedInterfaces{get;privateset

Page 269: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock..::.ObjectPropertyMockClassSeeAlsoSendFeedbackThemockedobjectinstance.ImplementsObject.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 270: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicObjectObject{get;}

Implements

IMock..::.Object

Page 272: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)ClassMembersSeeAlsoSendFeedbackCoreimplementationoftheIMock<(Of<(T>)>)interface.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 273: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicclassMock<T>:Mock,IMock<T>

whereT:class

Page 274: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

Page 275: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.MockMoq..::.Mock<(Of<(T>)>)

Page 276: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)MembersMoqNamespaceMoq..::.IMock<(Of<(T>)>)

[email protected]

Page 277: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)MembersMock<(Of<(T>)>)ClassConstructorsMethodsPropertiesSeeAlsoSendFeedback

TheMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 278: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Constructors Name DescriptionMock<(Of<(T>)>) Overloaded.

Page 279: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

As<(Of<(TInterface>)>) ImplementsAs<(Of<(TInterface>)>)()()().

CreateEventHandler<(Of<(TEventArgs>)>)

ImplementsCreateEventHandler<(Of<(TEventArgs>)>)()()().(InheritedfromMock.)

Expect Overloaded.

ExpectGet<(Of<(TProperty>)>)

ImplementsExpectGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

ExpectSet Overloaded.

GetObject Returnsthemockedobjectvalue.(OverridesMock..::.GetObject()()().)

Verify Overloaded.

VerifyAll ImplementsVerifyAll()()().(OverridesMock..::.VerifyAll()()().)

VerifyGet<(Of<(TProperty>)>)

ImplementsVerifyGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

VerifySet Overloaded.

Page 280: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior ImplementsBehavior.(InheritedfromMock.)

CallBase ImplementsCallBase.(InheritedfromMock.)

DefaultValue ImplementsDefaultValue.(InheritedfromMock.)

ImplementedInterfacesExposesthelistofextrainterfacesimplementedbythemock.(InheritedfromMock.)

Object Exposesthemockedobjectinstance.

Page 281: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 282: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)ConstructorMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

Page 283: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Mock<(Of<(T>)>)()()() Initializesaninstanceofthemockwithdefaultbehavior.

Mock<(Of<(T>)>)(MockBehavior)

Initializesaninstanceofthemockwiththespecifiedbehavior.

Mock<(Of<(T>)>)(array<Object>[]()[])

Initializesaninstanceofthemockwithdefaultbehaviorandwiththegivenconstructorargumentsfortheclass.(OnlyvalidwhenTisaclass)

Mock<(Of<(T>)>)(MockBehavior,array<Object>[]()[])

Initializesaninstanceofthemockwithaspecificbehaviorwiththegivenconstructorargumentsfortheclass.

Page 284: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 285: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)ConstructorMock<(Of<(T>)>)ClassExampleSeeAlsoSendFeedbackInitializesaninstanceofthemockwithdefaultbehavior.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 286: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock()

Page 287: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<IFormatProvider>();

Page 288: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace

[email protected]

Page 289: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)Constructor(MockBehavior)Mock<(Of<(T>)>)ClassExampleSeeAlsoSendFeedbackInitializesaninstanceofthemockwiththespecifiedbehavior.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 290: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock(

MockBehaviorbehavior

)

Parameters

behaviorType:Moq..::.MockBehaviorBehaviorofthemock.

Page 291: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<IFormatProvider>(MockBehavior.Relaxed);

Page 292: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace

[email protected]

Page 293: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)Constructor(array<>[]()[])Mock<(Of<(T>)>)ClassExampleSeeAlsoSendFeedbackInitializesaninstanceofthemockwithdefaultbehaviorandwiththegivenconstructorargumentsfortheclass.(OnlyvalidwhenTisaclass)

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 294: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock(

paramsObject[]args

)

Parameters

argsType:array<Object>[]()[]Optionalconstructorargumentsifthemockedtypeisaclass.

Page 295: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThemockwilltrytofindthebestmatchconstructorgiventheconstructorarguments,andinvokethattoinitializetheinstance.Thisappliesonlyforclasses,notinterfaces.

Page 296: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<MyProvider>(someArgument,25);

Page 297: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace

[email protected]

Page 298: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)Constructor(MockBehavior,array<>[]()[])Mock<(Of<(T>)>)ClassExampleSeeAlsoSendFeedbackInitializesaninstanceofthemockwithaspecificbehaviorwiththegivenconstructorargumentsfortheclass.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 299: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock(

MockBehaviorbehavior,

paramsObject[]args

)

Parameters

behaviorType:Moq..::.MockBehaviorBehaviorofthemock.

argsType:array<Object>[]()[]Optionalconstructorargumentsifthemockedtypeisaclass.

Page 300: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThemockwilltrytofindthebestmatchconstructorgiventheconstructorarguments,andinvokethattoinitializetheinstance.Thisappliesonlytoclasses,notinterfaces.

Page 301: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<MyProvider>(someArgument,25);

Page 302: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace

[email protected]

Page 303: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)MethodsMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

TheMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 304: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

As<(Of<(TInterface>)>) ImplementsAs<(Of<(TInterface>)>)()()().

CreateEventHandler<(Of<(TEventArgs>)>)

ImplementsCreateEventHandler<(Of<(TEventArgs>)>)()()().(InheritedfromMock.)

Expect Overloaded.

ExpectGet<(Of<(TProperty>)>)

ImplementsExpectGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

ExpectSet Overloaded.

GetObject Returnsthemockedobjectvalue.(OverridesMock..::.GetObject()()().)

Verify Overloaded.

VerifyAll ImplementsVerifyAll()()().(OverridesMock..::.VerifyAll()()().)

VerifyGet<(Of<(TProperty>)>)

ImplementsVerifyGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

VerifySet Overloaded.

Page 305: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 306: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.As<(Of<(TInterface>)>)MethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsAs<(Of<(TInterface>)>)()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 307: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualIMock<TInterface>As<TInterface>()

whereTInterface:class

Page 308: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTInterface

Typeofinterfacetocastthemockto.

Page 309: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 310: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)..::.ExpectMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

Page 311: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Expect(Expression<(Of<(Action<(Of<(T>)>)>)>))

ImplementsExpect(Expression<(Of<(Action<(Of<(T>)>)>)>)).

Expect<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>))

ImplementsExpect<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)).

Page 312: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 313: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.ExpectMethod(<(Of<(<(Of<(T>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsExpect(Expression<(Of<(Action<(Of<(T>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 314: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicIExpectExpect(

Expression<Action<T>>expression

)

Parameters

expressionType:Expression<(Of<(Action<(Of<(T>)>)>)>)Lambdaexpressionthatspecifiestheexpectedmethodinvocation.

Implements

IMock<(Of<(T>)>)..::.Expect<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>))

Page 315: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassExpectOverloadMoqNamespace

[email protected]

Page 316: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.Expect<(Of<(TResult>)>)Method(<(Of<(<(Of<(T,TResult>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsExpect<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 317: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicIExpect<TResult>Expect<TResult>(

Expression<Func<T,TResult>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)Lambdaexpressionthatspecifiestheexpectedmethodinvocation.

Page 318: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofthereturnvalue.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 319: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassExpectOverloadMoqNamespace

[email protected]

Page 320: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.ExpectGet<(Of<(TProperty>)>)MethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsExpectGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 321: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicIExpectGetter<TProperty>ExpectGet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertygetter.

Page 322: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 323: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 324: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)..::.ExpectSetMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

Page 325: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

ImplementsExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

ImplementsExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty).

Page 326: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 327: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 328: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicIExpectSetter<TProperty>ExpectSet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertysetter.

Page 329: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 330: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassExpectSetOverloadMoqNamespace

[email protected]

Page 331: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>),TProperty)Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 332: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicIExpectSetter<TProperty>ExpectSet<TProperty>(

Expression<Func<T,TProperty>>expression,

TPropertyvalue

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Lambdaexpressionthatspecifiestheexpectedpropertysetter.

valueType:TPropertyThevalueexpectedtobesetfortheproperty.

Page 333: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.Typicallyomittedasitcanbeinferredfromtheexpression.

Page 334: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassExpectSetOverloadMoqNamespace

[email protected]

Page 335: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.GetObjectMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackReturnsthemockedobjectvalue.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 336: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedoverrideObjectGetObject()

Page 337: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 338: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)..::.VerifyMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

Page 339: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Verify()()() ImplementsVerify()()().(OverridesMock..::.Verify()()().)

Verify(Expression<(Of<(Action<(Of<(T>)>)>)>))

ImplementsVerify(Expression<(Of<(Action<(Of<(T>)>)>)>)).

Verify<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>))

ImplementsVerify<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)).

Page 340: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 341: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifyMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerify()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 342: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicoverridevoidVerify()

Implements

IMock<(Of<(T>)>)..::.Verify()()()IMock..::.Verify()()()

Page 343: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace

[email protected]

Page 344: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifyMethod(<(Of<(<(Of<(T>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerify(Expression<(Of<(Action<(Of<(T>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 345: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerify(

Expression<Action<T>>expression

)

Parameters

expressionType:Expression<(Of<(Action<(Of<(T>)>)>)>)Expressiontoverify.

Implements

IMock<(Of<(T>)>)..::.Verify(Expression<(Of<(Action<(Of<(T>)>)>)>))

Page 346: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace

[email protected]

Page 347: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.Verify<(Of<(TResult>)>)Method(<(Of<(<(Of<(T,TResult>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerify<(Of<(TResult>)>)(Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 348: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerify<TResult>(

Expression<Func<T,TResult>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TResult>)>)>)>)Expressiontoverify.

Page 349: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofreturnvaluefromtheexpression.

Implements

IMock<(Of<(T>)>)..::.Verify(Expression<(Of<(Action<(Of<(T>)>)>)>))

Page 350: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace

[email protected]

Page 351: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifyAllMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerifyAll()()().

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 352: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicoverridevoidVerifyAll()

Implements

IMock<(Of<(T>)>)..::.VerifyAll()()()IMock..::.VerifyAll()()()

Page 353: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 354: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifyGet<(Of<(TProperty>)>)MethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerifyGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 355: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerifyGet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

Page 356: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Implements

IMock<(Of<(T>)>)..::.VerifyGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

Page 357: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 358: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)..::.VerifySetMethodMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

Page 359: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

ImplementsVerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

ImplementsVerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty).

Page 360: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace

[email protected]

Page 361: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>))Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 362: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerifySet<TProperty>(

Expression<Func<T,TProperty>>expression

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

Page 363: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Implements

IMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

Page 364: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassVerifySetOverloadMoqNamespace

[email protected]

Page 365: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)Method(<(Of<(<(Of<(T,TProperty>)>)>)>),TProperty)Mock<(Of<(T>)>)ClassSeeAlsoSendFeedbackImplementsVerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 366: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerifySet<TProperty>(

Expression<Func<T,TProperty>>expression,

TPropertyvalue

)

Parameters

expressionType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Expressiontoverify.

valueType:TPropertyThevaluethatshouldhavebeensetontheproperty.

Page 367: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeofthepropertytoverify.Typicallyomittedasitcanbeinferredfromtheexpression'sreturntype.

Implements

IMock<(Of<(T>)>)..::.VerifySet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

Page 368: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassVerifySetOverloadMoqNamespace

[email protected]

Page 369: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMock<(Of<(T>)>)PropertiesMock<(Of<(T>)>)ClassSeeAlsoSendFeedback

TheMock<(Of<(T>)>)typeexposesthefollowingmembers.

Page 370: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

Behavior ImplementsBehavior.(InheritedfromMock.)

CallBase ImplementsCallBase.(InheritedfromMock.)

DefaultValue ImplementsDefaultValue.(InheritedfromMock.)

ImplementedInterfacesExposesthelistofextrainterfacesimplementedbythemock.(InheritedfromMock.)

Object Exposesthemockedobjectinstance.

Page 371: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 372: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMock<(Of<(T>)>)..::.ObjectPropertyMock<(Of<(T>)>)ClassSeeAlsoSendFeedbackExposesthemockedobjectinstance.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 373: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicTObject{get;}

Implements

IMock<(Of<(T>)>)..::.Object

Page 374: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace

[email protected]

Page 375: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockBehaviorEnumerationSeeAlsoSendFeedbackOptionstocustomizethebehaviorofthemock.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 376: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicenumMockBehavior

Page 377: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

MembersMembername Description

Strict Causesthemocktoalwaysthrowanexceptionforinvocationsthatdon'thaveacorrespondingexpectation.

LooseWillneverthrowexceptions,returningdefaultvalueswhennecessary(nullforreferencetypes,zeroforvaluetypesoremptyenumerablesandarrays).

Default Defaultmockbehavior,whichequalsLoose.

Page 379: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEventClassMembersSeeAlsoSendFeedbackRepresentsagenericeventthathasbeenmockedandcanberised.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 380: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicclassMockedEvent

Page 381: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.MockedEventMoq..::.MockedEvent<(Of<(TEventArgs>)>)

Page 382: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventMembersMoqNamespace

[email protected]

Page 383: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEventMembersMockedEventClassMethodsEventsSeeAlsoSendFeedback

TheMockedEventtypeexposesthefollowingmembers.

Page 384: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Operators Name Description

Implicit ProvidessupportforattachingaMockedEventtoagenericEventHandlerevent.

Page 385: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Events Name Description

Raised Eventraisedwheneverthemockedeventisrised.

Page 386: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventClassMoqNamespace

[email protected]

Page 387: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEventMethodsMockedEventClassSeeAlsoSendFeedback

TheMockedEventtypeexposesthefollowingmembers.

Page 388: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Operators Name Description

Implicit ProvidessupportforattachingaMockedEventtoagenericEventHandlerevent.

Page 389: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventClassMoqNamespace

[email protected]

Page 390: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEvent..::.ImplicitOperatorMockedEventClassSeeAlsoSendFeedbackProvidessupportforattachingaMockedEventtoagenericEventHandlerevent.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 391: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticimplicitoperatorEventHandler(

MockedEventmockEvent

)

Parameters

mockEventType:Moq..::.MockedEventEventtoconvert.

Page 392: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventClassMoqNamespace

[email protected]

Page 393: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEventEventsMockedEventClassSeeAlsoSendFeedback

TheMockedEventtypeexposesthefollowingmembers.

Page 394: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Events Name Description

Raised Eventraisedwheneverthemockedeventisrised.

Page 395: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventClassMoqNamespace

[email protected]

Page 396: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEvent..::.RaisedEventMockedEventClassSeeAlsoSendFeedbackEventraisedwheneverthemockedeventisrised.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 397: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publiceventEventHandlerRaised

Page 398: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEventClassMoqNamespace

[email protected]

Page 399: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEvent<(Of<(TEventArgs>)>)ClassMembersSeeAlsoSendFeedbackProvidesatypedMockedEventforaspecifictypeofEventArgs.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 400: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicclassMockedEvent<TEventArgs>:MockedEvent

whereTEventArgs:EventArgs

Page 401: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTEventArgs

Thetypeofeventargumentsrequiredbytheevent.

Page 402: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThemockedeventcaneitherbeaEventHandlerorcustomeventhandlerwhichfollows.NETpracticeofprovidingobjectsender,EventArgsargskindofsignature.

Page 403: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.MockedEventMoq..::.MockedEvent<(Of<(TEventArgs>)>)

Page 404: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)MembersMoqNamespace

[email protected]

Page 405: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEvent<(Of<(TEventArgs>)>)MembersMockedEvent<(Of<(TEventArgs>)>)ClassMethodsEventsSeeAlsoSendFeedback

TheMockedEvent<(Of<(TEventArgs>)>)typeexposesthefollowingmembers.

Page 406: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Raise Raisestheassociatedeventwiththegiveneventargumentdata.

Page 407: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Operators Name Description

Implicit ProvidessupportforattachingaMockedEvent<(Of<(TEventArgs>)>)toagenericEventHandlerevent.

Page 408: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Events Name Description

Raised Eventraisedwheneverthemockedeventisrised.(InheritedfromMockedEvent.)

Page 409: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace

[email protected]

Page 410: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEvent<(Of<(TEventArgs>)>)MethodsMockedEvent<(Of<(TEventArgs>)>)ClassSeeAlsoSendFeedback

TheMockedEvent<(Of<(TEventArgs>)>)typeexposesthefollowingmembers.

Page 411: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Raise Raisestheassociatedeventwiththegiveneventargumentdata.

Page 412: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Operators Name Description

Implicit ProvidessupportforattachingaMockedEvent<(Of<(TEventArgs>)>)toagenericEventHandlerevent.

Page 413: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace

[email protected]

Page 414: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEvent<(Of<(TEventArgs>)>)..::.ImplicitOperatorMockedEvent<(Of<(TEventArgs>)>)ClassSeeAlsoSendFeedbackProvidessupportforattachingaMockedEvent<(Of<(TEventArgs>)>)toagenericEventHandlerevent.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 415: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticimplicitoperatorEventHandler<TEventArgs>(

MockedEvent<TEventArgs>mockEvent

)

Parameters

mockEventType:Moq..::.MockedEvent<(Of<(TEventArgs>)>)Eventtoconvert.

Page 416: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace

[email protected]

Page 417: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockedEvent<(Of<(TEventArgs>)>)..::.RaiseMethodMockedEvent<(Of<(TEventArgs>)>)ClassSeeAlsoSendFeedbackRaisestheassociatedeventwiththegiveneventargumentdata.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 418: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvoidRaise(

TEventArgsargs

)

Parameters

argsType:TEventArgsDatatopasstotheevent.

Page 419: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace

[email protected]

Page 420: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockedEvent<(Of<(TEventArgs>)>)EventsMockedEvent<(Of<(TEventArgs>)>)ClassSeeAlsoSendFeedback

TheMockedEvent<(Of<(TEventArgs>)>)typeexposesthefollowingmembers.

Page 421: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Events Name Description

Raised Eventraisedwheneverthemockedeventisrised.(InheritedfromMockedEvent.)

Page 422: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace

[email protected]

Page 423: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockExceptionClassMembersSeeAlsoSendFeedbackExceptionthrownbymockswhenexpectationsarenotmet,themockisnotproperlysetup,etc.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 424: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

[SerializableAttribute]

publicclassMockException:Exception

Page 425: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksAdistinctexceptiontypeisprovidedsothatexceptionsthrownbythemockcanbedifferentiatedinteststhatexpectotherexceptionstobethrown(i.e.ArgumentException).

Richerexceptionhierarchy/typesarenotprovidedasteststypicallyshouldnotcatchorexpectexceptionsfromthemocks.Thesearetypicallytheresultofchangesinthetestedclassoritscollaboratorsimplementation,andresultinfixesinthemocksetupsothattheydissapearandallowthetesttopass.

Page 426: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectExceptionMoq..::.MockException

Page 427: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockExceptionMembersMoqNamespace

[email protected]

Page 428: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockExceptionMembersMockExceptionClassConstructorsMethodsSeeAlsoSendFeedback

TheMockExceptiontypeexposesthefollowingmembers.

Page 429: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Constructors Name Description

MockException Supportstheserializationinfrastructure.

Page 430: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

GetObjectDataSupportstheserializationinfrastructure.(OverridesExceptionGetObjectData(SerializationInfo,StreamingContext).)

Page 431: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockExceptionClassMoqNamespace

[email protected]

Page 432: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockExceptionConstructorMockExceptionClassSeeAlsoSendFeedbackSupportstheserializationinfrastructure.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 433: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedMockException(

SerializationInfoinfo,

StreamingContextcontext

)

Parameters

infoType:SerializationInfoSerializationinformation.

contextType:StreamingContextStreamingcontext.

Page 434: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockExceptionClassMoqNamespace

[email protected]

Page 435: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockExceptionMethodsMockExceptionClassSeeAlsoSendFeedback

TheMockExceptiontypeexposesthefollowingmembers.

Page 436: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

GetObjectDataSupportstheserializationinfrastructure.(OverridesExceptionGetObjectData(SerializationInfo,StreamingContext).)

Page 437: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockExceptionClassMoqNamespace

[email protected]

Page 438: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockException..::.GetObjectDataMethodMockExceptionClassSeeAlsoSendFeedbackSupportstheserializationinfrastructure.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 439: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicoverridevoidGetObjectData(

SerializationInfoinfo,

StreamingContextcontext

)

Parameters

infoType:SerializationInfoSerializationinformation.

contextType:StreamingContextStreamingcontext.

Implements

ISerializableGetObjectData(SerializationInfo,StreamingContext)_ExceptionGetObjectData(SerializationInfo,StreamingContext)

Page 440: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockExceptionClassMoqNamespace

[email protected]

Page 441: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactoryClassMembersExampleSeeAlsoSendFeedbackUtilityfactoryclasstousetoconstructmultiplemockswhenconsistentverificationisdesiredforallofthem.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 442: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicclassMockFactory

Page 443: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfmultiplemockswillbecreatedduringatest,passingthedesiredMockBehavior(ifdifferentthantheDefaultortheonepassedtothefactoryconstructor)andlaterverifyingeachmockcanbecomerepetitiveandtedious.

ThisfactoryclasshelpsinthatscenariobyprovidingasimplifiedcreationofmultiplemockswithadefaultMockBehavior(unlessoverridenbycallingCreate<(Of<(T>)>)(MockBehavior))andposteriorverification.

Page 444: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesThefollowingisastraightforwardexampleonhowtocreateandautomaticallyverifystrictmocksusingaMockFactory:

C#

varfactory=newMockFactory(MockBehavior.Strict);

varfoo=factory.Create<IFoo>();

varbar=factory.Create<IBar>();

//noneedtocallVerifiable()ontheexpectation

//aswe'llbevalidatingallexpectationsanyway.

foo.Expect(f=>f.Do());

bar.Expect(b=>b.Redo());

//exercisethemockshere

factory.VerifyAll();

//Atthispointallexpectationsarealreadychecked

//andanoptionalMockExceptionmightbethrown.

//Notealsothatbecausethemocksarestrict,anyinvocation

//thatdoesn'thaveamatchingexpectationwillalsothrowaMockException.

Thefollowingexamplesshowshowtosetupthefactorytocreateloosemocksandlaterverifyonlyverifiableexpectations:

C#

varfactory=newMockFactory(MockBehavior.Loose);

varfoo=factory.Create<IFoo>();

varbar=factory.Create<IBar>();

//thisexpectationwillbeverifiedattheendofthe"using"block

foo.Expect(f=>f.Do()).Verifiable();

//thisexpectationwillNOTbeverified

foo.Expect(f=>f.Calculate());

//thisexpectationwillbeverifiedattheendofthe"using"block

bar.Expect(b=>b.Redo()).Verifiable();

Page 445: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

//exercisethemockshere

//notethatbecausethemocksareLoose,members

//calledintheinterfacesforwhichnomatching

//expectationsexistwillNOTthrowexceptions,

//andwillratherreturndefaultvalues.

factory.Verify();

//Atthispointverifiableexpectationsarealreadychecked

//andanoptionalMockExceptionmightbethrown.

Thefollowingexamplesshowshowtosetupthefactorywithadefaultstrictbehavior,overridingthatdefaultforaspecificmock:

C#

varfactory=newMockFactory(MockBehavior.Strict);

//thisparticularonewewantloose

varfoo=factory.Create<IFoo>(MockBehavior.Loose);

varbar=factory.Create<IBar>();

//setexpectations

//exercisethemockshere

factory.Verify();

Page 446: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq..::.MockFactory

Page 447: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryMembersMoqNamespaceMoq..::.MockBehavior

[email protected]

Page 448: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockFactoryMembersMockFactoryClassConstructorsMethodsPropertiesSeeAlsoSendFeedback

TheMockFactorytypeexposesthefollowingmembers.

Page 449: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Constructors Name Description

MockFactory InitializesthefactorywiththegivendefaultBehaviorfornewlycreatedmocksfromthefactory.

Page 450: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Create Overloaded.CreateMock<(Of<(T>)>)

Implementscreationofanewmockwithinthefactory.

Verify Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.

VerifyAll Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.

VerifyMocksInvokesverifyActionforeachmockinMocks,andaccumulatestheresultingMockVerificationExceptionthatmightbethrownfromtheaction.

Page 451: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocationsonloosemocks.

Mocks Getsthemocksthathavebeencreatedbythisfactoryandthatwillgetverifiedtogether.

Page 452: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 453: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactoryConstructorMockFactoryClassSeeAlsoSendFeedbackInitializesthefactorywiththegivendefaultBehaviorfornewlycreatedmocksfromthefactory.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 454: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMockFactory(

MockBehaviordefaultBehavior

)

Parameters

defaultBehaviorType:Moq..::.MockBehaviorThebehaviortouseformockscreatedusingtheCreate<(Of<(T>)>)()()()factorymethodifnotoverridenbyusingtheCreate<(Of<(T>)>)(MockBehavior)overload.

Page 455: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 456: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockFactoryMethodsMockFactoryClassSeeAlsoSendFeedback

TheMockFactorytypeexposesthefollowingmembers.

Page 457: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Create Overloaded.CreateMock<(Of<(T>)>)

Implementscreationofanewmockwithinthefactory.

Verify Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.

VerifyAll Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.

VerifyMocksInvokesverifyActionforeachmockinMocks,andaccumulatestheresultingMockVerificationExceptionthatmightbethrownfromtheaction.

Page 458: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 459: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockFactory..::.CreateMethodMockFactoryClassSeeAlsoSendFeedback

Page 460: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Create<(Of<(T>)>)()()()CreatesanewmockwiththedefaultMockBehaviorspecifiedatfactoryconstructiontime.

Create<(Of<(T>)>)(MockBehavior)

Createsanewmockwiththegivenbehavior.

Create<(Of<(T>)>)(array<Object>[]()[])

CreatesanewmockwiththedefaultMockBehaviorspecifiedatfactoryconstructiontimeandwiththethegivenconstructorargumentsfortheclass.

Create<(Of<(T>)>)(MockBehavior,array<Object>[]()[])

Createsanewmockwiththegivenbehaviorandwiththethegivenconstructorargumentsfortheclass.

Page 461: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMockFactoryMembersMoqNamespace

[email protected]

Page 462: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.Create<(Of<(T>)>)MethodMockFactoryClassExampleSeeAlsoSendFeedbackCreatesanewmockwiththedefaultMockBehaviorspecifiedatfactoryconstructiontime.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 463: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock<T>Create<T>()

whereT:class

Page 464: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

ReturnValue

AnewMock<(Of<(T>)>).

Page 465: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varfactory=newMockFactory(MockBehavior.Strict);

varfoo=factory.Create<IFoo>();

//usemockontests

factory.VerifyAll();

Page 466: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassCreateOverloadMoqNamespace

[email protected]

Page 467: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.Create<(Of<(T>)>)Method(MockBehavior)MockFactoryClassExampleSeeAlsoSendFeedbackCreatesanewmockwiththegivenbehavior.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 468: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock<T>Create<T>(

MockBehaviorbehavior

)

whereT:class

Parameters

behaviorType:Moq..::.MockBehaviorBehaviortouseforthemock,whichoverridesthedefaultbehaviorspecifiedatfactoryconstructiontime.

Page 469: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

ReturnValue

AnewMock<(Of<(T>)>).

Page 470: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtocreateamockwithadifferentbehaviortothatspecifiedasthedefaultforthefactory:

C#

varfactory=newMockFactory(MockBehavior.Strict);

varfoo=factory.Create<IFoo>(MockBehavior.Loose);

Page 471: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassCreateOverloadMoqNamespace

[email protected]

Page 472: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.Create<(Of<(T>)>)Method(array<>[]()[])MockFactoryClassExampleSeeAlsoSendFeedbackCreatesanewmockwiththedefaultMockBehaviorspecifiedatfactoryconstructiontimeandwiththethegivenconstructorargumentsfortheclass.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 473: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock<T>Create<T>(

paramsObject[]args

)

whereT:class

Parameters

argsType:array<Object>[]()[]Constructorargumentsformockedclasses.

Page 474: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

ReturnValue

AnewMock<(Of<(T>)>).

Page 475: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThemockwilltrytofindthebestmatchconstructorgiventheconstructorarguments,andinvokethattoinitializetheinstance.Thisappliesonlytoclasses,notinterfaces.

Page 476: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varfactory=newMockFactory(MockBehavior.Default);

varmock=factory.Create<MyBase>("Foo",25,true);

//usemockontests

factory.Verify();

Page 477: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassCreateOverloadMoqNamespace

[email protected]

Page 478: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.Create<(Of<(T>)>)Method(MockBehavior,array<>[]()[])MockFactoryClassExampleSeeAlsoSendFeedbackCreatesanewmockwiththegivenbehaviorandwiththethegivenconstructorargumentsfortheclass.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 479: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicMock<T>Create<T>(

MockBehaviorbehavior,

paramsObject[]args

)

whereT:class

Parameters

behaviorType:Moq..::.MockBehaviorBehaviortouseforthemock,whichoverridesthedefaultbehaviorspecifiedatfactoryconstructiontime.

argsType:array<Object>[]()[]Constructorargumentsformockedclasses.

Page 480: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

ReturnValue

AnewMock<(Of<(T>)>).

Page 481: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksThemockwilltrytofindthebestmatchconstructorgiventheconstructorarguments,andinvokethattoinitializetheinstance.Thisappliesonlytoclasses,notinterfaces.

Page 482: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtocreateamockwithadifferentbehaviortothatspecifiedasthedefaultforthefactory,passingconstructorarguments:

C#

varfactory=newMockFactory(MockBehavior.Default);

varmock=factory.Create<MyBase>(MockBehavior.Strict,"Foo",25,true

Page 483: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassCreateOverloadMoqNamespace

[email protected]

Page 484: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.CreateMock<(Of<(T>)>)MethodMockFactoryClassSeeAlsoSendFeedbackImplementscreationofanewmockwithinthefactory.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 485: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedvirtualMock<T>CreateMock<T>(

MockBehaviorbehavior,

Object[]args

)

whereT:class

Parameters

behaviorType:Moq..::.MockBehaviorThebehaviorforthenewmock.

argsType:array<Object>[]()[]Optionalargumentsfortheconstructionofthemock.

Page 486: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typetomock.

Page 487: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 488: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.VerifyMethodMockFactoryClassSeeAlsoSendFeedbackVerifiesallverifiableexpectationsonallmockscreatedbythisfactory.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 489: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerify()

Page 490: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Oneormoremockshadexpectationsthatwerenotsatisfied.

Page 491: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespaceMock<(Of<(T>)>)..::.Verify()()()

[email protected]

Page 492: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.VerifyAllMethodMockFactoryClassSeeAlsoSendFeedbackVerifiesallverifiableexpectationsonallmockscreatedbythisfactory.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 493: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicvirtualvoidVerifyAll()

Page 494: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

ExceptionsException Condition

Moq..::.MockException Oneormoremockshadexpectationsthatwerenotsatisfied.

Page 495: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespaceMock<(Of<(T>)>)..::.Verify()()()

[email protected]

Page 496: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.VerifyMocksMethodMockFactoryClassSeeAlsoSendFeedbackInvokesverifyActionforeachmockinMocks,andaccumulatestheresultingMockVerificationExceptionthatmightbethrownfromtheaction.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 497: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedvirtualvoidVerifyMocks(

Action<IMock>verifyAction

)

Parameters

verifyActionType:Action<(Of<(IMock>)>)Theactiontoexecuteagainsteachmock.

Page 498: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 499: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqMockFactoryPropertiesMockFactoryClassSeeAlsoSendFeedback

TheMockFactorytypeexposesthefollowingmembers.

Page 500: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Properties Name Description

CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocationsonloosemocks.

Mocks Getsthemocksthathavebeencreatedbythisfactoryandthatwillgetverifiedtogether.

Page 501: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 502: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.CallBasePropertyMockFactoryClassSeeAlsoSendFeedbackWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 503: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicboolCallBase{get;set;}

Page 504: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 505: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.DefaultValuePropertyMockFactoryClassSeeAlsoSendFeedbackSpecifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocationsonloosemocks.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 506: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicDefaultValueDefaultValue{get;set;}

Page 507: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 508: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMockFactory..::.MocksPropertyMockFactoryClassSeeAlsoSendFeedbackGetsthemocksthathavebeencreatedbythisfactoryandthatwillgetverifiedtogether.

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 509: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

protectedIEnumerable<IMock>Mocks{get;}

Page 510: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoMockFactoryClassMoqNamespace

[email protected]

Page 511: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqRangeEnumerationSeeAlsoSendFeedbackKindofrangetouseinafilterspecifiedthroughIsInRange<(Of<(TValue>)>)(TValue,TValue,Range).

Namespace:MoqAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 512: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicenumRange

Page 513: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

MembersMembername DescriptionInclusive Therangeincludesthetoandfromvalues.Exclusive Therangedoesnotincludethetoandfromvalues.

Page 515: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMoq.LanguageNamespaceSendFeedbackThisnamespacedefinestheinterfacesthatcontainthemethodsavailableinMoqfluentAPI,suchasExpect,Callback,Returns,Throws,etc.

Reviewthedocumentationoftheavailablemethodsontheseinterfacesforcodeexamples.Thewaytheseinterfacesarecomposed,groupedandmadevisibleatdifferentstagesduringanexpectation(i.e.Verifiableisthelast"verb"andcan'tbespecifiedbeforetheReturns)isinternalbuttheAPIwillnaturallyleadyoutotheproperwayofusingit,sodon'tworrytoomuchaboutwho(andwhere)exposestheselanguageinterfaces.TheywillshowupinIntellisensewhenit'sappropriate.

Dousetheirdocumentationtolearnaboutoptions(especiallywhenthereareseveraloverloadsavailable)thatmaybeabetterfitforaparticularscenario.

Page 516: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Interfaces Interface Description

ICallback DefinestheCallbackverbandoverloads.ICallback<(Of<(TResult>)>)

DefinestheCallbackverbandoverloadsforcallbacksonexpectationsthatreturnavalue.

ICallbackGetter<(Of<(TProperty>)>)

DefinestheCallbackverbforpropertygetterexpectations.

ICallbackSetter<(Of<(TProperty>)>)

DefinestheCallbackverbforpropertysetterexpectations.

INever DefinestheNeververb.

IOccurrence Definesoccurrencememberstoconstraintexpectations.

IRaise DefinestheRaisesverb.IReturns BaseinterfaceforIReturns<(Of<(TResult>)>).IReturns<(Of<(TResult>)>) DefinestheReturnsverb.

IReturnsGetter<(Of<(TProperty>)>)

DefinestheReturnsverbforpropertygetexpectations.

IThrows DefinestheThrowsverb.IVerifies DefinestheVerifiableverb.

[email protected]

Page 517: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallbackInterfaceMembersSeeAlsoSendFeedbackDefinestheCallbackverbandoverloads.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 518: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceICallback

Page 519: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackMembersMoq.LanguageNamespace

[email protected]

Page 520: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackMembersICallbackInterfaceMethodsSeeAlsoSendFeedback

Page 521: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionCallback Overloaded.

Page 522: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceMoq.LanguageNamespace

[email protected]

Page 523: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackMethodsICallbackInterfaceSeeAlsoSendFeedback

Page 524: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionCallback Overloaded.

Page 525: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceMoq.LanguageNamespace

[email protected]

Page 526: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallback..::.CallbackMethodICallbackInterfaceSeeAlsoSendFeedback

Page 527: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Callback(Action) Specifiesacallbacktoinvokewhenthemethodiscalled.

Callback<(Of<(T>)>)(Action<(Of<(T>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2>)>)(Action<(Of<(T1,T2>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2,T3>)>)(Action<(Of<(T1,T2,T3>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2,T3,T4>)>)(Action<(Of<(T1,T2,T3,T4>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Page 528: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceICallbackMembersMoq.LanguageNamespace

[email protected]

Page 529: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback..::.CallbackMethod()ICallbackInterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalled.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 530: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback(

Actioncallback

)

Parameters

callbackType:ActionCallbackmethodtoinvoke.

Page 531: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexamplespecifiesacallbacktosetabooleanvaluethatcanbeusedlater:

C#

boolcalled=false;

mock.Expect(x=>x.Execute())

.Callback(()=>called=true);

Page 532: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 533: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback..::.Callback<(Of<(T>)>)Method(<(Of<(T>)>))ICallbackInterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 534: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback<T>(

Action<T>callback

)

Parameters

callbackType:Action<(Of<(T>)>)Callbackmethodtoinvoke.

Page 535: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Argumenttypeoftheinvokedmethod.

Page 536: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentvalue.

Noticehowthespecificstringargumentisretrievedbysimplydeclaringitaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(It.IsAny<string>()))

.Callback((stringcommand)=>Console.WriteLine(command));

Page 537: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 538: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback..::.Callback<(Of<(T1,T2>)>)Method(<(Of<(T1,T2>)>))ICallbackInterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 539: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback<T1,T2>(

Action<T1,T2>callback

)

Parameters

callbackType:Action<(Of<(T1,T2>)>)Callbackmethodtoinvoke.

Page 540: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.

Page 541: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>()))

.Callback((stringarg1,stringarg2)=>Console.WriteLine(arg1+arg2));

Page 542: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 543: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback..::.Callback<(Of<(T1,T2,T3>)>)Method(<(Of<(T1,T2,T3>)>))ICallbackInterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 544: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback<T1,T2,T3>(

Action<T1,T2,T3>callback

)

Parameters

callbackType:Action<(Of<(T1,T2,T3>)>)Callbackmethodtoinvoke.

Page 545: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.

Page 546: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>()))

.Callback((stringarg1,stringarg2,intarg3)=>Console.WriteLine(arg1+arg2+arg3));

Page 547: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 548: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback..::.Callback<(Of<(T1,T2,T3,T4>)>)Method(<(Of<(T1,T2,T3,T4>)>))ICallbackInterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 549: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback<T1,T2,T3,T4>(

Action<T1,T2,T3,T4>callback

)

Parameters

callbackType:Action<(Of<(T1,T2,T3,T4>)>)Callbackmethodtoinvoke.

Page 550: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.T4

Typeofthefourthargumentoftheinvokedmethod.

Page 551: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>(),

It.IsAny<bool>()))

.Callback((stringarg1,stringarg2,intarg3,boolarg4)=>Console.WriteLine(arg1+arg2+arg3+arg4));

Page 552: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 553: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)InterfaceMembersSeeAlsoSendFeedbackDefinestheCallbackverbandoverloadsforcallbacksonexpectationsthatreturnavalue.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 554: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceICallback<TResult>

Page 555: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofthereturnvalueoftheexpectation.

Page 556: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)MembersMoq.LanguageNamespace

[email protected]

Page 557: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallback<(Of<(TResult>)>)MembersICallback<(Of<(TResult>)>)InterfaceMethodsSeeAlsoSendFeedback

Page 558: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionCallback Overloaded.

Page 559: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 560: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallback<(Of<(TResult>)>)MethodsICallback<(Of<(TResult>)>)InterfaceSeeAlsoSendFeedback

Page 561: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionCallback Overloaded.

Page 562: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 563: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallback<(Of<(TResult>)>)..::.CallbackMethodICallback<(Of<(TResult>)>)InterfaceSeeAlsoSendFeedback

Page 564: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Callback(Action) Specifiesacallbacktoinvokewhenthemethodiscalled.

Callback<(Of<(T>)>)(Action<(Of<(T>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2>)>)(Action<(Of<(T1,T2>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2,T3>)>)(Action<(Of<(T1,T2,T3>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Callback<(Of<(T1,T2,T3,T4>)>)(Action<(Of<(T1,T2,T3,T4>)>))

Specifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Page 565: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceICallback<(Of<(TResult>)>)MembersMoq.LanguageNamespace

[email protected]

Page 566: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)..::.CallbackMethod()ICallback<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalled.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 567: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrows<TResult>Callback(

Actioncallback

)

Parameters

callbackType:ActionCallbackmethodtoinvoke.

Page 568: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexamplespecifiesacallbacktosetabooleanvaluethatcanbeusedlater:

C#

boolcalled=false;

mock.Expect(x=>x.Execute())

.Callback(()=>called=true)

.Returns(true);

Notethatinthecaseofvalue-returningmethods,aftertheCallbackcallyoucanstillspecifythereturnvalue.

Page 569: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 570: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)..::.Callback<(Of<(T>)>)Method(<(Of<(T>)>))ICallback<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 571: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrows<TResult>Callback<T>(

Action<T>callback

)

Parameters

callbackType:Action<(Of<(T>)>)Callbackmethodtoinvoke.

Page 572: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typeoftheargumentoftheinvokedmethod.

Page 573: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentvalue.

Noticehowthespecificstringargumentisretrievedbysimplydeclaringitaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(It.IsAny<string>()))

.Callback((stringcommand)=>Console.WriteLine(command))

.Returns(true);

Page 574: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 575: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)..::.Callback<(Of<(T1,T2>)>)Method(<(Of<(T1,T2>)>))ICallback<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 576: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrows<TResult>Callback<T1,T2>(

Action<T1,T2>callback

)

Parameters

callbackType:Action<(Of<(T1,T2>)>)Callbackmethodtoinvoke.

Page 577: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.

Page 578: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>()))

.Callback((stringarg1,stringarg2)=>Console.WriteLine(arg1+arg2))

.Returns(true);

Page 579: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 580: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)..::.Callback<(Of<(T1,T2,T3>)>)Method(<(Of<(T1,T2,T3>)>))ICallback<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 581: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrows<TResult>Callback<T1,T2,T3>(

Action<T1,T2,T3>callback

)

Parameters

callbackType:Action<(Of<(T1,T2,T3>)>)Callbackmethodtoinvoke.

Page 582: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.

Page 583: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>()))

.Callback((stringarg1,stringarg2,intarg3)=>Console.WriteLine(arg1+arg2+arg3))

.Returns(true);

Page 584: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 585: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallback<(Of<(TResult>)>)..::.Callback<(Of<(T1,T2,T3,T4>)>)Method(<(Of<(T1,T2,T3,T4>)>))ICallback<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthemethodiscalledthatreceivestheoriginalarguments.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 586: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrows<TResult>Callback<T1,T2,T3,T4>(

Action<T1,T2,T3,T4>callback

)

Parameters

callbackType:Action<(Of<(T1,T2,T3,T4>)>)Callbackmethodtoinvoke.

Page 587: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.T4

Typeofthefourthargumentoftheinvokedmethod.

Page 588: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththeconcreteinvocationargumentsvalues.

Noticehowthespecificargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpressionforthecallback:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>(),

It.IsAny<bool>()))

.Callback((stringarg1,stringarg2,intarg3,boolarg4)=>Console.WriteLine(arg1+arg2+arg3+arg4))

.Returns(true);

Page 589: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace

[email protected]

Page 590: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallbackGetter<(Of<(TProperty>)>)InterfaceMembersSeeAlsoSendFeedbackDefinestheCallbackverbforpropertygetterexpectations.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 591: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceICallbackGetter<TProperty>

Page 592: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.

Page 593: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespaceMock<(Of<(T>)>)..::.ExpectGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

[email protected]

Page 594: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackGetter<(Of<(TProperty>)>)MembersICallbackGetter<(Of<(TProperty>)>)InterfaceMethodsSeeAlsoSendFeedback

TheICallbackGetter<(Of<(TProperty>)>)typeexposesthefollowingmembers.

Page 595: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Callback Specifiesacallbacktoinvokewhenthepropertyisretrieved.

Page 596: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 597: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackGetter<(Of<(TProperty>)>)MethodsICallbackGetter<(Of<(TProperty>)>)InterfaceSeeAlsoSendFeedback

TheICallbackGetter<(Of<(TProperty>)>)typeexposesthefollowingmembers.

Page 598: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Callback Specifiesacallbacktoinvokewhenthepropertyisretrieved.

Page 599: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 600: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallbackGetter<(Of<(TProperty>)>)..::.CallbackMethodICallbackGetter<(Of<(TProperty>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthepropertyisretrieved.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 601: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsThrowsGetter<TProperty>Callback(

Actioncallback

)

Parameters

callbackType:ActionCallbackmethodtoinvoke.

Page 602: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththepropertyvaluebeingset.

C#

mock.ExpectGet(x=>x.Suspended)

.Callback(()=>called=true)

.Returns(true);

Page 603: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 604: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallbackSetter<(Of<(TProperty>)>)InterfaceMembersSeeAlsoSendFeedbackDefinestheCallbackverbforpropertysetterexpectations.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 605: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceICallbackSetter<TProperty>

Page 606: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.

Page 607: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackSetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespaceIMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))IMock<(Of<(T>)>)..::.ExpectSet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

[email protected]

Page 608: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackSetter<(Of<(TProperty>)>)MembersICallbackSetter<(Of<(TProperty>)>)InterfaceMethodsSeeAlsoSendFeedback

TheICallbackSetter<(Of<(TProperty>)>)typeexposesthefollowingmembers.

Page 609: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Callback Specifiesacallbacktoinvokewhenthepropertyissetthatreceivesthepropertyvaluebeingset.

Page 610: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 611: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqICallbackSetter<(Of<(TProperty>)>)MethodsICallbackSetter<(Of<(TProperty>)>)InterfaceSeeAlsoSendFeedback

TheICallbackSetter<(Of<(TProperty>)>)typeexposesthefollowingmembers.

Page 612: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Callback Specifiesacallbacktoinvokewhenthepropertyissetthatreceivesthepropertyvaluebeingset.

Page 613: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 614: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqICallbackSetter<(Of<(TProperty>)>)..::.CallbackMethodICallbackSetter<(Of<(TProperty>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesacallbacktoinvokewhenthepropertyissetthatreceivesthepropertyvaluebeingset.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 615: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

ICallbackResultCallback(

Action<TProperty>callback

)

Parameters

callbackType:Action<(Of<(TProperty>)>)Callbackmethodtoinvoke.

Page 616: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesInvokesthegivencallbackwiththepropertyvaluebeingset.

C#

mock.ExpectSet(x=>x.Suspended)

.Callback((boolstate)=>Console.WriteLine(state));

Page 617: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 618: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqINeverInterfaceMembersSeeAlsoSendFeedbackDefinestheNeververb.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 619: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceINever

Page 620: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoINeverMembersMoq.LanguageNamespace

[email protected]

Page 621: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqINeverMembersINeverInterfaceMethodsSeeAlsoSendFeedback

TheINevertypeexposesthefollowingmembers.

Page 622: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Never Theexpectedinvocationisneverexpectedtohappen.

Page 623: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoINeverInterfaceMoq.LanguageNamespace

[email protected]

Page 624: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqINeverMethodsINeverInterfaceSeeAlsoSendFeedback

TheINevertypeexposesthefollowingmembers.

Page 625: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Never Theexpectedinvocationisneverexpectedtohappen.

Page 626: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoINeverInterfaceMoq.LanguageNamespace

[email protected]

Page 627: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqINever..::.NeverMethodINeverInterfaceExampleSeeAlsoSendFeedbackTheexpectedinvocationisneverexpectedtohappen.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 628: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidNever()

Page 629: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksNever()()()isalwaysverifiedinmediatelyastheinvocationsareperformed,likestrictmocksdowithunexpectedinvocations.

Page 630: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<ICommand>();

mock.Expect(foo=>foo.Execute("ping"))

.Never();

Page 631: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoINeverInterfaceMoq.LanguageNamespace

[email protected]

Page 632: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIOccurrenceInterfaceMembersSeeAlsoSendFeedbackDefinesoccurrencememberstoconstraintexpectations.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 633: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIOccurrence

Page 634: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIOccurrenceMembersMoq.LanguageNamespace

[email protected]

Page 635: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIOccurrenceMembersIOccurrenceInterfaceMethodsSeeAlsoSendFeedback

TheIOccurrencetypeexposesthefollowingmembers.

Page 636: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

AtMost Theexpectedinvocationcanhappenatmostspecifiednumberoftimes.

AtMostOnce Theexpectedinvocationcanhappenatmostonce.

Page 637: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace

[email protected]

Page 638: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIOccurrenceMethodsIOccurrenceInterfaceSeeAlsoSendFeedback

TheIOccurrencetypeexposesthefollowingmembers.

Page 639: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

AtMost Theexpectedinvocationcanhappenatmostspecifiednumberoftimes.

AtMostOnce Theexpectedinvocationcanhappenatmostonce.

Page 640: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace

[email protected]

Page 641: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIOccurrence..::.AtMostMethodIOccurrenceInterfaceExampleSeeAlsoSendFeedbackTheexpectedinvocationcanhappenatmostspecifiednumberoftimes.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 642: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesAtMost(

intcallCount

)

Parameters

callCountType:Int32

[Missing<paramname="callCount"/>documentationfor"M:Moq.Language.IOccurrence.AtMost(System.Int32)"]

Page 643: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<ICommand>();

mock.Expect(foo=>foo.Execute("ping"))

.AtMost(5);

Page 644: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace

[email protected]

Page 645: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIOccurrence..::.AtMostOnceMethodIOccurrenceInterfaceExampleSeeAlsoSendFeedbackTheexpectedinvocationcanhappenatmostonce.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 646: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesAtMostOnce()

Page 647: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

varmock=newMock<ICommand>();

mock.Expect(foo=>foo.Execute("ping"))

.AtMostOnce();

Page 648: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace

[email protected]

Page 649: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaiseInterfaceMembersSeeAlsoSendFeedbackDefinestheRaisesverb.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 650: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIRaise

Page 651: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseMembersMoq.LanguageNamespace

[email protected]

Page 652: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIRaiseMembersIRaiseInterfaceMethodsSeeAlsoSendFeedback

Page 653: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionRaises Overloaded.

Page 654: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceMoq.LanguageNamespace

[email protected]

Page 655: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIRaiseMethodsIRaiseInterfaceSeeAlsoSendFeedback

Page 656: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionRaises Overloaded.

Page 657: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceMoq.LanguageNamespace

[email protected]

Page 658: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIRaise..::.RaisesMethodIRaiseInterfaceSeeAlsoSendFeedback

Page 659: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Raises(MockedEvent,EventArgs)Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Raises(MockedEvent,Func<(Of<(EventArgs>)>))

Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Raises<(Of<(T>)>)(MockedEvent,Func<(Of<(T,EventArgs>)>))

Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Raises<(Of<(T1,T2>)>)(MockedEvent,Func<(Of<(T1,T2,EventArgs>)>))

Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Raises<(Of<(T1,T2,T3>)>)(MockedEvent,Func<(Of<(T1,T2,T3,EventArgs>)>))

Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Raises<(Of<(T1,T2,T3,T4>)>)(MockedEvent,Func<(Of<(T1,T2,T3,T4,EventArgs>)>))

Specifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Page 660: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceIRaiseMembersMoq.LanguageNamespace

[email protected]

Page 661: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.RaisesMethod(MockedEvent,)IRaiseInterfaceExampleSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 662: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises(

MockedEventeventHandler,

EventArgsargs

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

argsType:EventArgsTheeventargstopasswhenraisingtheevent.

Page 663: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtosetanexpectationthatwillraiseaneventwhenit'smet:

C#

varmock=newMock<IContainer>();

//createhandlertoassociatewiththeeventtoraise

varhandler=mock.CreateEventHandler();

//associatethehandlerwiththeeventtoraise

mock.Object.Added+=handler;

//settheexpectationandthehandlertoraise

mock.Expect(add=>add.Add(It.IsAny<string>(),It.IsAny<object>()))

.Raises(handler,EventArgs.Empty);

Page 664: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespace

[email protected]

Page 665: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.RaisesMethod(MockedEvent,<(Of<(>)>))IRaiseInterfaceSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 666: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises(

MockedEventeventHandler,

Func<EventArgs>func

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

funcType:Func<(Of<(EventArgs>)>)AfunctionthatwillbuildtheEventArgstopasswhenraisingtheevent.

Page 667: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)

[email protected]

Page 668: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.Raises<(Of<(T>)>)Method(MockedEvent,<(Of<(T,>)>))IRaiseInterfaceSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 669: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises<T>(

MockedEventeventHandler,

Func<T,EventArgs>func

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

funcType:Func<(Of<(T,EventArgs>)>)AfunctionthatwillbuildtheEventArgstopasswhenraisingtheevent.

Page 670: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typeoftheargumentreceivedbytheexpectedinvocation.

Page 671: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)

[email protected]

Page 672: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.Raises<(Of<(T1,T2>)>)Method(MockedEvent,<(Of<(T1,T2,>)>))IRaiseInterfaceSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 673: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises<T1,T2>(

MockedEventeventHandler,

Func<T1,T2,EventArgs>func

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

funcType:Func<(Of<(T1,T2,EventArgs>)>)AfunctionthatwillbuildtheEventArgstopasswhenraisingtheevent.

Page 674: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentreceivedbytheexpectedinvocation.T2

Typeofthesecondargumentreceivedbytheexpectedinvocation.

Page 675: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)

[email protected]

Page 676: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.Raises<(Of<(T1,T2,T3>)>)Method(MockedEvent,<(Of<(T1,T2,T3,>)>))IRaiseInterfaceSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 677: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises<T1,T2,T3>(

MockedEventeventHandler,

Func<T1,T2,T3,EventArgs>func

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

funcType:Func<(Of<(T1,T2,T3,EventArgs>)>)AfunctionthatwillbuildtheEventArgstopasswhenraisingtheevent.

Page 678: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentreceivedbytheexpectedinvocation.T2

Typeofthesecondargumentreceivedbytheexpectedinvocation.T3

Typeofthethirdargumentreceivedbytheexpectedinvocation.

Page 679: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)

[email protected]

Page 680: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIRaise..::.Raises<(Of<(T1,T2,T3,T4>)>)Method(MockedEvent,<(Of<(T1,T2,T3,T4,>)>))IRaiseInterfaceSeeAlsoSendFeedbackSpecifiesthemockedeventthatwillberaisedwhentheexpectationismet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 681: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IVerifiesRaises<T1,T2,T3,T4>(

MockedEventeventHandler,

Func<T1,T2,T3,T4,EventArgs>func

)

Parameters

eventHandlerType:Moq..::.MockedEventThemockedevent,retrievedfromCreateEventHandler()()()orCreateEventHandler<(Of<(TEventArgs>)>)()()().

funcType:Func<(Of<(T1,T2,T3,T4,EventArgs>)>)AfunctionthatwillbuildtheEventArgstopasswhenraisingtheevent.

Page 682: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentreceivedbytheexpectedinvocation.T2

Typeofthesecondargumentreceivedbytheexpectedinvocation.T3

Typeofthethirdargumentreceivedbytheexpectedinvocation.T4

Typeofthefourthargumentreceivedbytheexpectedinvocation.

Page 683: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)

[email protected]

Page 684: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturnsInterfaceSeeAlsoSendFeedbackBaseinterfaceforIReturns<(Of<(TResult>)>).

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 685: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIReturns

Page 687: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)InterfaceMembersSeeAlsoSendFeedbackDefinestheReturnsverb.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 688: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIReturns<TResult>:IReturns

Page 689: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Typeofthereturnvaluefromtheexpression.

Page 690: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)MembersMoq.LanguageNamespace

[email protected]

Page 691: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturns<(Of<(TResult>)>)MembersIReturns<(Of<(TResult>)>)InterfaceMethodsSeeAlsoSendFeedback

Page 692: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionReturns Overloaded.

Page 693: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 694: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturns<(Of<(TResult>)>)MethodsIReturns<(Of<(TResult>)>)InterfaceSeeAlsoSendFeedback

Page 695: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionReturns Overloaded.

Page 696: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 697: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturns<(Of<(TResult>)>)..::.ReturnsMethodIReturns<(Of<(TResult>)>)InterfaceSeeAlsoSendFeedback

Page 698: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Returns(Func<(Of<(TResult>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod.

Returns<(Of<(T>)>)(Func<(Of<(T,TResult>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Returns<(Of<(T1,T2>)>)(Func<(Of<(T1,T2,TResult>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Returns<(Of<(T1,T2,T3>)>)(Func<(Of<(T1,T2,T3,TResult>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Returns<(Of<(T1,T2,T3,T4>)>)(Func<(Of<(T1,T2,T3,T4,TResult>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Returns(TResult) Specifiesthevaluetoreturn.

Page 699: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceIReturns<(Of<(TResult>)>)MembersMoq.LanguageNamespace

[email protected]

Page 700: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.ReturnsMethod(<(Of<(TResult>)>))IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 701: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns(

Func<TResult>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(TResult>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 702: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhenthemethodiscalled:

C#

mock.Expect(x=>x.Execute("ping"))

.Returns(()=>returnValues[0]);

Thelambdaexpressiontoretrievethereturnvalueislazy-executed,meaningthatitsvaluemaychangedependingonthemomentthemethodisexecutedandthevaluethereturnValuesarrayhasatthatmoment.

Page 703: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 704: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.Returns<(Of<(T>)>)Method(<(Of<(T,TResult>)>))IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 705: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns<T>(

Func<T,TResult>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(T,TResult>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 706: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Typeoftheargumentoftheinvokedmethod.

Page 707: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhichisevaluatedlazilyatthetimeoftheinvocation.

Thelookuplistcanchangebetweeninvocationsandtheexpectationwillreturndifferentvaluesaccordingly.Also,noticehowthespecificstringargumentisretrievedbysimplydeclaringitaspartofthelambdaexpression:

C#

mock.Expect(x=>x.Execute(It.IsAny<string>()))

.Returns((stringcommand)=>returnValues[command]);

Page 708: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 709: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.Returns<(Of<(T1,T2>)>)Method(<(Of<(T1,T2,TResult>)>))IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 710: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns<T1,T2>(

Func<T1,T2,TResult>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(T1,T2,TResult>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 711: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.

Page 712: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhichisevaluatedlazilyatthetimeoftheinvocation.

Thereturnvalueiscalculatedfromthevalueoftheactualmethodinvocationarguments.Noticehowtheargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpression:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>()))

.Returns((stringarg1,stringarg2)=>arg1+arg2);

Page 713: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 714: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.Returns<(Of<(T1,T2,T3>)>)Method(<(Of<(T1,T2,T3,TResult>)>))IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 715: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns<T1,T2,T3>(

Func<T1,T2,T3,TResult>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(T1,T2,T3,TResult>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 716: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.

Page 717: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhichisevaluatedlazilyatthetimeoftheinvocation.

Thereturnvalueiscalculatedfromthevalueoftheactualmethodinvocationarguments.Noticehowtheargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpression:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>()))

.Returns((stringarg1,stringarg2,intarg3)=>arg1+arg2+arg3);

Page 718: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 719: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.Returns<(Of<(T1,T2,T3,T4>)>)Method(<(Of<(T1,T2,T3,T4,TResult>)>))IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfromthemethod,retrievingtheargumentsfortheinvocation.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 720: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns<T1,T2,T3,T4>(

Func<T1,T2,T3,T4,TResult>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(T1,T2,T3,T4,TResult>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 721: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT1

Typeofthefirstargumentoftheinvokedmethod.T2

Typeofthesecondargumentoftheinvokedmethod.T3

Typeofthethirdargumentoftheinvokedmethod.T4

Typeofthefourthargumentoftheinvokedmethod.

Page 722: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhichisevaluatedlazilyatthetimeoftheinvocation.

Thereturnvalueiscalculatedfromthevalueoftheactualmethodinvocationarguments.Noticehowtheargumentsareretrievedbysimplydeclaringthemaspartofthelambdaexpression:

C#

mock.Expect(x=>x.Execute(

It.IsAny<string>(),

It.IsAny<string>(),

It.IsAny<int>(),

It.IsAny<bool>()))

.Returns((stringarg1,stringarg2,intarg3,boolarg4)=>arg1+arg2+arg3+arg4);

Page 723: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 724: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturns<(Of<(TResult>)>)..::.ReturnsMethod(TResult)IReturns<(Of<(TResult>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesthevaluetoreturn.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 725: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns(

TResultvalue

)

Parameters

valueType:TResultThevaluetoreturn,ornullNothingnullptranullreference(NothinginVisualBasic).

Page 726: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnatruevaluefromthemethodcall:

C#

mock.Expect(x=>x.Execute("ping"))

.Returns(true);

Page 727: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 728: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturnsGetter<(Of<(TProperty>)>)InterfaceMembersSeeAlsoSendFeedbackDefinestheReturnsverbforpropertygetexpectations.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 729: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIReturnsGetter<TProperty>:IReturns

Page 730: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.

Page 731: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespace

[email protected]

Page 732: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturnsGetter<(Of<(TProperty>)>)MembersIReturnsGetter<(Of<(TProperty>)>)InterfaceMethodsSeeAlsoSendFeedback

Page 733: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionReturns Overloaded.

Page 734: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 735: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturnsGetter<(Of<(TProperty>)>)MethodsIReturnsGetter<(Of<(TProperty>)>)InterfaceSeeAlsoSendFeedback

Page 736: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionReturns Overloaded.

Page 737: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace

[email protected]

Page 738: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIReturnsGetter<(Of<(TProperty>)>)..::.ReturnsMethodIReturnsGetter<(Of<(TProperty>)>)InterfaceSeeAlsoSendFeedback

Page 739: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Returns(Func<(Of<(TProperty>)>))

Specifiesafunctionthatwillcalculatethevaluetoreturnfortheproperty.

Returns(TProperty) Specifiesthevaluetoreturn.

Page 740: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceIReturnsGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespace

[email protected]

Page 741: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturnsGetter<(Of<(TProperty>)>)..::.ReturnsMethod(<(Of<(TProperty>)>))IReturnsGetter<(Of<(TProperty>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesafunctionthatwillcalculatethevaluetoreturnfortheproperty.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 742: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns(

Func<TProperty>valueFunction

)

Parameters

valueFunctionType:Func<(Of<(TProperty>)>)Thefunctionthatwillcalculatethereturnvalue.

Page 743: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnacalculatedvaluewhenthepropertyisretrieved:

C#

mock.ExpectGet(x=>x.Suspended)

.Returns(()=>returnValues[0]);

Thelambdaexpressiontoretrievethereturnvalueislazy-executed,meaningthatitsvaluemaychangedependingonthemomentthepropertyisretrievedandthevaluethereturnValuesarrayhasatthatmoment.

Page 744: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 745: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIReturnsGetter<(Of<(TProperty>)>)..::.ReturnsMethod(TProperty)IReturnsGetter<(Of<(TProperty>)>)InterfaceExampleSeeAlsoSendFeedbackSpecifiesthevaluetoreturn.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 746: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IReturnsResultReturns(

TPropertyvalue

)

Parameters

valueType:TPropertyThevaluetoreturn,ornullNothingnullptranullreference(NothinginVisualBasic).

Page 747: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesReturnatruevaluefromthepropertygettercall:

C#

mock.ExpectGet(x=>x.Suspended)

.Returns(true);

Page 748: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceReturnsOverloadMoq.LanguageNamespace

[email protected]

Page 749: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIThrowsInterfaceMembersSeeAlsoSendFeedbackDefinestheThrowsverb.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 750: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIThrows

Page 751: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsMembersMoq.LanguageNamespace

[email protected]

Page 752: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIThrowsMembersIThrowsInterfaceMethodsSeeAlsoSendFeedback

Page 753: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionThrows Overloaded.

Page 754: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsInterfaceMoq.LanguageNamespace

[email protected]

Page 755: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIThrowsMethodsIThrowsInterfaceSeeAlsoSendFeedback

Page 756: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name DescriptionThrows Overloaded.

Page 757: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsInterfaceMoq.LanguageNamespace

[email protected]

Page 758: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIThrows..::.ThrowsMethodIThrowsInterfaceSeeAlsoSendFeedback

Page 759: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Throws<(Of<(TException>)>)()()()

Specifiesthetypeofexceptiontothrowwhenthemethodisinvoked.

Throws(Exception) Specifiestheexceptiontothrowwhenthemethodisinvoked.

Page 760: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsInterfaceIThrowsMembersMoq.LanguageNamespace

[email protected]

Page 761: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIThrows..::.Throws<(Of<(TException>)>)MethodIThrowsInterfaceExampleSeeAlsoSendFeedbackSpecifiesthetypeofexceptiontothrowwhenthemethodisinvoked.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 762: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IThrowsResultThrows<TException>()

whereTException:new(),Exception

Page 763: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTException

Typeofexceptiontoinstantiateandthrowwhentheexpectationismet.

Page 764: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleshowshowtothrowanexceptionwhenthemethodisinvokedwithanemptystringargument:

C#

mock.Expect(x=>x.Execute(""))

.Throws<ArgumentException>();

Page 765: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsInterfaceThrowsOverloadMoq.LanguageNamespace

[email protected]

Page 766: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIThrows..::.ThrowsMethod()IThrowsInterfaceExampleSeeAlsoSendFeedbackSpecifiestheexceptiontothrowwhenthemethodisinvoked.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 767: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IThrowsResultThrows(

Exceptionexception

)

Parameters

exceptionType:ExceptionExceptioninstancetothrow.

Page 768: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThisexampleshowshowtothrowanexceptionwhenthemethodisinvokedwithanemptystringargument:

C#

mock.Expect(x=>x.Execute(""))

.Throws(newArgumentException());

Page 769: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIThrowsInterfaceThrowsOverloadMoq.LanguageNamespace

[email protected]

Page 770: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIVerifiesInterfaceMembersSeeAlsoSendFeedbackDefinestheVerifiableverb.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 771: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIVerifies

Page 772: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIVerifiesMembersMoq.LanguageNamespace

[email protected]

Page 773: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIVerifiesMembersIVerifiesInterfaceMethodsSeeAlsoSendFeedback

TheIVerifiestypeexposesthefollowingmembers.

Page 774: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Verifiable Markstheexpectationasverifiable,meaningthatacalltoVerify()()()willcheckifthisparticularexpectationwasmet.

Page 775: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace

[email protected]

Page 776: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIVerifiesMethodsIVerifiesInterfaceSeeAlsoSendFeedback

TheIVerifiestypeexposesthefollowingmembers.

Page 777: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Verifiable Markstheexpectationasverifiable,meaningthatacalltoVerify()()()willcheckifthisparticularexpectationwasmet.

Page 778: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace

[email protected]

Page 779: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIVerifies..::.VerifiableMethodIVerifiesInterfaceExampleSeeAlsoSendFeedbackMarkstheexpectationasverifiable,meaningthatacalltoVerify()()()willcheckifthisparticularexpectationwasmet.

Namespace:Moq.LanguageAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 780: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

voidVerifiable()

Page 781: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexamplemarkstheexpectationasverifiable:

C#

mock.Expect(x=>x.Execute("ping"))

.Returns(true)

.Verifiable();

Page 782: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace

[email protected]

Page 783: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMoq.ProtectedNamespaceSendFeedbackImportingthisnamespacewillenabletheProtected()methodonmocks,enablingexpectationsonprotectedmembersbyspecifyingthemembernameasastring.

Page 784: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Classes Class Description

ItExpr

Allowsthespecificationofamatchingconditionforanargumentinaprotectedmemberexpectation,ratherthanaspecificargumentvalue."ItExpr"referstotheargumentbeingmatched.

ProtectedExtension

EnablestheProtected()methodonMock<(Of<(T>)>),allowingexpectationstobesetforprotectedmembersbyusingtheirnameasastring,ratherthanstrong-typingthemwhichisnotpossibleduetotheirvisibility.

Page 785: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Interfaces Interface Description

IProtectedMock

Allowsexpectationstobesetforprotectedmembersbyusingtheirnameasastring,ratherthanstrong-typingthemwhichisnotpossibleduetotheirvisibility.

[email protected]

Page 786: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIProtectedMockInterfaceMembersSeeAlsoSendFeedbackAllowsexpectationstobesetforprotectedmembersbyusingtheirnameasastring,ratherthanstrong-typingthemwhichisnotpossibleduetotheirvisibility.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 787: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicinterfaceIProtectedMock

Page 788: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockMembersMoq.ProtectedNamespace

[email protected]

Page 789: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIProtectedMockMembersIProtectedMockInterfaceMethodsSeeAlsoSendFeedback

TheIProtectedMocktypeexposesthefollowingmembers.

Page 790: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Expect Overloaded.ExpectGet<(Of<(TProperty>)>)

SetsanexpectationonapropertygetterwiththegivenpropertyName.

ExpectSet<(Of<(TProperty>)>)

SetsanexpectationonapropertysetterwiththegivenpropertyName.

Page 791: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace

[email protected]

Page 792: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIProtectedMockMethodsIProtectedMockInterfaceSeeAlsoSendFeedback

TheIProtectedMocktypeexposesthefollowingmembers.

Page 793: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Expect Overloaded.ExpectGet<(Of<(TProperty>)>)

SetsanexpectationonapropertygetterwiththegivenpropertyName.

ExpectSet<(Of<(TProperty>)>)

SetsanexpectationonapropertysetterwiththegivenpropertyName.

Page 794: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace

[email protected]

Page 795: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqIProtectedMock..::.ExpectMethodIProtectedMockInterfaceSeeAlsoSendFeedback

Page 796: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Expect<(Of<(TResult>)>)(String,array<Object>[]()[])

SetsanexpectationonapropertyoranonvoidmethodwiththegivenmethodOrPropertyName,optionallyspecifyingargumentsforthemethodcall.

Expect(String,array<Object>[]()[])

SetsanexpectationonthevoidmethodwiththegivenvoidMethodName,optionallyspecifyingargumentsforthemethodcall.

Page 797: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceIProtectedMockMembersMoq.ProtectedNamespace

[email protected]

Page 798: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIProtectedMock..::.Expect<(Of<(TResult>)>)Method(,array<>[]()[])IProtectedMockInterfaceSeeAlsoSendFeedbackSetsanexpectationonapropertyoranonvoidmethodwiththegivenmethodOrPropertyName,optionallyspecifyingargumentsforthemethodcall.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 799: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpect<TResult>Expect<TResult>(

stringmethodOrPropertyName,

paramsObject[]args

)

Parameters

methodOrPropertyNameType:StringNameofthemethodorpropertytobeinvoke.

argsType:array<Object>[]()[]Optionalargumentsfortheinvocation.

Page 800: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTResult

Returntypeofthemethodorproperty.

Page 801: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceExpectOverloadMoq.ProtectedNamespace

[email protected]

Page 802: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIProtectedMock..::.ExpectMethod(,array<>[]()[])IProtectedMockInterfaceSeeAlsoSendFeedbackSetsanexpectationonthevoidmethodwiththegivenvoidMethodName,optionallyspecifyingargumentsforthemethodcall.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 803: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectExpect(

stringvoidMethodName,

paramsObject[]args

)

Parameters

voidMethodNameType:StringNameofthevoidmethodtobeinvoke.

argsType:array<Object>[]()[]Optionalargumentsfortheinvocation.

Page 804: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceExpectOverloadMoq.ProtectedNamespace

[email protected]

Page 805: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIProtectedMock..::.ExpectGet<(Of<(TProperty>)>)MethodIProtectedMockInterfaceSeeAlsoSendFeedbackSetsanexpectationonapropertygetterwiththegivenpropertyName.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 806: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectGetter<TProperty>ExpectGet<TProperty>(

stringpropertyName

)

Parameters

propertyNameType:StringNameoftheproperty.

Page 807: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.

Page 808: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace

[email protected]

Page 809: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqIProtectedMock..::.ExpectSet<(Of<(TProperty>)>)MethodIProtectedMockInterfaceSeeAlsoSendFeedbackSetsanexpectationonapropertysetterwiththegivenpropertyName.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 810: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

IExpectSetter<TProperty>ExpectSet<TProperty>(

stringpropertyName

)

Parameters

propertyNameType:StringNameoftheproperty.

Page 811: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTProperty

Typeoftheproperty.

Page 812: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace

[email protected]

Page 813: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExprClassMembersSeeAlsoSendFeedbackAllowsthespecificationofamatchingconditionforanargumentinaprotectedmemberexpectation,ratherthanaspecificargumentvalue."ItExpr"referstotheargumentbeingmatched.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 814: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticclassItExpr

Page 815: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksUsethisvariantofargumentmatchinginsteadofItforprotectedexpectations.

Thisclassallowstheexpectationtomatchamethodinvocationwithanarbitraryvalue,withavalueinaspecifiedrange,orevenonethatmatchesagivenpredicate.

Page 816: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq.Protected..::.ItExpr

Page 817: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprMembersMoq.ProtectedNamespace

[email protected]

Page 818: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqItExprMembersItExprClassMethodsSeeAlsoSendFeedback

TheItExprtypeexposesthefollowingmembers.

Page 819: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Is<(Of<(TValue>)>) Matchesanyvaluethatsatisfiesthegivenpredicate.

IsAny<(Of<(TValue>)>) MatchesanyvalueofthegivenTValuetype.IsInRange<(Of<(TValue>)>)

Matchesanyvaluethatisintherangespecified.

IsRegex Overloaded.

Page 820: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassMoq.ProtectedNamespace

[email protected]

Page 821: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqItExprMethodsItExprClassSeeAlsoSendFeedback

TheItExprtypeexposesthefollowingmembers.

Page 822: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Is<(Of<(TValue>)>) Matchesanyvaluethatsatisfiesthegivenpredicate.

IsAny<(Of<(TValue>)>) MatchesanyvalueofthegivenTValuetype.IsInRange<(Of<(TValue>)>)

Matchesanyvaluethatisintherangespecified.

IsRegex Overloaded.

Page 823: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassMoq.ProtectedNamespace

[email protected]

Page 824: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExpr..::.Is<(Of<(TValue>)>)MethodItExprClassExampleSeeAlsoSendFeedbackMatchesanyvaluethatsatisfiesthegivenpredicate.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 825: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticExpressionIs<TValue>(

Expression<Predicate<TValue>>match

)

Parameters

matchType:Expression<(Of<(Predicate<(Of<(TValue>)>)>)>)Thepredicateusedtomatchthemethodargument.

Page 826: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeoftheargumenttocheck.

Page 827: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksAllowsthespecificationofapredicatetoperformmatchingofmethodcallarguments.

Page 828: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesThisexampleshowshowtoreturnthevalue1whenevertheargumenttotheDomethodisanevennumber.

C#

mock.Protected()

.Expect("Do",ItExpr.Is<int>(i=>i%2==0))

.Returns(1);

Thisexampleshowshowtothrowanexceptioniftheargumenttothemethodisanegativenumber:

C#

mock.Protected()

.Expect("GetUser",ItExpr.Is<int>(i=>i<0))

.Throws(newArgumentException());

Page 829: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassMoq.ProtectedNamespace

[email protected]

Page 830: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExpr..::.IsAny<(Of<(TValue>)>)MethodItExprClassExampleSeeAlsoSendFeedbackMatchesanyvalueofthegivenTValuetype.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 831: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticExpressionIsAny<TValue>()

Page 832: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeofthevalue.

Page 833: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksTypicallyusedwhentheactualargumentvalueforamethodcallisnotrelevant.

Page 834: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesC#

//ThrowsanexceptionforacalltoRemovewithanystringvalue.

mock.Protected()

.Expect("Remove",ItExpr.IsAny<string>())

.Throws(newInvalidOperationException());

Page 835: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassMoq.ProtectedNamespace

[email protected]

Page 836: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExpr..::.IsInRange<(Of<(TValue>)>)MethodItExprClassExampleSeeAlsoSendFeedbackMatchesanyvaluethatisintherangespecified.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 837: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticExpressionIsInRange<TValue>(

TValuefrom,

TValueto,

RangerangeKind

)

whereTValue:IComparable

Parameters

fromType:TValueThelowerboundoftherange.

toType:TValueTheupperboundoftherange.

rangeKindType:Moq..::.RangeThekindofrange.SeeRange.

Page 838: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersTValue

Typeoftheargumenttocheck.

Page 839: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectamethodcallwithanintegerargumentwithinthe0..100range.

C#

mock.Protected()

.Expect("HasInventory",

ItExpr.IsAny<string>(),

ItExpr.IsInRange(0,100,Range.Inclusive))

.Returns(false);

Page 840: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassMoq.ProtectedNamespace

[email protected]

Page 841: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqItExpr..::.IsRegexMethodItExprClassSeeAlsoSendFeedback

Page 842: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

IsRegex(String) Matchesastringargumentifitmatchesthegivenregularexpressionpattern.

IsRegex(String,RegexOptions)

Matchesastringargumentifitmatchesthegivenregularexpressionpattern.

Page 843: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassItExprMembersMoq.ProtectedNamespace

[email protected]

Page 844: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExpr..::.IsRegexMethod()ItExprClassExampleSeeAlsoSendFeedbackMatchesastringargumentifitmatchesthegivenregularexpressionpattern.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 845: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticExpressionIsRegex(

stringregex

)

Parameters

regexType:StringThepatterntousetomatchthestringargumentvalue.

Page 846: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectacalltoamethodwherethestringargumentmatchesthegivenregularexpression:

C#

mock.Protected()

.Expect("Check",ItExpr.IsRegex("[a-z]+"))

.Returns(1);

Page 847: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassIsRegexOverloadMoq.ProtectedNamespace

[email protected]

Page 848: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqItExpr..::.IsRegexMethod(,)ItExprClassExampleSeeAlsoSendFeedbackMatchesastringargumentifitmatchesthegivenregularexpressionpattern.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 849: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticExpressionIsRegex(

stringregex,

RegexOptionsoptions

)

Parameters

regexType:StringThepatterntousetomatchthestringargumentvalue.

optionsType:RegexOptionsTheoptionsusedtointerpretthepattern.

Page 850: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

ExamplesThefollowingexampleshowshowtoexpectacalltoamethodwherethestringargumentmatchesthegivenregularexpression,inacaseinsensitiveway:

C#

mock.Protected()

.Expect("Check",ItExpr.IsRegex("[a-z]+",RegexOptions.IgnoreCase))

.Returns(1);

Page 851: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoItExprClassIsRegexOverloadMoq.ProtectedNamespace

[email protected]

Page 852: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqProtectedExtensionClassMembersSeeAlsoSendFeedbackEnablestheProtected()methodonMock<(Of<(T>)>),allowingexpectationstobesetforprotectedmembersbyusingtheirnameasastring,ratherthanstrong-typingthemwhichisnotpossibleduetotheirvisibility.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 853: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticclassProtectedExtension

Page 854: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq.Protected..::.ProtectedExtension

Page 855: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoProtectedExtensionMembersMoq.ProtectedNamespace

[email protected]

Page 856: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqProtectedExtensionMembersProtectedExtensionClassMethodsSeeAlsoSendFeedback

TheProtectedExtensiontypeexposesthefollowingmembers.

Page 857: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Protected<(Of<(T>)>) Enableprotectedexpectationsforthemock.

Page 858: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace

[email protected]

Page 859: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqProtectedExtensionMethodsProtectedExtensionClassSeeAlsoSendFeedback

TheProtectedExtensiontypeexposesthefollowingmembers.

Page 860: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Protected<(Of<(T>)>) Enableprotectedexpectationsforthemock.

Page 861: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace

[email protected]

Page 862: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqProtectedExtension..::.Protected<(Of<(T>)>)MethodProtectedExtensionClassSeeAlsoSendFeedbackEnableprotectedexpectationsforthemock.

Namespace:Moq.ProtectedAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 863: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticIProtectedMockProtected<T>(

Mock<T>mock

)

whereT:class

Parameters

mockType:Moq..::.Mock<(Of<(T>)>)Themocktosettheprotectedexpectationson.

Page 864: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Mockedobjecttype.Typicallyomittedasitcanbeinferredfromthemockinstance.

Page 865: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace

[email protected]

Page 866: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqMoq.StubNamespaceSendFeedback

[Missing<summary>documentationforN:Moq.Stub]

Page 867: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Classes Class Description

StubExtensions AddsStubextensionmethodtoamocksothatyoucanstubproperties.

[email protected]

Page 868: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqStubExtensionsClassMembersSeeAlsoSendFeedbackAddsStubextensionmethodtoamocksothatyoucanstubproperties.

Namespace:Moq.StubAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 869: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticclassStubExtensions

Page 870: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

InheritanceHierarchyObjectMoq.Stub..::.StubExtensions

Page 871: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsMembersMoq.StubNamespace

[email protected]

Page 872: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqStubExtensionsMembersStubExtensionsClassMethodsSeeAlsoSendFeedback

TheStubExtensionstypeexposesthefollowingmembers.

Page 873: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Stub Overloaded.

StubAll<(Of<(T>)>)

Stubsallpropertiesonthemock,settingthedefaultvaluetotheonegeneratedasspecifiedbytheDefaultValueproperty.

Page 874: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassMoq.StubNamespace

[email protected]

Page 875: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqStubExtensionsMethodsStubExtensionsClassSeeAlsoSendFeedback

TheStubExtensionstypeexposesthefollowingmembers.

Page 876: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Methods Name Description

Stub Overloaded.

StubAll<(Of<(T>)>)

Stubsallpropertiesonthemock,settingthedefaultvaluetotheonegeneratedasspecifiedbytheDefaultValueproperty.

Page 877: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassMoq.StubNamespace

[email protected]

Page 878: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#IncludeProtectedMembersIncludeInheritedMembers

MoqStubExtensions..::.StubMethodStubExtensionsClassSeeAlsoSendFeedback

Page 879: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

OverloadList Name Description

Stub<(Of<(T,TProperty>)>)(Mock<(Of<(T>)>),Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))

Specifiesthatthegivenpropertyshouldhavestubbehavior,meaningthatsettingitsvaluewillcauseittobesavedandlaterreturnedwhenthepropertyisrequested.

Stub<(Of<(T,TProperty>)>)(Mock<(Of<(T>)>),Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>),TProperty)

Specifiesthatthegivenpropertyshouldhavestubbehavior,meaningthatsettingitsvaluewillcauseittobesavedandlaterreturnedwhenthepropertyisrequested.Thisoverloadallowssettingtheinitialvaluefortheproperty.

Page 880: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassStubExtensionsMembersMoq.StubNamespace

[email protected]

Page 881: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqStubExtensions..::.Stub<(Of<(T,TProperty>)>)Method(Mock<(Of<(T>)>),<(Of<(<(Of<(T,TProperty>)>)>)>))StubExtensionsClassExampleSeeAlsoSendFeedbackSpecifiesthatthegivenpropertyshouldhavestubbehavior,meaningthatsettingitsvaluewillcauseittobesavedandlaterreturnedwhenthepropertyisrequested.

Namespace:Moq.StubAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 882: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticvoidStub<T,TProperty>(

Mock<T>mock,

Expression<Func<T,TProperty>>property

)

whereT:class

Parameters

mockType:Moq..::.Mock<(Of<(T>)>)Theinstancetostub.

propertyType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Propertyexpressiontostub.

Page 883: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Mockedtype,inferredfromtheobjectwherethismethodisbeingapplied(doesnotneedtobespecified).

TPropertyTypeoftheproperty,inferredfromthepropertyexpression(doesnotneedtobespecified).

Page 884: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesIfyouhaveaninterfacewithanintpropertyValue,youmightstubitusingthefollowingstraightforwardcall:

C#

varmock=newMock<IHaveValue>();

mock.Stub(v=>v.Value);

AftertheStubcallhasbeenissued,settingandretrievingtheobjectvaluewillbehaveasexpected:

C#

IHaveValuev=mock.Object;

v.Value=5;

Assert.Equal(5,v.Value);

Page 885: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassStubOverloadMoq.StubNamespace

[email protected]

Page 886: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqStubExtensions..::.Stub<(Of<(T,TProperty>)>)Method(Mock<(Of<(T>)>),<(Of<(<(Of<(T,TProperty>)>)>)>),TProperty)StubExtensionsClassExampleSeeAlsoSendFeedbackSpecifiesthatthegivenpropertyshouldhavestubbehavior,meaningthatsettingitsvaluewillcauseittobesavedandlaterreturnedwhenthepropertyisrequested.Thisoverloadallowssettingtheinitialvaluefortheproperty.

Namespace:Moq.StubAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 887: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticvoidStub<T,TProperty>(

Mock<T>mock,

Expression<Func<T,TProperty>>property,

TPropertyinitialValue

)

whereT:class

Parameters

mockType:Moq..::.Mock<(Of<(T>)>)Theinstancetostub.

propertyType:Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>)Propertyexpressiontostub.

initialValueType:TPropertyInitialvaluefortheproperty.

Page 888: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Mockedtype,inferredfromtheobjectwherethismethodisbeingapplied(doesnotneedtobespecified).

TPropertyTypeoftheproperty,inferredfromthepropertyexpression(doesnotneedtobespecified).

Page 889: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

Copy

Copy

ExamplesIfyouhaveaninterfacewithanintpropertyValue,youmightstubitusingthefollowingstraightforwardcall:

C#

varmock=newMock<IHaveValue>();

mock.Stub(v=>v.Value,5);

AftertheStubcallhasbeenissued,settingandretrievingtheobjectvaluewillbehaveasexpected:

C#

IHaveValuev=mock.Object;

//Initialvaluewasstored

Assert.Equal(5,v.Value);

//Newvaluesetwhichchangestheinitialvalue

v.Value=6;

Assert.Equal(6,v.Value);

Page 890: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassStubOverloadMoq.StubNamespace

[email protected]

Page 891: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

C#

MoqStubExtensions..::.StubAll<(Of<(T>)>)MethodStubExtensionsClassSeeAlsoSendFeedbackStubsallpropertiesonthemock,settingthedefaultvaluetotheonegeneratedasspecifiedbytheDefaultValueproperty.

Namespace:Moq.StubAssembly:Moq(inMoq.dll)Version:2.6.1014.1(2.6.0.0)

Page 892: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SyntaxC#

publicstaticvoidStubAll<T>(

Mock<T>mock

)

whereT:class

Parameters

mockType:Moq..::.Mock<(Of<(T>)>)Themocktostub.

Page 893: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

TypeParametersT

Mockedtype,typicallyomittedasitcanbeinferredfromthemockargument.

Page 894: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

RemarksIfthemockDefaultValueissettoMock,themockeddefaultvalueswillalsobestubbedrecursively.

Page 895: C# - documentation.help · Moq Moq Namespace Send Feedback Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET developed from scratch to

SeeAlsoStubExtensionsClassMoq.StubNamespace

[email protected]