rhino-mocks

Can Rhino stub out a dictionary so that no matter what key is used the same value comes back?

var fakeRoles = MockRepository.GenerateStub < IDictionary<PermissionLevel, string>>(); fakeRoles[PermissionLevel.Developer] = "Developer"; fakeRoles[PermissionLevel.DeveloperManager] = "Developer Manager"; This is specific to what that method happens to be calling, and is irrelevant for the sake of my unit test. I'd rat...

Rhino Mocks -- assert no interaction with mock/stub

Is it possible to tell that a mock/stub has seen no interaction at all in RhinoMocks. Something along the lines of: logger.AssertNoInteraction(); Which would assert no method has been called on the stubbed logger. This would be a much less tedious than calling the following each time: logger.AssertWasNotCalled(l => l.Debug(Arg<strin...

How can I bypass the execution of a method in a RhinoMocks mock ?

I use RhinoMocks for a very simple test (I have to say I'm a beginner here). I tried to mock my object like this var mock = MockRepository.GenerateMock<MyClass>(); create a helper stub : var stubLinkedObject = MockRepository.GenerateStub<MyClass>(); then execute some logic which should call the method AddLink of the class MyClass ...

Mocking method call with out param and no return value in Rhino Mocks

So I've got this method called LoginUser: public void LoginUser(out SystemUser userToLogin, string username) Having just started with Rhino Mocks, I'm having a little trouble mocking a call and return value from this method while testing my Presenter code. What's the correct syntax in this instance? ...

How to write a Mockist test of a recursive method

If I have a method that calls itself under a certain condition, is it possible to write a test to verify the behavior? I'd love to see an example, I don't care about the mock framework or language. I'm using RhinoMocks in C# so I'm curious if it is a missing feature of the framework, or if I'm misunderstanding something fundamental, or i...

How do I mock IQueryable<T>

I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable<MyObject> QueryObject = MockRepository.GenerateStub<IQueryable<MyObject>>(); This doesn't work though so I tried doing...

unit test with mock objects

Please take a look at the following article about testing with mocks So there is an example of unit test with mock objects. As you can see, the test is written for GetPersonByID method. In the IPersonServices interface there is another method: List<Person> GetPersons(); Can anyone tell me how a Test method on this service should look ...

Clean Way to Test ASP.NET MVC Controller Without Hitting Database?

I'm trying to think of a good way to clean up my controllers to make them more testable without having to rely on a constant database connection. I thought I had a decent start by abstracting away my object context with an IObjectContext. This works well for the context, but my next problem is that I have a generic repository that I use ...

Ability to pass array to mocked method call

Hi all, I have a method that i want to mock that takes an array as a argument. In a real call, the method would modify this array and the resultant array would be use further along in code. What i tried to do was pass in array to the mocked method call, that had values that would be valid when the array is used again. However what i fin...

Rhino Mocks overwriting stubs possible?

I have this problem, which may be a bug in Rhino Mocks 3.5: stubObj = MockRepository.GenerateStub(IObject); stubObj.Stub(a=>a.Get()).Return (Guid.Empty); //1.stub stubObj.Stub(a=>a.Get()).Return (Guid.NewGuid()); //2.stub, should overwrite the first one? this: var value = stubObj.Get(); returns Guid.Empty, is this the correct beh...

Rhino AutoMocker and Stubs

I am using Joshua Flanagan article “Auto mocking Explained” as a guide. In the article there is a section called “The same tests, with automocker would look like this”. I used this information to build code to run the automocker. As you can see below answer is a list returned from the BLL. Answer does have one row in it; however, a...

Rhino Mocks: Mocking HttpRequestBase.Files

I have a view & controller that allow the user to upload a file to the server. This is done in the view using an input type='file' and in the controller by getting the value of Request.Files (HttpRequestBase, returning a HttpFileCollectionWrapper). I am having difficulty mocking this using Rhino Mocks. HttpContextBase mockHttpContext =...

How do I test a controller that has an Authorize attribute and dependencies injection by IoC?

Hi I’ve taken over an ASP.NET MVC project from a colleague. I have only a rudimentary knowledge of both ASP.NET MVC and unit testing. I’m trying to get off on the right foot by creating unit tests. I thought I’d start with testing a controller. Unfortunately I stumbled at the first hurdle! The controller in question has the Authorize ...

Stub property and save other behaviour

Is it possible to stub only one property and keep other's behaviour using Rhino Mocks? Upd. Example: I have a class with two properties public class ClassA { public string Property1 { get { return "Property1"; } } public string Property2 { get { return "Property2"; } } } I would like to get an instance of thi...

How can I test blades in MVC Turbine with Rhino Mocks?

I'm trying to set up blade unit tests in an MVC Turbine-derived site. The problem is that I can't seem to mock the IServiceLocator interface without hitting the following exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at System.Reflection.E...

Using a Factory to replace instances by fakes from an Isolation Framework

A month ago I finished reading the book "Art of Unit Testing" and today I finally had time to start using Rhino Mocks with unit testing a service that sends/receives messages to devices (UDP) and saves/loads data from the database. Off course I want to isolate the database and the UDP communication. For example for database access, we ...

Test call from abstract class to base class using rhino mocks

If have following class public abstract class MyBaseClass : BaseClass { public override string Test(string value) { return value == null ? value : base.Test(value); } } Using partial mocks I can actually test the first part of the Test-code (with value = null). Is it possible to test the fact that the call to the b...

Rhino Mocks: fixing AssertWasCalled for disposed objects

I have a test which looks a bit like this (I'm simplifying a bit from my real issue): [Test] public void Eat_calls_consumption_tracker_OnConsume() { var consumptionTrackerStub = MockRepository.GenerateStub<IConsumptionTracker>(); var monkey = new Monkey(consumptionTrackerStub); var banana = new Banana(); monkey.Eat(b...

RhinoMocks AAA Syntax

Hi, I've spent a good part of the day trying to figure out why a simple RhinoMocks test doesn't return the value I'm setting in the return. I'm sure that I'm just missing something really simple but I can't figure it out. Here's my test: [TestMethod] public void CopyvRAFiles_ShouldCallCopyvRAFiles_ShouldReturnTrue2() { ...

Making mocks trigger PropertyChanged when changed

I am using RhinoMocks, and I have a Mock which has a property I need to behave as a real property - updating its value when set, and also trigger PropertyChanged when the property is changed. The interface of the mocked object is in essence this: public interface IFoo { event PropertyChangedEventHandler PropertyChanged; int B...