I have TimeMachine class which provides me current date/time values. The class looks like this:
public class TimeMachine
{
public virtual DateTime GetCurrentDateTime(){ return DateTime.Now; };
public virtual DateTime GetCurrentDate(){ return GetCurrentDateTime().Date; };
public virtual TimeSpan GetCurrentTime(){ return GetCurrentDate...
Does anyone have an implementation lying around of an auto-mock container using Rhino Mocks and NInject?
...
Hi,
In my unit test instead of IgnoreArguments i want to use some partial matching of arguments in rhino mocks testing.
How to do that?
Thanks,
John
...
I have just crafted the following test using Rhino mocks. Does my test look valid and make sense to those more experienced with mocking?
I am a a little confused that I haven't had to use the DynamicMock() or StrictMock() methods to create a seemingly valid test.
This test tests that the Add method was invoked on the supplied ICachingS...
I'm trying to unit test file read operations. In this scenario I also need make sure that, if a particular user don't have read access he should get an exception...
But somehow I'm unable to get it working, can anyone suggest something?
PS: I'm using Rhino mock and NUnit
...
I am new to Rhino Mocks, and using mock isolation frameworks in general for unit testing. I have written the following test, where I have set up an expectation for a mock IDataProvider object to return a collection of objects. The collection supplied has one object in it.
When I run the test, the call to the IDataProvider returns a empt...
I am trying to setup unit tests for my Linq To SQL code. My code uses the System.Data.Linq.Table class (generated by the designer).
Because this class is sealed and the constructor is internal it is completely impervious to unit testing frameworks like Rhino Mocks. (Unless you want to alter you code to use the repository pattern, whic...
I have an object the references a bunch of Properties.Settings.Default... values and I need to stub these in the unit test for this object.
Unfortunately the type for the settings object is declared as internal and so I can't access it from the unit test project.
How can I stub up the return values for these properties? I'm using Rhino...
I have a situation I've run into several times but have never found a good answer for. Suppose I have a class like the following, where one method calls another in the same class:
public class Foo
{
public int Bar()
{
if (Baz())
{
return 1;
}
else
{
return 2;
...
Quite new to this mocking thing, I have a couple of questions.
Correct me if I'm wrong:
Mocking does not initialize the real method i.e. Mocking will not actually call the constructor of your class. Instead it does something like look at the signature of the class and create an object with that signature but with none of the methods fun...
In RhinoMocks or Moq, can properties on an object be set before the constructor is called?
I'm trying to test a method.
The class containing the method has some code in it's constructor which depends on some members being set, unfortunately there's no params in the constructor to set them so I must set them through a property. Is ther...
My object under test has two dependency objects of the same type. Sometimes when a test has a failed expectation, it's not clear which dependency object set that expectation. Is there some way to give the dependency objects names that will appear in the error messages so that I can tell them apart?
Here's an example:
MockReposi...
I'm having trouble using Rhino Mocks to assert that a method was called (and ideally with a particular parameter). The Method is ILog.Debug(FormatMessageHandler) in Common.Logging 2.0 using the new lamba syntax. It works fine using the old way plain ILog.Debug(string).
// Sample Code to Test
public int TestFuncLambda(ILog log,...
I am using RhinoMocks. Now I want to assert that some function was called, but I only care about one of the arguments. Can I do a AssertWasCalled where I only specify one argument?
In the following example I'd like the ignore what was sent to the second argument of SomeOtherFunction(). I.e. I want to check that SomeOtherFunction was ca...
I'm writing unit tests using RhinoMocks for mocking, and now I'm in need of some new functionality which I haven't used before.
I'd like to call a function, which again will call an async function. To simulate that the async function finishes and triggers the given callback with the result from execution I assume I can use the Callback...
Forgive me for my ignorance. I'm trying to learn Rhino.
public Foo(Stream stream)
{
if (stream == null) throw new ArgumentNullException("woot");
if (!stream.CanRead) throw new NotSupportedException("sporkish");
if (!stream.CanSeek) throw new NotSupportedException("monkey");
}
I would like to test this function with a NUni...
I would like to be able to mock the ClientScriptManager class on a webforms Page object,
however it seems like I can't, I get the error that I can't mock a sealed class.
MockRepository mocks = new MockRepository()
Page page = mocks.PartialMock<Page>();
var clientScript = mocks.PartialMock<ClientScriptManager>(); //error here
SetupRes...
Using Rhinomocks, how can I verify that a Mock/stub was never called at all? Meaning no methods was called on the mock/stub?
I am aware of the AssertWasNotCalled method, but this method requires that I mention a method name. (Perhaps I have a class with 10 different methods that could be called).
Log.AssertWasNotCalled(x => x.LogAndRe...
Hi Guys,
I am using rhino mocks 3.5 and am trying to throw an exception in my expectation to test some functionality in my catch block.
But for some reason it is not throwing the exception.
_xyz.stub(x => x.function(string)).throw(new exception("test string"));
So, I am stubbing out the call to the function to throw exception but it...
I am planning to rewrite a current system that I previously worked on a portion of. I am doing this as a learning exercise. Below is a description of the old system, basic architecture of the new system, some best practices I want to follow, the goals I want to acheive and my questions.
Let me explain the old system:
1. SQL Server Datab...