NMock2 is a library for assisting test driven development of C# code by providing a dynamic Mock Object framework for .NET interfaces.
Questions tagged [nmock2]
16 questions
44
votes
5 answers
What are the capabilities of Moq and Rhino.mocks?
I cannot find a specific feature-by-feature comparison of Moq and Rhino. All the questions are "which do you like better and why", or "here's how you do a simple mock in rhino and how it's done in moq".
I cannot find a deep comparison anywhere. …

womp
- 115,835
- 26
- 236
- 269
6
votes
2 answers
How to unit test class that reads xml file?
I need to write a unit tests for a class that reads a xml file and parses it's content.
How can I Mock the file reading ? Because all the content of the tests should be against read file .
I use nmock2 with nUnit.
Thanks

Night Walker
- 20,638
- 52
- 151
- 228
4
votes
1 answer
How test SqlParameter for equality
Using NUnit and NMock2 I was not able to compare what I thought were the same SqlParameters:
SqlParameter param1 = new SqlParameter("@Id", 1);
SqlParameter param2 = new SqlParameter("@Id", 1);
Assert.IsTrue(param1.Equals(param2)); // This failed
I…

sgmeyer
- 645
- 5
- 21
2
votes
1 answer
Convert NMock2 test to Moq
I'm new to unit testing and mocking. I have to convert unit tests in my current project with using Moq. Currently tests are using Nmock2. Can you help me with converting this code (using of CollectAction) with using Moq:
Action…

iburlakov
- 4,164
- 7
- 38
- 40
2
votes
1 answer
Help with some mocking
I was trying to mock an interface and I got the next expection:
System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match
I figured out later that my problem was a function…

Luisa
- 525
- 1
- 6
- 16
2
votes
2 answers
Differences between NMock 2.0 and NMock2
I am a bit confused over which version of NMock2 I should use. The one I've been using for a while I got from here:
http://www.nmock.org/download.html
The filename is NMock2.dll with version 2.0.0.44.
I ran into a problem where I couldn't mock…

Igor Zevaka
- 74,528
- 26
- 112
- 128
2
votes
2 answers
NMock - how to say expect 'any value' on these params? Or should I not do this?
I have a quick question that I could not figure out in the docs about NMock2.0.
I have a function called Save() that I want to mock out. This takes a string ID as parameter and a decimal as value..
I know I can write this to make sure that Save()…

dferraro
- 6,357
- 11
- 46
- 69
2
votes
1 answer
How to NMock FileStream?
I have this code in my unit test:
var file = m_Mockery.NewMock();
Stream s = new MemoryStream();
Expect.Once.On( file ).Method( "OpenRead" )
.With( "someFile.mdb")
.Will( Return.Value( s ) );
...
...
...
// this runs the real code that…

O.O
- 11,077
- 18
- 94
- 182
1
vote
1 answer
Nmock2 and Event Expectations
Im in the process of writing a test for a small application that follows the MVP pattern.
Technically, I know I should have written the test before the code, but I needed to knock up a demo app quick smart and so im now going back to the test before…

Kildareflare
- 4,590
- 5
- 51
- 65
1
vote
1 answer
Convert UT in NMock2 to Moq. Also, what does .Will() in NMock2 stand for?
I am new to NMock2 and Moq frameworks. I need some help converting NMock2 code in my current project to Moq code:
var myMock= myMockery.NewMock();
var myRoleMock = myMockery.NewMock();
var acceptAction = new…

Adrian T
- 33
- 7
0
votes
1 answer
migrate unit tests written with NMock2 to Moq
I am asked to upgrade a very old codebase to .net 6 and after upgrading the unit tests no longer pass because the mock library NMock2 doesn't support .net 6. I try to replace the old mock library with Moq but encountered new problems. Since I am no…

tmsh
- 71
- 1
- 9
0
votes
1 answer
Have NMock2 to create instance of a Type
I have this situation:
A method that expects a Type as one of its parameter;
This Type must be a Type that implements an Interface in the project;
I need to write tests for this method;
I'm using NMock2;
Is there any way to get a Type from NMock2 so…

Bruno
- 4,337
- 12
- 42
- 55
0
votes
2 answers
How can I mock an internal interface using NMock2?
If I try this, I just get an exception:
System.TypeLoadException : Access is denied: 'Namespace.IInternalInterface'.
Making the interface public is not an acceptable solution. I don't want to change the visiblity of my API in order to test it.

Matt Brunell
- 10,141
- 3
- 34
- 46
0
votes
1 answer
Returning object in NMOCK2
I am using NMOCK2 and I want my mock to return a List containing 1 element, . This is what I have written so far:
Expect.Once.On(mockDatabaseManager).
Method("GetTablesNames").
Will(Return.Value(new List()));
Is it even possible to…

Marta Panuszewska
- 55
- 11
0
votes
2 answers
How to check property of function argument in NMock
Say if i had the following interface mocked in (NMock). How could i check that email.Subject = 'xyz' ?
Currently im doing something like
IEmailService s = mocks.NewMock();
Expect.Once.On(s).Method("Send").With(?????)
s.Send(new…

mrwayne
- 627
- 6
- 15