Rhino Mocks Stub Ref Parameter



A quick tip here, we've just spent what felt like ages trying to Stub a method with a ref parameter using RhinoMocks, you'll also need NUnit for the code below to work.

The problem we had was for the .Ref() method we needed an AbstractContraint but the normal Is.Anything didn't work, but if you use: Rhino.Mocks.Constraints.Is.Anything() it works fine.

RhinoMocks Stub with a Ref Parameter Example

using NUnit.Framework;
using Rhino.Mocks;

namespace RhinoRef
{
	[TestFixture]
    public class RhinoMockRefTests
    {
		[Test]
		public void Should_be_able_to_stub_a_ref_parameter_in_rhino_mocks()
		{
			var repo = MockRepository.GenerateStub();

			repo.Stub(r => r.Get(Arg.Is.Anything, ref Arg.Ref(Rhino.Mocks.Constraints.Is.Anything(), 0).Dummy))
				.Return("StubQuestion");

			int theAnswer = 42;
			var theQuestion = repo.Get("anything", ref theAnswer);
			Assert.That(theQuestion,Is.EqualTo("StubQuestion"));
		}
    }

	public interface IGetThingsOutOfTheDatabase
	{
		string Get(string name, ref int awkwardParameter);
	}
}

 


DIP - The Dependency Inversion Principle



Here it is the final SOLID principle the Dependency Inversion Principle. In this brief video we'll talk about Robert Martin's premise that:

A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.

Shoutout

The opening drawing of 'inverted dependents' was originally by Tim Musgrove, it made me laugh, full credit to him for that :)

SOLID Principles

The SOLID principles are namely.


Search

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2013