rhino-mocks

How do I use Rhino.Mocks.RhinoMocksExtensions.VoidType with lamda Expect?

I get the following error on this line: session.Expect(s => s.Add("string", null)).IgnoreArguments().Return(SaveMockUser()); cannot convert from 'void' to 'Rhino.Mocks.RhinoMocksExtensions.VoidType' SaveMockUser is defined as follows private void SaveMockUser() { } What am I doing wrong? ...

Problem mocking events attached to abstract class through constructor of other object

i have an abstract class and im trying to mock out events being attached to it using Rhino Mocks. Here a bit of the abstract class public abstract class Download { public virtual event EventHandler<DownloadProgressEventArgs> DownloadProgress_Changed; protected virtual void OnDownloadProgressChanged(DownloadProgressEventargs e) ...

How do I stub a Func<T,TResult> in Rhino Mocks?

I have a class with a dependency: private readonly IWcfClient<ITestConnectionService> _connectionClient; and I want to stub out this call: _connectionClient.RemoteCall(client => client.Execute("test")); This currently isn't working: _connectionService .Stub(c => c.RemoteCall(rc => rc.Execute("test"))) .Return(true); Is t...

Can't get Latest Rhino Mocks to work

I don't get it - I've looked at the documentation, and I can't see what's wrong with this code: var mocks = new MockRepository(); var repository = mocks.StrictMock<IRecipeRepository>(); IList<Recipe> recipes = new List<Recipe>(); recipes.Add(new Recipe { ID = 1, Name = "Fish" }); recipes.Add(new Recipe { ID = 2, Name = "Chips" }); // T...

Testing a background worker with rhino mocks

lets say i have a background worker in a class that perform db query in a background thread. i wanna test this class so i mock my db and return some collection so far so good, make sure my background worker called the do work and than i wanna make sure that the finish also happened. I've noticed that the test pass and fail randomly (...

Mocking an arry of type with Rhino Mock

I am having issues mocking an array with Rhino Mock, any direction would be great. namespace Checks_Rhino_Mocks { public class Check { public Header header; public Detail[] details; } public class Header { public string Number; public decimal Amount; } public class Detail ...

How do I set the expectation of an event when calling a method?

I've implemented an ITimer interface because I want to write some tests around a class I'm building that utilizes the System.Timers.Timer class. So the sequence goes when I call Timer.Start() some time later I expect the Elapsed event to occur. However, for my test I want to mock out this behavior, because I don't want to wait a certai...

How do I reset the result for a property in a stub without resetting the entire stub?

I'm new to Rhino Mocks, so I may be missing something completely. Lets say I have an interface with has a half dozen properties: public interface IFoo { string Foo1 { get; } // Required non-null or empty string Foo2 { get; } // Required non-null or empty string Foo3 { get; } string Foo4 { get; } int Foo5 { get; } int Foo6 {...

Rhino Mocks - Stub a Singleton

I have a Singleton that is accessed in my class via a static property like this:OtherClassNotBeingTested.Instance.SomeInstanceMethod() I would like to test my class with out making one of these objects. Is there a way for RhinoMocks to return a stub when the getter for the static property Instance is called? To be clearer, here is the...

How can I test an event of a MVC controller

I want to test the OnException, OnActionExecuted event of an MVC controller. If I use mock like this: var httpContext = MockRepository.GenerateMock<HttpContextBase>(); var request = MockRepository.GenerateMock<HttpRequestBase>(); httpContext.Expect(c => c.Request).Return(request).Repeat.AtLeastOnce(); r...

Rhino Mocks constraints and Dictionary parameters

How would you check the parameters on a function that accepts a Dictionary? IDictionary<string, string> someDictionary = new Dictionary<string, string> { {"Key1", "Value1"}, {"Key2", "Value2"} }; Expect.Call(delegate {someService.GetCodes(someDictionary);}).Constraints(...); Basically, I want to verify that the parameter for GetC...

Rhino.Mocks: method calls recorder (a.k.a. test spy)

I have a piece of logic I want to test and it uses dependency injected interface with one (or more) void methods, example: interface IMyService { void MethodA (MyComplexObject arg1, int arg2); } What I would want is to create a stub for this IMyService that would just record the method invocations of MethodA and I would later be a...

Extension methods in Mono 2.4 and RhinoMocks 3.5

I am playing around with MonoDevelop 2.0 and Mono 2.4 in Ubuntu. I have run into problems with extension methods not being available (eg mockView.Stub(...)) in RhinoMocks 3.5 for AAA style tests. I downloaded the RhinoMocks dll from Ayende's site rather than compiled from source. My project in MonoDevelop is setup to target framework 3....

How do I Fake UpdateModel for ASP.Net MVC?

I am trying to unit test a controller action that uses UpdateModel but I am not correctly mocking the HttpContext. I keep getting the following exception: System.InvalidOperationException: Previous method 'HttpRequestBase.get_Form();' requires a return value or an exception to throw. To mock the HttpContext I am using some thing ...

What are the real-world pros and cons of each of the major mocking frameworks?

see also "What should I consider when choosing a mocking framework for .Net" I'm trying to decide on a mocking framework to use on a .NET project I've recently embarked on. I'd like to speed my research on the different frameworks. I've recently read this blog post http://codevanced.net/post/Mocking-frameworks-comparison.aspx ...

RhinoMocks - Stub a Method That Returns a Parameter

I am using RhinoMocks, I need to stub a method, and always have it return the third parameter, regardless of what is passed in: _service.Stub(x => x.Method(parm1, parm2, parm3)).Return(parm3); Obviously, it ain't that easy. I don't always know what the parms are going to be, but I know I always want to return the 3rd one. ...

StrucutureMap RhinoMock Record/Playback, Example needed

I'm looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(int id); } public class DAL : IDAL { public List<Model> Method1(int id) { List<Model> retval = new List<Model>(); DbComman...

How to mock Add method of subsonic's SimpleRepository

Hi, I'm trying to mock the Add method of subsonic SimpleRepository with Rihino mocks, I'm using the IRepository Interface but I'm new to mocking and dont know how to go from there, can this be done? thanks for your help. ...

Mocking a DataReader and getting a Rhino.Mocks.Exceptions.ExpectationViolationException: IDisposable.Dispose(); Expected #0, Actual #1

I'm trying to mock a SqlDataReader SqlDataReader reader = mocks.CreateMock<SqlDataReader>(); Expect.Call(reader.Read()).Return(true).Repeat.Times(1); Expect.Call(reader.Read()).Return(false); Expect.Call(reader.HasRows).Return(true); Expect.Call(reader.Dispose); Expect.Call(reader["City"]).Return("Boise"); Expect.Call(reader["St...

How to mock methods with lambda as parameter

Hi, I'm new to mocking, I have a method which takes a lambda as a parameter, how can I mock it using Rhino Mocks? Thanks. ...