tagged [moq]

Using Moq to assign property value when method is called

Using Moq to assign property value when method is called I am trying to use Moq to assign a property when a method is called. Something along the lines of: Is it possible to use Moq to set an expected...

10 Apr at 14:32

Moq: How to get to a parameter passed to a method of a mocked service

Moq: How to get to a parameter passed to a method of a mocked service Imagine this class Mo(q)cking Handler in a test of Foo, how would I be able

22 Nov at 21:52

Moq to set up a function return based on called times

Moq to set up a function return based on called times I need to mock an interface to call to MSMQ, is there a way I can use Moq to simulate real MSMQ scenario that there are 10 messages in the queue, ...

16 Jan at 21:40

Using Moq, how do I set up a method call with an input parameter as an object with expected property values?

Using Moq, how do I set up a method call with an input parameter as an object with expected property values? The Add() method expects a UserMetaData object which has a FirstName property. I'd like to ...

25 Jul at 12:49

How to moq a static class with a static method (UnitOfWork case)?

How to moq a static class with a static method (UnitOfWork case)? I have these classes: ``` public static class UnitOfWorkSS { public static IUnitOfWork Begin() { return IoC.Resolve(); } } public...

27 Sep at 20:42

C# how to mock Configuration.GetSection("foo:bar").Get<List<string>>()

C# how to mock Configuration.GetSection("foo:bar").Get>() I have a list like following in config.json file ` ``` { "foo": { "bar": [ "1", "2", "3" ] } }` Configuration.GetSection("foo:b...

6 May at 16:34

How to install Moq framework

How to install Moq framework I plan on using Moq to mock some interfaces in the unit test code I've created. I've already downloaded the latest version of Moq. My question is how do I install it? Wher...

21 Jan at 20:44

SetupSequence in Moq

SetupSequence in Moq I want a mock that returns `0` the first time, then returns `1` anytime the method is called thereafter. The problem is that if the method is called 4 times, I have to write: Othe...

9 Aug at 22:48

Verifying a delegate was called with Moq

Verifying a delegate was called with Moq i got a class that gets by argument a delegate. This class invokes that delegate, and i want to unit test it with Moq. how do i verify that this method was cal...

20 Jun at 22:45

C# Static Readonly log4net logger, any way to change logger in Unit Test?

C# Static Readonly log4net logger, any way to change logger in Unit Test? My class has this line: When I go to unit test, I can't inject a moq logger into this interface so I could count log calls. Is...

28 May at 16:9

How can I tell Moq to return a Task?

How can I tell Moq to return a Task? I've got an interface which declares I'm using MoqFramework for my tests: Then in my test I execute the code which i

Why do we need mocking frameworks?

Why do we need mocking frameworks? I have worked with code which had NUnit test written. But, I have never worked with mocking frameworks. What are they? I understand dependency injection and how it h...

11 Nov at 18:14

Moq how to correctly mock set only properties

Moq how to correctly mock set only properties What is the correct way for dealing with interfaces the expose set-only properties with Moq? Previously I've added the other accessor but this has bled in...

21 Jul at 07:46

unit testing a unit of work

unit testing a unit of work new to unit testing. I have a unit of work that I am trying to unit test. I am probably missing something simple here. I am trying to unit test the Commit method. I am usin...

14 Jun at 20:56

Need some advice for trying to mock a .NET WebClient or equivalent

Need some advice for trying to mock a .NET WebClient or equivalent I've got some code which downloads some RSS feeds. I've been using `WebClient` or `Argotic.Syndication.RssFeed` libraries. I definate...

19 Jun at 06:31

How can I mock this static method

How can I mock this static method I have this code: And I like to create unit test, but how can I mock `AppData.GetAppData("stringval")` to whatever I want the value is, so I can test the

7 Aug at 07:34

Mocking Static Methods

Mocking Static Methods Recently, I've begun to use [Moq](https://github.com/moq/moq4) to unit test. I use Moq to mock out classes that I don't need to test. How do you typically deal with static metho...

28 Dec at 18:31

Use Moq to mock Constructor?

Use Moq to mock Constructor? I have such a set of Constructors: ``` public BusinessObjectContext() : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString").TableEndpoint.ToStrin...

22 Sep at 16:34

Async methods return null

Async methods return null If I try to mock a type containing an `async` method such as : Then the mock's `Bar` method is returning null. I guess Moq is choosing `default(Task)` as default return value...

2 Jun at 21:45

Using Moq to determine if a method is called

Using Moq to determine if a method is called It is my understanding that I can test that a method call will occur if I call a higher level method, i.e.: I want to test that if I call `SomeMethod()` th...

28 Aug at 12:52

Moq property with protected setter

Moq property with protected setter I want to Moq next object: so that `new Mock().Bar` return `"Blah"`. How can I do that? --- throws > Failure: System.NotSupportedException : Invalid setup on a non-v...

11 Sep at 19:14

Can I use moq Mock<MyClass> to mock a class, not an interface?

Can I use moq Mock to mock a class, not an interface? Going through [https://github.com/Moq/moq4/wiki/Quickstart](https://github.com/Moq/moq4/wiki/Quickstart), I see it Mock an interface. I have a cla...

10 Mar at 00:46

How to mock Controller.User using moq

How to mock Controller.User using moq I have a couple of ActionMethods that queries the Controller.User for its role like this acting conveniently on that condition. I'm starting to make tests for the...

Service stack and Mocking, any tutorials?

Service stack and Mocking, any tutorials? I am currently evaluating ServiceStack (to create rest based services in .Net). One of the areas of interest is the testing side. My rest service will have a ...

Assigning out/ref parameters in Moq

Assigning out/ref parameters in Moq Is it possible to assign an `out`/`ref` parameter using Moq (3.0+)? I've looked at using `Callback()`, but `Action` does not support ref parameters because it's bas...

29 Aug at 17:55