rhino-mocks

How to mock a generic repository using NUnit.Mocks ?

I'm working on a generic repository and I would like to test it using a NUnit.Mocks . According to Mike Hadlow in his article you can do it using Rhino mocks like this: User[] users = new User[] { }; ... Expect.Call(userRepository.GetAll()).Return(users); So I thought maybe I could write the same thing in NUnit.Mocks like this : data...

How to use Rhino Mock to mock a local function calling?

Here is my situation: I want to test on the "HasSomething()" function, which is in the following class: public class Something { private object _thing; public virtual bool HasSomething() { if (HasSomething(_thing)) return true; return false; } public virtual bool HasSom...

RhinoMocks exceptions when stubbing out Equals method

Hi! I've a problem setting up a test for an Equals method on an object. The object in question is defined by this interface: public interface IHours { ITimeOfDay OpenAt { get; set; } ITimeOfDay CloseAt { get; set; } DateTime ValidFrom { get; set; } DateTime ValidTo { get; set; } bool isCovered(DateTime time); } a...

With ASP.NET/MVC + MvcMockHelpers + RhinoMocks, who sets RouteData?

I'm trying to write a test for an ASP.NET MVC controller method. I've got RhinoMocks (since it seems to be the most popular and best supported), and MvcMockHelpers (since it seems like I need that). My test method looks like: var controller = new MyController(); MvcMockHelpers.SetFakeControllerContext(mocks, controller); mocks.ReplayA...

Issues mocking the MVC ControllerContext request

I'm pretty new to testing and mocking and i am trying to write a test that will ensure that my validation logic is setting ModelState errors correctly. What I'm seeing is that the controller.ControllerContext.HttpContext.Request is set the first time I check it but every time after that the Request is null. This is causing a null r...

Rhino Mocks : How to match array arguments in an expectation?

Again at the Rhino Mocks Noob Wall mockUI.Expect( x => x.Update( new Frame[] {Frame.MakeIncompleteFrame(1, 5)} ) ); This is the exact argument that I need to match. Via trace statements, I have verified that is the actual output as well i.e. the code behaves as intended but the test disagrees. RhinoMocks responds with TestBowlingSc...

How can I raise an event on a mocked BackgroundWorker ?

I am trying to test how my class reacts on to what happens when the BackgroundWorker fires the RunWorkerCompleted event. I am using RhinoMocks (if there is another approach I am willing to try it as well) and the code is as follows: //arrange var bw1 = MockRepository.GenerateStub<BackgroundWorker>(); Action work1 = () => T...

How to mock method call from other class in Rhino Mock AAA ?

Hi, I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test) { OrderParser orderParser = new OrderParser(); string tester = orderParser.ParseOrder(test); return tester + " here" ; } } public class OrderParser { public virtual string P...

Multiple calls to a Rhino mocked method return different results

If I want to mock a class that returns a string that is used to determine whether while loop should continue (imagine read while string != null), how can I set the expectation. I have tried the following: provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20"); provider.Reader.Expect(r => r.ReadLine()).Return(null); but wh...

Recursive mocking with Rhino-Mocks

Hi I'm trying to unittest several MVP implementations and can't quite figure out the best way to mock the view. I'll try to boil it down. The view IView consists e.g. of a property of type IControl. interface IView { IControl Control1 { get; } IControl Control2 { get; } } interface IControl { bool Enabled { get; set; } ...

Unit Testing Stubbed Method

Given this class: public class OrderService { public OrderService(IOrderLogger log) { this.log = log; } private readonly IOrderLogger log; public void PurgeOrder(Order order) { ... var action = new LogAction("foo","bar"); log.Action(action); } } And this test: [Fact] public void Purg...

How to avoid setup code duplication with record-replay mode of Rhino Mocks?

This is a test suite that is green using Rhino Mocks. [SetUp] public void BeforeEachTest() { _mocksRepo = new MockRepository(); _mockBank = _mocksRepo.StrictMock<IBank>(); //_mockPrinter = _mocksRepo.StrictMock<IPrinter>(); _mockPrinter = _mocksRepo.DynamicMock<IPrinter>(); _mockLogger = _mocksRepo.Str...

Rhino Mocks mock inherited interface

Hi, i have a class e.g. DerivedClass that inherits from a base class e.g. BaseClass. BaseClass implements an interface called IBaseClass. IBaseClass has 1 property called TestProperty which is an integer auto property. I PartialMultiMock DerivedClass like so: derivedClassMock = repository.PartialMultiMock<DerivedClass>(typeof(IBaseIn...

c#: How can I verify methods are called in a certain order?

I have the following class: public class Script { IPrinter _printer; public Script(IPrinter printer) { _printer = printer; } public void Print(TextWriter writer) { _printer.PrintComment(writer, "lolz"); writer.WriteLine("omg this complicates things"; _printer.PrintSpecial(writer)...

The new syntax for Rhino Mocks

Hi, I am struggling a bit to understand how the new AAA syntax works in Rhino Mocks. Most of my tests look like this: [Test] public void Test() { //Setup ISth sth= mocks.DynamicMock<ISth>(); //Expectations Expect.Call(sth.A()).Return("sth"); mocks.ReplayAll(); //Execution ...

What is wrong with Stubs for unit testing?

I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong with stubs. I haven't started using a mocking framework and I haven't started feeling the...

Method with Object argument won't accept anything other than an Object

We have a VB.net function with the following signature in class InitializerFactory: Public Shared Function Create(ByRef ui As Object) As IModeInitializer I'm attempting to test this function by passing in a mock of ui (using Rhino Mocks): MainForm ui = mocks.StrictMock<MainForm>(); IModeInitializer item = InitializerFactory.Create(re...

Is there any open source mocking framework resembling TypeMock?

TypeMock is too expensive for a hobbist like me :) Moq or the next version of RhinoMocks have no plans on listening to the profiling API, why is that? EDIT: This enables features such as: Mocking non-virtual methods and properties (!). Mocking browser environments. simpler syntax which is less fragile (and not having to go trough...

Rhino Mocks vs Moq for Silverlight

We are Silverlight Unit Test Framework for testing. Which one will be better for my team? Rhino Mocks or Moq. No one has any experience with using a framework like this. What are the pros and cons of using each framework in this environment? ...

Strict Mocks using AAA syntax of Rhino Mocks

Hi, Is it possible to create a "strict" mock using the new AAA syntax of Rhino Mocks? The issue I am seeing is that the library I am mocking often returns null as a valid return value (which I handle in my function), so using the default mock I can never be sure if I tested all paths or I forgot to set some expectations. ...