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
0
votes
2answers
52 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...
2
votes
0answers
42 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 wondering if maybe more experienced developers will have any comments or suggestions ...
6
votes
1answer
163 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 ...
3
votes
1answer
991 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): ...
1
vote
1answer
389 views

REST API wrapper testing

I'm writing wrapper for REST API of a service. In my wrapper I have quite simple method: ...
3
votes
1answer
1k 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 ...
5
votes
1answer
2k 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 ...
10
votes
2answers
5k 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): ...
7
votes
1answer
5k 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-...
3
votes
1answer
747 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 ...
12
votes
1answer
29k 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 ...
3
votes
1answer
6k 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 ...
5
votes
2answers
6k 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 ...
7
votes
1answer
10k 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. ...
2
votes
1answer
91 views

Multiple Services and Test Setup

Class To Test Some methods hidden for clarity ...
3
votes
2answers
589 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: ...
6
votes
2answers
17k 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: ...
1
vote
1answer
3k views

Verify collection as a method parameter

How can I verify that ohterClassMock.MethodToTest() was called with contracts? That it was called with ...
4
votes
1answer
683 views

Mock/unit test for this IRepositoryService method/class

I have the below code: ...
14
votes
3answers
3k 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) ...
6
votes
2answers
2k 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, ...
9
votes
2answers
15k 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 ...
5
votes
2answers
20k views

Mocking the class under test with private method calls

Consider the scenario below. It covers multiple methods of my unit under test. ...