rhino-mocks

Unable to add Rhino Mocks 3.5 to a .NET 2.0 project in Visual Studio 2010

We're upgrading from Dev Studio 2005 to Dev Studio 2010. I opened my 2005 solution in Visual Studio 2010 and went through the conversion process keeping all projects targeted at .NET 2.0. When I try to build the project, my references to Rhino.Mocks.dll are failing to be used. I see errors like this: DalDiscoveryTest.cs(7,7): error ...

RhinoMocks: how to test if method was called when using PartialMock

I have a clas that is something like this public class MyClass { public virtual string MethodA(Command cmd) { //some code here} public void MethodB(SomeType obj) { // do some work MethodA(command); } } I mocked MyClass as PartialMock (mocks.PartialMock<MyClass>) and I setup expectation for MethodA var cmd = ne...

Rhino Mock how to loop expectations

var dependency1 = MockRepository.GenerateMock<IDependency1>(); var dependency2 = MockRepository.GenerateMock<IDependency2>(); var dependency3 = MockRepository.GenerateMock<IDependency3>(); using(dependency2.GetMockRepository().Ordered()) { using (dependency1.GetMockRepository().Ordered()) { using (dependency3.GetMockRepo...

Stub not returning correct value with Rhino Mocks 3.6

Hi I'm trying to write a test using Rhino Mocks 3.6 with AAA. The problem I'm running into is that the Stub i've set up doesn't seem to be returning the correct object. The following test fails: [SetUp] public void SetUp() { repository = new MockRepository(); webUserDal = repository.Stub<IWebUserDal>(); ...

Is Entity Framework more mockable than Linq2Sql?

I've found that Linq2Sql doesn't (Rhino) mock well, as the interfaces I need aren't there. Does EF generate code that's more mockable? NOTE: I'm not mocking, yet, without interfaces, the next reader of this question may not have my bias. EDIT: VS2008 / 3.5 for now. ...

Rhino Mocks - Fluent Mocking - Expect.Call question

Hi, I'm trying to use the fluent mocking style of Rhino.Mocks and have the following code that works on a mock IDictionary object called 'factories': With.Mocks(_Repository).Expecting(() => { Expect.Call(() => factories.ContainsKey(Arg<String>.Is.Anything)); LastCall.Return(false); Expect.Ca...

Cannot mock class with constructor having array parameter using Rhino Mocks

Hi, We cannot mock his class in RhinoMocks. public class Service { public Service(Command[] commands){} } public abstract class Command {} // Code var mock = MockRepository.GenerateMock<Service>(new Command[]{}); // or mock = MockRepository.GenerateMock<Service>(null) Rhino mocks fails complaining that it cannot find a construct...

Mock Assertions on objects inside Parallel ForEach's???

Any idea how we can assert a mock object was called when it is being accessed inside Parallel.ForEach via a closure? I assume that because each invocation is on a different thread that Rhino Mocks loses track of the object? Pseudocode: var someStub = MockRepository.GenerateStub() Parallel.Foreach(collectionOfInts, anInt => someStub.Do...

Do we really need isolation frameworks to create stubs?

I have read this: http://martinfowler.com/articles/mocksArentStubs.html My concepts about a stub and a mock are clear. I understand the need of isolation frameworks like moq, rhinomocks and like to create a mock object. As mocks, participate in actual verfication of expectations. But why do we need these frameworks to create stubs. I wou...

Rhino Mocks 3.5 Test that property setter was not called

Is it possible to test that a property setter has not been called using Rhino Mocks 3.5? ...

How to add items to a list in Rhino Mocks

I have method (which is part of IMyInteface) like this: interface IMyInterface { void MyMethod(IList<Foo> list); } I have the ClassUnderTest: class ClassUnderTest { IMyInterface Bar {get; set;} bool AMethod() { var list = new List<Foo>(); Bar.MyMethod(list); return list.Count()>0; } My Test with Rhino ...

Difference in techniques for setting a stubbed method's return value with Rhino Mocks

What is the main difference between these following two ways to give a method some fake implementation? I was using the second way fine in one test but in another test the behaviour can not be achieved unless I go with the first way. so (the first), using (test.Record()) //test is MockRepository instance { service.GetUser("dummyName"...

RhinoMocks Testing callback method

Hi All I have a service proxy class that makes asyn call to service operation. I use a callback method to pass results back to my view model. Doing functional testing of view model, I can mock service proxy to ensure methods are called on the proxy, but how can I ensure that callback method is called as well? With RhinoMocks I can tes...

Verify an event was raised by mocked object

In my unit test how can I verify that an event is raised by the mocked object. I have a View(UI) --> ViewModel --> DataProvider --> ServiceProxy. ServiceProxy makes async call to serivce operation. When async operation is complete a method on DataProvider is called (callback method is passed as a method parameter). The callback method t...

Error using MVCContrib TestHelper

While trying to implement the second answer to a previous question, I am receiving an error. I have implemented the methods just as the post shows, and the first three work properly. The fourth one (HomeController_Delete_Action_Handler_Should_Redirect_If_Model_Successfully_Delete) gives this error: Could not find a parameter named 'con...

How to test silverlight behaviors using Rhino Mocks?

I have slightly adapted the custom behavior code that can be found here: http://www.reflectionit.nl/blog/default.aspx?guid=d81a8cf8-0345-48ee-bbde-84c2e3f21a25 that controls a MediaElement. I need to know how to go about testing this with Rhino Mocks e.g. how to instantiate a new ControlMediaElementAction in test code and then call the...

Mocking SQL output parameter

I mocked a couple of methods of my Data Access layer, but in some methods the value of an SQL output param is set. How can I mock this ? Method: var wrappedParameters = new SqlParameter[3]; wrappedParameters[0] = new SqlParameter("@username",username); wrappedParameters[1] = new SqlParameter("@password",passwor...

RhinoMocks - Mocking Protected virtual members

As far as I know, RM should mock anything that can be accessed by a derived class. Since a protected virtual member is accessible from a subclass, shouldn't it be mockable? My understanding is that RM does not support mocking protected virtual members. ...

Seeding repository Rhino Mocks

I am embarking upon my first journey of test driven development in C#. To get started I'm using MSTest and Rhino.Mocks. I am attempting to write my first unit tests against my ICustomerRepository. It seems tedious to new up a Customer for each test method. In ruby-on-rails I'd create a seed file and load the customer for each test. It se...

What is the purpose of unit testing an interface repository

I am unit testing an ICustomerRepository interface used for retrieving objects of type Customer. As a unit test what value am I gaining by testing the ICustomerRepository in this manner? Under what conditions would the below test fail? For tests of this nature is it advisable to do tests that I know should fail? i.e. look for id 4 when...