Moq (pronounced "Mock-you" or just "Mock") is a mocking framework for .NET build using the language features of C# 3 and the .NET 3.5 platform.
2
votes
1answer
24 views
Moq a virtual ICollection<> property that has a private set : “Invalid setup on a non-virtual”
I'm running into a problem where I try to mock an object which contain a property Items of type ICollection<>. I get the following error :
System.NotSupportedException : Invalid setup on a ...
1
vote
2answers
46 views
How do I unit test a root ViewModel with multiple layers of children?
I am having difficulty writing tests for a particular ViewModel which ties together several other ViewModels and their children. It's the most complex ViewModel in my application.
My ViewModel's ...
-2
votes
1answer
45 views
Is there any possible way to Moq object's ToString method?
Right, title quite says it all.
[TestMethod()]
void TestFunc()
{
string r = "Hello World"
var oMoq = new Mock<object>();
oMoq.setup(o => o.ToString()).Returns(r);
...
0
votes
2answers
24 views
MOQ stubbing property value on “Any” object
I'm working on some code that follows a pattern of encapsulating all arguments to a method as a "request" object and returning a "response" object. However, this has produced some problems when it ...
2
votes
2answers
45 views
Unit testing Parallel.foreach
I'm using Moq to unit test some code that includes a Parallel.foreach loop.
The Arrange phase sets up 4 exceptions to be thrown within the loop and then wrapped in an AggregateException.
This passed ...
2
votes
3answers
42 views
Check if a property was set - using Moq
I am new to Moq and testing in general so here is my noobish Q.
How do I test if the Status property on Request has been set using Moq?
public class DudeManager
{
private readonly ...
0
votes
1answer
60 views
Moq Unit Test Setup Not Working
I am trying to create a simple unit test using the Ninject Moq framework, and for some reason I cannot get the Setup method to work correctly. From what I understand the Setup method below should ...
1
vote
0answers
34 views
Configure AutoMapper to return Mock in test layer
In my app, all domain classes follow the standardization:
All implement the interface IEntity
Id properties are protected*
The properties of type IList are protected and initialized in the ...
1
vote
1answer
37 views
Moq: Facade for a class whose method are not virtual
I have a class that depends on XmlSerializer. I want to mock XmlSerializer to verify that its methods are being called correctly. However, because the Serialize() and Deserialize() methods aren't ...
0
votes
1answer
19 views
Which is the correct web site to download Moq binary files?
I want to play around with Moq framework. I wanted to download the framework, so I reached http://code.google.com/p/moq/ through google, but the first line mentions that this project has been moved to ...
0
votes
1answer
51 views
Having difficulties setting up a mock to unit test WebAPI Post
I'm attempting to set up a unit test with MSTest and Moq for a live system that posts json from a form to a database. The system itself works just fine, but I've been tasked with attempting to build ...
0
votes
2answers
62 views
Is this a proper way of mocking a repository implementation
Having unit-tested my repository interface, I'm now unit testing my repository-implementation. I find that I'm mocking much of the implementation, too much for my comfort. An example follows:
...
0
votes
2answers
56 views
How to assign values to properties in moq?
I have a class with a method that returns an object of type User
public class CustomMembershipProvider : MembershipProvider
{
public virtual User GetUser(string username, string password, string ...
1
vote
2answers
27 views
In Moq, is there a simple way to make Setup() return null, regardless of all arguments supplied?
Using Moq, I want to Setup() a call, so that it always returns null, regardless of any supplied parameters.
I do it like this:
_myMock.Setup(mock => mock.MyMethod(
It.IsAny<int?>(),
...
0
votes
3answers
58 views
Testing a service using mock repository objects
I am testing a service within a framework.
In order to initialize the service, I am using mock repository objects.
ServiceTest.cs
private IRepository _repository;
private IService _service;
...