![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/1.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/2.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/4.jpg)
Enumerations Enumeration Description
DefaultValue Determinesthewaydefaultvaluesaregeneratedcalculatedforloosemocks.
MockBehavior Optionstocustomizethebehaviorofthemock.
Range KindofrangetouseinafilterspecifiedthroughIsInRange<(Of<(TValue>)>)(TValue,TValue,Range).
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/6.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/14.jpg)
Properties Name Description
CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).
DefaultValue Determineshowtogeneratedefaultvaluesforloosemocksonunexpectedinvocations.Object Themockedobjectinstance.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/17.jpg)
Methods Name Description
CreateEventHandler Overloaded.
Verify Verifiesthatallverifiableexpectationshavebeenmet.
VerifyAll Verifiesallexpectationsregardlessofwhethertheyhavebeenflaggedasverifiable.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/21.jpg)
SeeAlsoIMockInterfaceIMockMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/22.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/23.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/24.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/25.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/26.jpg)
SeeAlsoIMockInterfaceCreateEventHandlerOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/27.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/28.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/29.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/30.jpg)
SeeAlsoIMockInterfaceCreateEventHandlerOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/31.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/32.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/33.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/34.jpg)
ExceptionsException Condition
Moq..::.MockException Notallverifiableexpectationsweremet.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/36.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/37.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/38.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/39.jpg)
ExceptionsException Condition
Moq..::.MockException Atleastoneexpectationwasnotmet.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/41.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/42.jpg)
Properties Name Description
CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).
DefaultValue Determineshowtogeneratedefaultvaluesforloosemocksonunexpectedinvocations.Object Themockedobjectinstance.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/44.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/45.jpg)
SyntaxC#
boolCallBase{get;set;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/47.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/48.jpg)
SyntaxC#
DefaultValueDefaultValue{get;set;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/50.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/51.jpg)
SyntaxC#
ObjectObject{get;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/53.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/54.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/55.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/56.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/57.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/58.jpg)
//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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/59.jpg)
SeeAlsoIMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/60.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/61.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/62.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/63.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/64.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/65.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/66.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/67.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/68.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/69.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/70.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/71.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/72.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/73.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/74.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/75.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/76.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/77.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/78.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/79.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/80.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/81.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceExpectOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/82.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/83.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/84.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/85.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/86.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/87.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceExpectOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/88.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/89.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/90.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/91.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/92.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/93.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/94.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/95.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/96.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/97.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/98.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/99.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/100.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/101.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/102.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceExpectSetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/103.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/104.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/105.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/106.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/107.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/108.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceExpectSetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/109.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/110.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/111.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/112.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/113.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/114.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/115.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/116.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/117.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/118.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/119.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/120.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/121.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/122.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/123.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/124.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/125.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/126.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/127.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/128.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/129.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/130.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/131.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/132.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/133.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/134.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/135.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/136.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/137.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceIMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/138.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/139.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/140.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/141.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/142.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/143.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceVerifySetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/144.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/145.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/146.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/147.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/148.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/149.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceVerifySetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/150.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/151.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/152.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/153.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/154.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/155.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/156.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/157.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/158.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/159.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/160.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/161.jpg)
SeeAlsoIMock<(Of<(T>)>)InterfaceMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/162.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/163.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/164.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/165.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/167.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/168.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/170.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/171.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/173.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/174.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/175.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/176.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/177.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/179.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/180.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/181.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/182.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/183.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/185.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/186.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/187.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/188.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/190.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/191.jpg)
OverloadList Name Description
IsRegex(String) Matchesastringargumentifitmatchesthegivenregularexpressionpattern.
IsRegex(String,RegexOptions)
Matchesastringargumentifitmatchesthegivenregularexpressionpattern.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/193.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/194.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/195.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/196.jpg)
SeeAlsoItClassIsRegexOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/197.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/198.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/199.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/200.jpg)
SeeAlsoItClassIsRegexOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/201.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/202.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/203.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/204.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/205.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/206.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/207.jpg)
SeeAlsoMatcherAttributeMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/208.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/209.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/210.jpg)
SeeAlsoMatcherAttributeClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/211.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/212.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/213.jpg)
SeeAlsoMatcherAttributeClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/214.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/215.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/216.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/218.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/219.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/220.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/221.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/223.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/224.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/226.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/227.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/229.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/230.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/231.jpg)
SeeAlsoMockClassMockMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/232.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/233.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/234.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/235.jpg)
SeeAlsoMockClassCreateEventHandlerOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/236.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/237.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/238.jpg)
SeeAlsoMockClassCreateEventHandlerOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/239.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/240.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/241.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/242.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/243.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/245.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/246.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/248.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/249.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/251.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/252.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/254.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/255.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/257.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/258.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/260.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/261.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/263.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/264.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/266.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/267.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/269.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/270.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/272.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/273.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/274.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/275.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/276.jpg)
SeeAlsoMock<(Of<(T>)>)MembersMoqNamespaceMoq..::.IMock<(Of<(T>)>)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/277.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/278.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/279.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/280.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/281.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/282.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/283.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/284.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/285.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/286.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/287.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/288.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/289.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/290.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/291.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/292.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/293.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/294.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/295.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/296.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/297.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/298.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/299.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/300.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/301.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/302.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)OverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/303.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/304.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/305.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/306.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/307.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/308.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/309.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/310.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/311.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/312.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/313.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/314.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/315.jpg)
SeeAlsoMock<(Of<(T>)>)ClassExpectOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/316.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/317.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/318.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/319.jpg)
SeeAlsoMock<(Of<(T>)>)ClassExpectOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/320.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/321.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/322.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/323.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/324.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/325.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/326.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/327.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/328.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/329.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/330.jpg)
SeeAlsoMock<(Of<(T>)>)ClassExpectSetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/331.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/332.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/333.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/334.jpg)
SeeAlsoMock<(Of<(T>)>)ClassExpectSetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/335.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/336.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/337.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/338.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/339.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/340.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/341.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/342.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/343.jpg)
SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/344.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/345.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/346.jpg)
SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/347.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/348.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/349.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/350.jpg)
SeeAlsoMock<(Of<(T>)>)ClassVerifyOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/351.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/352.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/353.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/354.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/355.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/356.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/357.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/358.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/359.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/360.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMock<(Of<(T>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/361.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/362.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/363.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/364.jpg)
SeeAlsoMock<(Of<(T>)>)ClassVerifySetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/365.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/366.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/367.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/368.jpg)
SeeAlsoMock<(Of<(T>)>)ClassVerifySetOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/369.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/370.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/371.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/372.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/373.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/374.jpg)
SeeAlsoMock<(Of<(T>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/375.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/376.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/377.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/379.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/380.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/381.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/382.jpg)
SeeAlsoMockedEventMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/383.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/384.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/385.jpg)
Events Name Description
Raised Eventraisedwheneverthemockedeventisrised.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/387.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/388.jpg)
Operators Name Description
Implicit ProvidessupportforattachingaMockedEventtoagenericEventHandlerevent.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/390.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/391.jpg)
SyntaxC#
publicstaticimplicitoperatorEventHandler(
MockedEventmockEvent
)
Parameters
mockEventType:Moq..::.MockedEventEventtoconvert.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/393.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/394.jpg)
Events Name Description
Raised Eventraisedwheneverthemockedeventisrised.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/396.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/397.jpg)
SyntaxC#
publiceventEventHandlerRaised
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/399.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/400.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/401.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/402.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/403.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/404.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)MembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/405.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/406.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/407.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/408.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/409.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/410.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/411.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/412.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/413.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/414.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/415.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/416.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/417.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/418.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/419.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/420.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/421.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/422.jpg)
SeeAlsoMockedEvent<(Of<(TEventArgs>)>)ClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/423.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/424.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/425.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/426.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/427.jpg)
SeeAlsoMockExceptionMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/428.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/429.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/430.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/431.jpg)
SeeAlsoMockExceptionClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/432.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/433.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/434.jpg)
SeeAlsoMockExceptionClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/435.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/436.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/437.jpg)
SeeAlsoMockExceptionClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/438.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/439.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/440.jpg)
SeeAlsoMockExceptionClassMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/441.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/442.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/443.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/444.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/445.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/446.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/447.jpg)
SeeAlsoMockFactoryMembersMoqNamespaceMoq..::.MockBehavior
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/448.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/449.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/450.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/451.jpg)
Properties Name Description
CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).
DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocationsonloosemocks.
Mocks Getsthemocksthathavebeencreatedbythisfactoryandthatwillgetverifiedtogether.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/453.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/454.jpg)
SyntaxC#
publicMockFactory(
MockBehaviordefaultBehavior
)
Parameters
defaultBehaviorType:Moq..::.MockBehaviorThebehaviortouseformockscreatedusingtheCreate<(Of<(T>)>)()()()factorymethodifnotoverridenbyusingtheCreate<(Of<(T>)>)(MockBehavior)overload.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/456.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/457.jpg)
Methods Name Description
Create Overloaded.CreateMock<(Of<(T>)>)
Implementscreationofanewmockwithinthefactory.
Verify Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.
VerifyAll Verifiesallverifiableexpectationsonallmockscreatedbythisfactory.
VerifyMocksInvokesverifyActionforeachmockinMocks,andaccumulatestheresultingMockVerificationExceptionthatmightbethrownfromtheaction.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/459.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/460.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/461.jpg)
SeeAlsoMockFactoryClassMockFactoryMembersMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/462.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/463.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/464.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/465.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/466.jpg)
SeeAlsoMockFactoryClassCreateOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/467.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/468.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/469.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/470.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/471.jpg)
SeeAlsoMockFactoryClassCreateOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/472.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/473.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/474.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/475.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/476.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/477.jpg)
SeeAlsoMockFactoryClassCreateOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/478.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/479.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/480.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/481.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/482.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/483.jpg)
SeeAlsoMockFactoryClassCreateOverloadMoqNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/484.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/485.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/486.jpg)
TypeParametersT
Typetomock.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/488.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/489.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/490.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/491.jpg)
SeeAlsoMockFactoryClassMoqNamespaceMock<(Of<(T>)>)..::.Verify()()()
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/492.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/493.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/494.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/495.jpg)
SeeAlsoMockFactoryClassMoqNamespaceMock<(Of<(T>)>)..::.Verify()()()
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/496.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/497.jpg)
SyntaxC#
protectedvirtualvoidVerifyMocks(
Action<IMock>verifyAction
)
Parameters
verifyActionType:Action<(Of<(IMock>)>)Theactiontoexecuteagainsteachmock.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/499.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/500.jpg)
Properties Name Description
CallBaseWhetherthebasemembervirtualimplementationwillbecalledformockedclassesifnoexpectationismet.DefaultstotrueTruetruetrue(TrueinVisualBasic).
DefaultValue Specifiesthebehaviortousewhenreturningdefaultvaluesforunexpectedinvocationsonloosemocks.
Mocks Getsthemocksthathavebeencreatedbythisfactoryandthatwillgetverifiedtogether.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/502.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/503.jpg)
SyntaxC#
publicboolCallBase{get;set;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/505.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/506.jpg)
SyntaxC#
publicDefaultValueDefaultValue{get;set;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/508.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/509.jpg)
SyntaxC#
protectedIEnumerable<IMock>Mocks{get;}
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/511.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/512.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/513.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/515.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/516.jpg)
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.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/517.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/518.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/519.jpg)
SeeAlsoICallbackMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/520.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/521.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/522.jpg)
SeeAlsoICallbackInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/523.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/524.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/525.jpg)
SeeAlsoICallbackInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/526.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/527.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/528.jpg)
SeeAlsoICallbackInterfaceICallbackMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/529.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/530.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/531.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/532.jpg)
SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/533.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/534.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/535.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/536.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/537.jpg)
SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/538.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/539.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/540.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/541.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/542.jpg)
SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/543.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/544.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/545.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/546.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/547.jpg)
SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/548.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/549.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/550.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/551.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/552.jpg)
SeeAlsoICallbackInterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/553.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/554.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/555.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/556.jpg)
SeeAlsoICallback<(Of<(TResult>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/557.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/558.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/559.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/560.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/561.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/562.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/563.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/564.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/565.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceICallback<(Of<(TResult>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/566.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/567.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/568.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/569.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/570.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/571.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/572.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/573.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/574.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/575.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/576.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/577.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/578.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/579.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/580.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/581.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/582.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/583.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/584.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/585.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/586.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/587.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/588.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/589.jpg)
SeeAlsoICallback<(Of<(TResult>)>)InterfaceCallbackOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/590.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/591.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/592.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/593.jpg)
SeeAlsoICallbackGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespaceMock<(Of<(T>)>)..::.ExpectGet<(Of<(TProperty>)>)(Expression<(Of<(Func<(Of<(T,TProperty>)>)>)>))
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/594.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/595.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/596.jpg)
SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/597.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/598.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/599.jpg)
SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/600.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/601.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/602.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/603.jpg)
SeeAlsoICallbackGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/604.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/605.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/606.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/607.jpg)
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)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/608.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/609.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/610.jpg)
SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/611.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/612.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/613.jpg)
SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/614.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/615.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/616.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/617.jpg)
SeeAlsoICallbackSetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/618.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/619.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/620.jpg)
SeeAlsoINeverMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/621.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/622.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/623.jpg)
SeeAlsoINeverInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/624.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/625.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/626.jpg)
SeeAlsoINeverInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/627.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/628.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/629.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/630.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/631.jpg)
SeeAlsoINeverInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/632.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/633.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/634.jpg)
SeeAlsoIOccurrenceMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/635.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/636.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/637.jpg)
SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/638.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/639.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/640.jpg)
SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/641.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/642.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/643.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/644.jpg)
SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/645.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/646.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/647.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/648.jpg)
SeeAlsoIOccurrenceInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/649.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/650.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/651.jpg)
SeeAlsoIRaiseMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/652.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/653.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/654.jpg)
SeeAlsoIRaiseInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/655.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/656.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/657.jpg)
SeeAlsoIRaiseInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/658.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/659.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/660.jpg)
SeeAlsoIRaiseInterfaceIRaiseMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/661.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/662.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/663.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/664.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/665.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/666.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/667.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/668.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/669.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/670.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/671.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/672.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/673.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/674.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/675.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/676.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/677.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/678.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/679.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/680.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/681.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/682.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/683.jpg)
SeeAlsoIRaiseInterfaceRaisesOverloadMoq.LanguageNamespaceIRaise..::.Raises(MockedEvent,EventArgs)
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/684.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/685.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/687.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/688.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/689.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/690.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/691.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/692.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/693.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/694.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/695.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/696.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/697.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/698.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/699.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceIReturns<(Of<(TResult>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/700.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/701.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/702.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/703.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/704.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/705.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/706.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/707.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/708.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/709.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/710.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/711.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/712.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/713.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/714.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/715.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/716.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/717.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/718.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/719.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/720.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/721.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/722.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/723.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/724.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/725.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/726.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/727.jpg)
SeeAlsoIReturns<(Of<(TResult>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/728.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/729.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/730.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/731.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/732.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/733.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/734.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/735.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/736.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/737.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/738.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/739.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/740.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceIReturnsGetter<(Of<(TProperty>)>)MembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/741.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/742.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/743.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/744.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/745.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/746.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/747.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/748.jpg)
SeeAlsoIReturnsGetter<(Of<(TProperty>)>)InterfaceReturnsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/749.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/750.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/751.jpg)
SeeAlsoIThrowsMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/752.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/753.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/754.jpg)
SeeAlsoIThrowsInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/755.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/756.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/757.jpg)
SeeAlsoIThrowsInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/758.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/759.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/760.jpg)
SeeAlsoIThrowsInterfaceIThrowsMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/761.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/762.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/763.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/764.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/765.jpg)
SeeAlsoIThrowsInterfaceThrowsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/766.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/767.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/768.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/769.jpg)
SeeAlsoIThrowsInterfaceThrowsOverloadMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/770.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/771.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/772.jpg)
SeeAlsoIVerifiesMembersMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/773.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/774.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/775.jpg)
SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/776.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/777.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/778.jpg)
SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/779.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/780.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/781.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/782.jpg)
SeeAlsoIVerifiesInterfaceMoq.LanguageNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/783.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/784.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/785.jpg)
Interfaces Interface Description
IProtectedMock
Allowsexpectationstobesetforprotectedmembersbyusingtheirnameasastring,ratherthanstrong-typingthemwhichisnotpossibleduetotheirvisibility.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/786.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/787.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/788.jpg)
SeeAlsoIProtectedMockMembersMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/789.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/790.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/791.jpg)
SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/792.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/793.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/794.jpg)
SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/795.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/796.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/797.jpg)
SeeAlsoIProtectedMockInterfaceIProtectedMockMembersMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/798.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/799.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/800.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/801.jpg)
SeeAlsoIProtectedMockInterfaceExpectOverloadMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/802.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/803.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/804.jpg)
SeeAlsoIProtectedMockInterfaceExpectOverloadMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/805.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/806.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/807.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/808.jpg)
SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/809.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/810.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/811.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/812.jpg)
SeeAlsoIProtectedMockInterfaceMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/813.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/814.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/815.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/816.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/817.jpg)
SeeAlsoItExprMembersMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/818.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/819.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/820.jpg)
SeeAlsoItExprClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/821.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/822.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/823.jpg)
SeeAlsoItExprClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/824.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/825.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/826.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/827.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/828.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/829.jpg)
SeeAlsoItExprClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/830.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/831.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/832.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/833.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/834.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/835.jpg)
SeeAlsoItExprClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/836.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/837.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/838.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/839.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/840.jpg)
SeeAlsoItExprClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/841.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/842.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/843.jpg)
SeeAlsoItExprClassItExprMembersMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/844.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/845.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/846.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/847.jpg)
SeeAlsoItExprClassIsRegexOverloadMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/848.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/849.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/850.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/851.jpg)
SeeAlsoItExprClassIsRegexOverloadMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/852.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/853.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/854.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/855.jpg)
SeeAlsoProtectedExtensionMembersMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/856.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/857.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/858.jpg)
SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/859.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/860.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/861.jpg)
SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/862.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/863.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/864.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/865.jpg)
SeeAlsoProtectedExtensionClassMoq.ProtectedNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/866.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/867.jpg)
Classes Class Description
StubExtensions AddsStubextensionmethodtoamocksothatyoucanstubproperties.
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/868.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/869.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/870.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/871.jpg)
SeeAlsoStubExtensionsMembersMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/872.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/873.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/874.jpg)
SeeAlsoStubExtensionsClassMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/875.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/876.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/877.jpg)
SeeAlsoStubExtensionsClassMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/878.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/879.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/880.jpg)
SeeAlsoStubExtensionsClassStubExtensionsMembersMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/881.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/882.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/883.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/884.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/885.jpg)
SeeAlsoStubExtensionsClassStubOverloadMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/886.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/887.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/888.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/889.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/890.jpg)
SeeAlsoStubExtensionsClassStubOverloadMoq.StubNamespace
![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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/891.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/892.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/893.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/894.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022043010/5fa318d5e14b4718c268532e/html5/thumbnails/895.jpg)
SeeAlsoStubExtensionsClassMoq.StubNamespace