rhino-mocks

Using Rhino Mocks, why does invoking a mocked on a property during test initilization return Expected call #1, Actual call #0?

I currently have a test which tests the presenter I have in the MVP model. On my presenter I have a property which will call into my View, which in my test is mocked out. In the Initilization of my test, after I set my View on the Presenter to be the mocked View, I set my property on the Presenter which will call this method. In my te...

Rhino Mocks AssertWasCalled (multiple times) on property getter using AAA.

I have a mocked object that is passed as a constructor argument to another object. How can I test that a mocked object's property has been called? This is code I am using currently: INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>(); newContact.Stub(x => x.Forenames).Return("One Two Three"); someobj...

Mocking the FormsAuthentication.Authenticate() method

Is there any way I can mock FormsAuthentication.Authenticate("username", "password") method with test credential? My test goal is to make sure that if authentication fails, it redirects to correct place. I'm using Rhino Mocks as mocking framework. Thank you very much for your help, ...

Rhino Mocks: How to clear previous expectations on an object?

I would like to set up a return value _stubRepository.Stub(Contains(null)).IgnoreArguments().Return(true); but then in a specific test, override that expectation to return false. Something like _stubRepository.ClearExpectations(); //<- this does not exist, I'm just making something up _stubRepository.Stub(Contains(null)).IgnoreAr...

What is the AAA syntax equivalent to using Ordered() in Rhino Mocks

I can't for the life of me find the proper syntax using the Fluent/AAA syntax in Rhino for validating order of operations. I know how to do this with the old school record/playback syntax: MockRepository repository = new MockRepository(); using (repository.Ordered()) { // set some ordered expectation...

Can I get the parameters used in an expectation in Rhino Mocks?

I am setting up an expectation for a call to a method that builds and executes a query. I would like to interrogate the properties of the parameter used. Is this possible using (mocks.Record()) { Expect.Call(connection.Retrieve(SOMETHING_HERE)).Return(returnedDatay); } The bit I am after is the "SOMETHING HERE" bit. (This is my f...

Testing an object's state at save

I'm looking to write unit tests for a method such as this one: public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { ISPMembershipUserDao userDao = GetISPMembershipUserDao(); if (ValidateUser(username, password)) { SPMembershipU...

Mocking a Customer SessionHandler Object in ASP.NET MVC for Unittests with Rhino Mocks

Hi folks, I currently use the following approach to create a strongly typed object representing session variables. public abstract class SessionController : Controller { private const string SESSION_NAME = "UserSession"; public SessionData SessionData { get { SessionData sessionData = (SessionDa...

How do you stub IQueryable<T>.Where(Func<T, bool>) with Rhino Mocks?

In the .net 3.5 project that I am working on right now, I was writing some tests for a service class. public class ServiceClass : IServiceClass { private readonly IRepository _repository; public ServiceClass(IRepository repository) { _repository = repository; } #region IServiceClass Members pu...

Mocking RouteTable.Routes.GetVirtualPath in MVC

Hi, I have a paging controller with a method which calls RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, valueDictionary) I am trying to test this method using Rhino mocks and I'm unsure how to mock GetVirtualPath to return a route other than null. I am mocking the RequestContext but I am unsure which methods/prop...

RhinoMock help: Mocking WCF service

Hi! I'm trying to use RhinoMock for mocking out a wcf service. Say I have the following service: [OperationContract] List<User> SearchUsers(UserSearchFilter filter); Adding this service with Visual Studio will generate a proxy, and that proxy has a Interface like: public interface ResourceService { System.IAsyncResult ...

Why does my partial mock have all virtual methods mocked, even if no expectations are set?

I have a user control which does some validation in the ValidateChildren method which I would like to test. I have created a partial mock of the user control, but although I am not setting any expectations on the ValidateChildren method, I am simply calling it, it is simply skipped and the code inside the method never executes. To try ...

How can I use Rhino Mocks to mock a MEF export?

With reference to the Managed Extensibility Framework (MEF), I'm trying to work out how to create clean tests with mocks. I have an exported component which has three private imports. Each imported object (field) needs to be mocked. Given that the CompositionContainer uses fancy reflection tactics to set imported private fields of compo...

How to mock or stub a .netTiers generated DataRepository object

I am using Rhino mocks for unit test mocking of objects. Our DAL uses codesmith to generate code from .netTiers templates, which creates these DataRepository classes that contain all the methods for CRUD type transaction to the datasource. In unit testing, I am trying to mock this data repository object which has no interface class to us...

NMocks2 Argument Syntax in Rhino Mocks?

In NMocks2 you can mock up the result of a method you don't know the arguments to before hand using Stub.On(aMock) .Method( ... ) .WithAnyArguments() .Will(Return.Value( ... ); from NMocks2 Cheatsheet. My question is, is there a similar mechanism for Rhino mocks when you don't care about the arguments? I want to make a ...

Using Lambda in Unit Test in VB.NET 2008 with Rhino.Mocks

Hi, I am trying to create a unit test similar to how I would have done one in C# but am struggling with the lambdas in vb. Bascially I am trying to mock a class and then create a stub and return. In C# I would have done something like; MockedPersonRepository .Stub(x => x.Find(id)) .Return(person) But in visual basic I am t...

Rhino Mocks: Can I use Stub() when one of my parameters is Expression<Func<T1, T2>>?

I have a method on an interface that looks like this and I want to stub it with Rhino Mocks: TValue GetPropertyOfExistingObject<TValue>(long id, Expression<Func<T, TValue>> propertyExpression); My code that does the stubbing looks like this: var service = MockRepository.GenerateStub<IQuoteService>(); service.Stub(s => s.GetPropertyOf...

Parameter constraints

Hello, I am using the Rhino Mocks framework. I referenced the Rhinomocks dll and everything worked fine.. but when I was trying to use the LastCall.Constraints(Is.Anything()) it says: Error The name 'Is' does not exist in the current context The same happens with Text and List constraints.. any help?? ...

Is there a difference between SetupResult and Stub in RhinoMocks?

Is there, if any? : var storage = mocks.DynamicMock<IStorage>(); ... SetupResult.For(storage.GetCustomers()) .Return(new Collection<Customer> { cust1, cust2 }); // and storage.Stub(x => x.Customers) .Return(new Collection<Customer> { cust1, cust2 }); ...

Function stubbed out with Structuremap Automocking not returning value

Using Josh Flanagans StructureMap Automocking overview, I'm trying my hand at it but can get the following code to return the Category object I've assigned: [Test] public void Service_Should_Return_Category_From_ID() { // Arrange var categoryToTest = new Category() { ID = 1, Name = "Department 1", Description = ...