rhino-mocks

Mocking View with RhinoMocks

We are using MVP (Supervising Controller) for ASP.NET WebForms with 3.5 SP1. What is the preferred way to check the value of a view property that only has the a set operation with RhinoMocks? Here is what we have so far: var service = MockRepository.GenerateStub<IFooService>(); // stub some data for the method used in OnLoad in the pr...

Testing In A Try Catch With Moq Compared To Rhino Mocks

I've just been working on some tests using Moq but ran into trouble trying to test a method I wanted to call twice through a try catch block. The principle is that the first call throws an exception, then in the catch I correct the problem and call the method again. I managed to do it with Rhino Mocks as below but being new to both fra...

Rhino Mocks stubs and mocks are only good for interfaces?

Is it correct that Rhino Mocks stubs and mocks are only good for interfaces, not concrete classes? I spent quite a time trying to make this piece of code working. What I did not expected is that stabbed pubSubClient will always call Send method from the class. That method has some dependencies and throws exception. [Test] public void Te...

RhinoMocks and Heisenbugs

I've been using RhinoMocks lately but I keep running into an issue. If I break into the debugger and step over code while a mock is in Record mode, I end up getting an exception along the lines of: System.InvalidOperationException: Previous method 'SuchAndSuch.ToString();' requires a return value or an exception to throw. But if I ...

Rhino Mocks DynamicMultiMock - setting expectation with return value on additional interface

Hello, I am creating a DynamicMultiMock as follows: this.serviceClient = this.mocks.DynamicMultiMock<ISlippyPlateProcedureService>(typeof(ICommunicationObject)); Then setting the following expectation: Expect.Call(((ICommunicationObject)this.serviceClient).State).Return(CommunicationState.Faulted); When I execute the test, Rhino M...

Unit Test For NpgsqlCommand With Rhino Mocks

My unit test keeps getting the following error: "System.InvalidOperationException: The Connection is not open." The Test [TestFixture] public class Test { [Test] public void Test1() { NpgsqlConnection connection = MockRepository.GenerateStub<NpgsqlConnection>(); // Tried to fake the open connection c...

How to use the AAA syntax to do an AssertWasCalled but ignore arguments

I'm using the new AAA syntax and wanted to know the syntax to do the below and have the mock ignore the agruments. mockAccount.AssertWasCalled(account => account.SetPassword("dsfdslkj")); I think the below is how I would do this with the record/ replay model but I wanted to see if this could be done with AAA using 3.6 mockAccount.Expe...

How can I replace an already declared Stub call in rhino mocks with a different Stub call?

If I have a Rhino Mock object that has already has a Stub call declared on it like this... mockEmploymentService.Stub(x => x.GetEmployment(999)).Return(employment); Is there anyway I can remove this call to replace it with something different eg... mockEmploymentService.Stub(x => x.GetEmployment(999)).Return(null); The reason I ask i...

Rhino Mocks, Dependency Injection, and Separation of Concerns

I am new to mocking and dependency injection and need some guidance. My application is using a typical N-Tier architecture where the BLL references the DAL, and the UI references the BLL but not the DAL. Pretty straight forward. Lets say, for example, I have the following classes: class MyDataAccess : IMyDataAccess {} class MyBusines...

Argument constraints in RhinoMock methods

I am mocking a repository that should have 1 entity in it for the test scenario. The repository has to return this entity based on a known id and return nothing when other ids are passed in. I have tried doing something like this: _myRepository.Expect(item => item.Find(knownId)).Return(knownEntity); _myRepository.Expect(item => item.Fi...

Best way to mock WCF Client proxy

Are there any ways to mock a WCF client proxy using Rhino mocks framework so I have access to the Channel property? I am trying to unit test Proxy.Close() method but as the proxy is constructed using the abstract base class ClientBase<T> which has the ICommunicationObject interface, my unit test is failing as the internal infrastructure ...

TDD a controller with ASP.NET MVC 2, NUnit and Rhino Mocks

What would a simple unit test look like to confirm that a certain controller exists if I am using Rhino Mocks, NUnit and ASP.NET MVC 2? I'm trying to wrap my head around the concept of TDD, but I can't see to figure out how a simple test like "Controller XYZ Exists" would look. In addition, what would the unit test look like to test an...

RhinoMocks Stub return real instance

I'm trying to use RhinoMocks to stub out a third party component. The third party component looks like the following. public class connection { public connection(string host,int port) {} public void Submit(message msg) {} } public class message { public message(string recipient) {} { When I attempt to use a s...

Rhino Mocks - Difference between GenerateStub<T> & GenerateMock<T>

Can any of the Rhino experts explain me by giving a suitable example of the differnce between the above methods on the MockRepository class (Rhino Mocks framework).Where should one use Stub over Mock method or otherwise? ...

How to test if raising an event results in a method being called conditional on value of parameters

I'm trying to write a unit test that will raise an event on a mock object which my test class is bound to. What I'm keen to test though is that when my test class gets its eventhandler called, it should only call a method on certain values of the eventhandler's parameters. My test seems to pass even if I comment the code that calls Pro...

When using a mocking framework and MSPEC where do you set your stubs

I am relatively new to using MSpec and as I write more and more tests it becomes obvious to reduce duplication you often have to use a base class for your setup as per Rob Conery's article I am happy with using the AssertWasCalled method to verify my expectations, but where do you set up a stub's return value, I find it useful to set th...

How to write a test for accounts controller for forms authenticate

Trying to figure out how to adequately test my accounts controller. I am having problem testing the successful logon scenario. Issue 1) Am I missing any other tests.(I am testing the model validation attributes separately) Issue 2) Put_ReturnsOverviewRedirectToRouteResultIfLogonSuccessAndNoReturnUrlGiven() and Put_ReturnsRedirectResu...

How to mock protected virtual members with Rhino.Mocks?

Moq allows developers to mock protected members. I was looking for the same functionality in Rhino.Mocks but fail to find it. Here's an example from Moq Quick Start page how to mock protected method. // at the top of the test fixture using Moq.Protected() // in the test var mock = new Mock<CommandBase>(); mock.Protected() .Setup...

Unit Test this - Simple method but don't know what's to test!

a very simple method, but don't know what's to test! I'd like to test this method in Business Logic Layer, and the _dataAccess apparently is from data layer. public DataSet GetLinksByAnalysisId(int analysisId) { DataSet result = new DataSet(); result = _dataAccess.SelectAnalysisLinksOverviewByAnalysisId(analysisId); ...

Mocking advantages over nUint

I am new to testing.I have to test some C# classes.Kindly let me know what is mocking and why some mocking framework like Rhino mock is preferred over nUint? ...