Questions tagged [moq]

A mocking framework, used in unit tests for injecting "fake" implementations of interfaces as dependencies of the system under test. Use this tag for code reviews of unit testing methods that use this specific mocking framework.

Filter by
Sorted by
Tagged with
2 votes
1 answer
445 views

Testing an action returns a View with a ViewModel using xUnit and Moq

This is my first test, I think it's testing what I need it to test but wanted to get some feedback. I wanted to test to make sure the controller action returns a view with a certain ViewModel. The ...
MF1010's user avatar
  • 107
1 vote
2 answers
486 views

Wrapper class for system dialog to allow for dependency injection

The following class is a wrapper for Microsoft.Win32.SaveFileDialog. I've implemented the usage of Microsoft.Win32.SaveFileDialog...
Toby Smith's user avatar
3 votes
1 answer
159 views

TDD test class for ViewModel class

I am currently writing my first TDD application. The project is in Xamarin.Forms and tested in xUnit. I am also using Autofac and Moq. The first class below is testing second class (VM). The VM is: ...
bakunet's user avatar
  • 81
6 votes
1 answer
190 views

Generate pieces of an SQL query [closed]

Background I already changed my mind towards the SOLID principles, and am applying them in everything that I create. Now I am reading a lot of articles about TDD and BDD, aiming to begin applying ...
LoRdPMN's user avatar
  • 163
3 votes
1 answer
2k views

Unit-testing event aggregator

I have written event aggregator with the following API (just for the fun of it, I am aware that nuget has like 100 similar implementations): ...
Nikita B's user avatar
  • 13k
1 vote
1 answer
667 views

REST API wrapper testing

I'm writing wrapper for REST API of a service. In my wrapper I have quite simple method: ...
rpeshkov's user avatar
  • 183
3 votes
1 answer
2k views

Unit testing a prism event

I am currently working on a C# WPF project following the MVVM design pattern. I am using Autofac and Prism as core frameworks in the design. For unit testing I am using Xunit and Moq. I am also using ...
Cameron Hurst's user avatar
5 votes
1 answer
3k views

UnitTesting with Mocking and Dependency Injection using Ninject

I have the following scenario that I have not come across so far using Ninject. I have the following class structure (simplified for easy of reading :]). First the abstract base class for all ...
MoonKnight's user avatar
10 votes
1 answer
10k views

Unit test with Moq callback anonymous function

I have the following unit test that is testing predicate logic in a repository (Note: mockOpportunityRepository.Setup): ...
sarin's user avatar
  • 250
8 votes
1 answer
6k views

Service-Repository pattern with IoC, NPoco micro-ORM and unit tests

I'm trying to build a Web API using best practices, based on a simple proof-of-concept using students. My goal is to build the system using: Onion Architecture to seperate concerns. Service-...
Gaui's user avatar
  • 621
3 votes
1 answer
3k views

Mocking IElasticClient in unit tests

I'm trying to unit test how my class responds to a NEST 1.7 IElasticClient's return values, using NUnit 2.6.4 and Moq 4.2. I feel mocking the ...
Jeroen's user avatar
  • 1,441
12 votes
1 answer
38k views

Unit testing with dependency injection and MOQ

I'm just learning how dependency injection and mocking work, but I'd like some feedback on how I'm setting up a couple of tests. I can get them to pass, but I'm not sure this is all I need. This is ...
madvora's user avatar
  • 221
3 votes
1 answer
7k views

Same setup for many properties in Moq

I'm trying to use Moq to mock a rather large set of interfaces in an object. I'm trying to capture the behavior of retaining a dirty flag when properties are set and I'm hoping there is a cleaner way ...
Erik's user avatar
  • 139
5 votes
2 answers
9k views

Using the builder pattern to build mock objects and nested builders

No, this question has no roosting construction workers. I'm not sure if what I'm doing is a good use of the builder pattern or whether its a bastardization of what its intended purpose was. I'm ...
Craig Brett's user avatar
8 votes
1 answer
12k views

Unit tests using C#, Moq, AutoFixture, FluentAssertions

Could you give any suggestion on the following unit tests? How to make it more readable, maintainable and trustworthy. If it is not a problem - post some code with the suggestions. ...
Pellared's user avatar
  • 384
2 votes
1 answer
97 views

Multiple Services and Test Setup

Class To Test Some methods hidden for clarity ...
MarkKGreenway's user avatar
3 votes
2 answers
745 views

Using MOQ in unit-testing for a shipping calculator

I am fairly new to writing unit tests, and I was wondering if this approach I have taken is on the right track? Given the following interfaces/classes: ...
user avatar
6 votes
2 answers
22k views

REST Web Api unit test endpoint validity with NUnit and Moq

I am unit testing that the URL that I give to my IRestClient is valid. This client talks to a third party Web API. The test is as below: ...
Sam Leach's user avatar
  • 295
2 votes
1 answer
6k views

Verify collection as a method parameter

How can I verify that ohterClassMock.MethodToTest() was called with contracts? That it was called with ...
MikroDel's user avatar
  • 405
4 votes
1 answer
816 views

Mock/unit test for this IRepositoryService method/class

I have the below code: ...
Karl Cassar's user avatar
14 votes
3 answers
6k views

Unit tests for testing error codes

Both unit tests pass and they both test the same thing. The production code uses the right error codes. System Under Test (SUT) ...
Raj's user avatar
  • 320
6 votes
2 answers
3k views

Is this UnitTest for updating an object in data-access layer sensible?

I'm still trying to learn how to write good tests (and write testable code). This is the function I want to verify, ...
hometoast's user avatar
  • 163
10 votes
2 answers
22k views

Unit tests for methods that access the file system

Basically I have some methods that access the file system and to avoid that in the unit test I have broken those sections out into a protected virtual method. In the Unit Test I then use Moq to setup ...
Tyler Reid's user avatar
6 votes
2 answers
33k views

Mocking the class under test with private method calls

Consider the scenario below. It covers multiple methods of my unit under test. ...
Myrtle's user avatar
  • 528