rhino-mocks

RhinoMocks AssertWasCalled on mocked object's method that needs to have an object returned?

Using RhinoMocks, I have a catch-22 situation: I want to verify that a method is called, but this method needs to have an object returned on it because the returned object is acted on in the next line. In other words, mocking on the interface just returns a null value, but not mocking it up doesn't give me any way to verify that the meth...

Use Rhino Mocks to create an in-memory database for use while developing code and user interface

Hi Everyone, I've been struggling with this all morning and I may be completely on the wrong track since Rhino Mocks was originally designed for Unit Testing. However, I have a couple of resusable backend components that handle Authentication and 'Blogging' like features of a website, each contains their own data access layer. While d...

How can I test for null arguments in the constructor of abstract class using rhino mocks?

I have a class like so: public abstract class ClassA<T> { protected ClassA(IInterface interface) { if (interface== null) { throw new ArgumentNullException ("interface"); } } } I want to write a test which verifies that if I pass null in the exception is thrown: [Test] [ExpectedExcep...

How to Mock a Static Singleton?

I have number of classes I've been asked to add some unit tests to with Rhino Mocks and having some issues. First off, I know RhinoMocks doesn't allow for the mocking of Static members. I'm looking for what options I have (besides using TypeMock). An example of the class I have is similar to the below: class Example1 : ISomeInterface...

RhinoMocks - Fetching parameters of called functions

Using RhinoMocks - can I fetch the parameters of a called function? I mean; can I get some of the unknown parameters from the function call out? I have a mock, and I expect some function to be called on this. I know one of the parameters, but the other one is unknown as this comes from the class that uses the mock and calls a function ...

Stubbing a read only property with Rhino Mocks

I have a class with a private set property that I want to stub out with rhino mocks. When I try to do this, though, it gives me a compile time error saying I can't set a read only property. I'm new to using Rhino Mocks so I must be missing something here... public Interface IFoo { int Quantity { get; } } [TestMethod] public void ...

How can I mock Server.HtmlEncode

I am trying the following, but I am getting : Object reference not set to an instance of an object. HttpContextBase mockContext = MockRepository.GenerateMock<HttpContextBase>(); mockContext.Expect(c => c.Server.HtmlEncode("")).IgnoreArguments().Return(""); mockContext.Expect(c => c.Server.HtmlDecode("")).Return(""); controller.Con...

RhinoMocks - Specifying return for functions called later

Using RhinoMocks - how can I say "whenever some function is called from now on - it should return some value". I'd like to say something like this: fakeCalculator.WhenCalled(factory => factory.AddNumbers(1, 2)).Return(3); And then - when the AddNumbers function is called with 1 and 2 - it will return 3. I.e. I want to define this ...

Rhino Mocks AAA Quick Start?

Hi, I've been looking around for some decent information on using Rhino Mocks 3.5+ with the AAA syntax. I find a lot of blogs that have a mix of things from the old and new which seem to make it more difficult to figure out how to use it. Would would be great would be if there were a Rhino Mocks AAA Cheat Sheet like was done for an earl...

How to test a writeonly property

Hi, In my application, using MVP pattern, presenter is setting some properties on view.For example, Iview has string Customer {set;}.Now, I want to test that this property was set with some value "x".How can I do the test with rhino mocks? ...

rhino mocks mocking a call

Hi all, I have a method that I want to test which hits the database. From what I have read this is a perfect oppurtunity to use a mock. However the problem that I am facing is that I pass the object a string and then it creates an object and hits the db with this object i.e. public void test(string t) { Test t1 = new Test(t); d...

Rhino Mock stub returns different type from expected and breaks my unit test

Related to yesterday's question. I implemented the solution proposed by Mehrdad Afshari but this caused another problem. To recap: I have a class containing a dictionary of Type->IList<Type> e.g. Cat->{cat1, cat2}, Zebra->{zebra1, zebra2} where Cat and Zebra are subclasses of Animal. Now Mehrdad proposed the following method to retriev...

MockUnitOfWork 'Cannot resolve symbol MockUnitOfWork'

Hi, I'm trying to get Figure 3 Fake Database from IRepository using the example here http://msdn.microsoft.com/en-us/magazine/dd263069.aspx public class InMemoryRepository : IRepository { private readonly Cache<Type, object> _types; private MockUnitOfWork _lastUnitOfWork; public InMemoryRepository() { _types = n...

Getting DRY with Rhino Mocks

I am looking for ways of making the following more concise. public class MyTests { IPresenter presenter; [SetUp] public void SetUp() { presenter = MockRepository.GenerateStub<IPresenter>(); } ... } In particular specifying the type again when creating the mock seems redundant. For example I can write...

How do I mock a Where clause in EF4

I am re-writing this question to make it clearer what I need to do. I am trying to use Rhino-Mock to test: public IQueryable<TxRxMode> GetAllModes() { return m_context.TxRxModes.Where(txRxMode => txRxMode.Active); } Here's the code: var context = MockRepository.GenerateStub<IProjectContext>(); //Returns an empty ...

Dynamically Subscribing to Events in RhinoMocks

We're currently migrating from NMock2 to RhinoMocks and we're having trouble replicating this code: foreach (EventInfo e in typeof(MarketMapPopupIMVPView).GetEvents()) Expect.Once.On(mockView).EventAdd(e.Name, new TypeMatcher(typeof(EventHandler))); Essentially this was placed inside a template for MVC controls to ensure that deve...

Can Rhino Mock deeper/nested members directly?

Is it possible to mock a stub/mock's object member call without having to define that as a stub, and also set the return value as all seperate verbose lines? Example: [TestMethod] public void AssignedPermissions_AssociateExists_ReturnsEdit_Rhino() { //Arrange var fakeConfiguration = MockRepository.GenerateSt...

Unable to figure out rhino mocks issue

Hi, In a method in presenter,I expect a method of view to be called.This method is also passed data extracted from a service method(which is not mocked).This service method basically gets data from database and returns List(using LINQ to SQL).Now, when I write this in the test List<customers> cus = expecteddata; view.AssertWasCalled(...

Has anyone unit tested a HttpModule in ASP.NET using rhino Mocks framework?

If so can you pls supply a sample test.... ...

Troubles with simple mocking using RhinoMocks .NET

I am trying to experiment with RhinoMocks, where I have to say I am a newbie and probably I don't get some obvious thing here. What I'm doing is something like : [TestMethod] public void SaveResponsibleUserFromChangeset() { var action = mocks.StrictMock<GenomeAction>(); var changeset = new ActionChangeset(); ...