rhino-mocks

Question about Rhino Mock (RhinoAutoMocker)

I have a question about Rhino Mock. I am trying to put restriction on what methods could be called from the method that is under test. Lets say I have a method that I am writing the Unit Test against like this: public void MyMethod() { var test = _Repository.Get(2); _Services.DoSomething(test); } what I do right now is someth...

test driven expect me to expect exception ,MStest not . why ? or, how to do it for testdriven

hello everyone i'm testing method foo() : [TestClass] class myTestClass { myTestClas() { var MockedProg = Mocks.Stub<myProg>(); } >[TestMethod] someTestName() { using (Mocks.Record()) { MockedProg.firstTest(); MockedProg.SecondTest(); MockedProg.th...

How To Write Unit Test For Method Returning JsonResult With RenderPartialViewToString?

If you look at the example at this link: http://www.atlanticbt.com/blog/asp-net-mvc-using-ajax-json-and-partialviews/ How would one write a unit test for the JsonAdd method? I have a similar situation in my own code, but the RenderPartialViewToString errors when calling: ViewEngineResult viewResult = ViewEngines.Engines.FindPartial...

Rhino Mocks stubbing an event with ref parameter

I'm trying to call an event from my mocked object. I'm doing it like: importObject.Raise(x => x.RequestImportLevel += null, false, false, true, importLevel); the last parameter required to be passed by reference. So, i'm getting an exception Parameter #4 is System.Int16 but should be System.Int16& What can I do to handle this...

Rhinomocks with .net 4 threading

So I have a little app which will process a load of files and I'm trying to write tests for the class which will handle looping through the files and firing them to various places. This was an obvious place to try out the new parallel library stuff. Heres a simplified version of the code I'm testing: public void ProcessSomeFiles(IEnumer...

Unit testing a method with no observable state change

Hello all, (C#, Rhino Mocks, MbUnit). I have a class called AccountManager that has a RegisterUser() method. This method returns void but does throw an exception for any errors. AccountManager calls into an IDataRepository calling its AddUser() method to do a database insert. I'm mocking the IDataRepository using a Rhino Mock and thro...

Issue With RhinoMocks and Generics

Here's my test code: var container = MockRepository.GenerateMock<UnityContainer>(); container.Expect(e => e.RegisterType<IEventAggregator, EventAggregator>( Arg<ContainerControlledLifetimeManager>.Is.Anything)); Basically I'm going to assert that a class that takes a IUnityContainer interface sets up the container in an expected wa...

RhinoMocks - mock a concrete type - run constructor

I've got the following line, attempting to create a mock of a concrete type: AddPropPersonalCOI = MockRepository.GenerateMock<SomeType>(ObjectFactory.GetInstance<paramType1>(), ObjectFactory.GetInstance<paramType2>()); Assert.IsNotNull(AddPropPersonalCOI.view); I've actually stepped into the constructor in question, watched it execut...

Formulating both general and specific stub-methods?

Hello, in order to test another class, I want to create a stub for an interface IFoo: public interface IFoo { int DoSomething(int value); } The stub is created in the SetUp (or TestInitialize)-method for the test fixture and stored in a property as almost all test methods need an IFoo: this.Foo = MockRepository.GenerateStub<IFoo...

RhinoMocks - Pass Action<T> as parameter

In RhinoMocks, there's Stub extension method, that takes Action<T>. For some reason this: CurrentInvoice.Stub(i => i.TaxYear).Return(1); works great, but this: CurrentInvoice.Stub(new Action<Invoice>(i => i.TaxYear)).Return(1); produces the compiler error: Only assignment, call, increment, decrement, and new object expressions ca...

How can I setup default actions for a rhino mocked interface in a setup method, which can be overridden for specific behavior in a test method?

Hello :) I would like to mock an interface that's passed in as the main argument to a function, but the method is complicated, and as a result I don't want to have to specify defaults or exact behavior for every test. I'd like to specify defaults in a Setup method, and override specific parts of that in each test as required. I.e.: pu...

Tramp Data vs. Testability

I'm not doing much new development right now, but a lot of refactoring of older C# subsystems whose original requirements no longer support new and I'll add unexpected requirements. I'm also now using Rhino Mocks and unit tests where possible (vs 2008). The dilemma for me is that to make the methods testable and mockable, I need to defi...

Rhino Mocks - Using Arg.Matches

Hi, I have a function I am mocking which takes an argument object as a parameter. I want to return a result based on the values in the object. I cannot compare the objects as Equals is not overriden. I have the following code: _tourDal.Stub(x => x.GetById(Arg<TourGet>.Matches(y => y.TourId == 2), null)).Return( new Tou...

Mocking without injection

Hello all, (C#, WCF Service, Rhino Mocks, MbUNit) I have been writing tests for code already in place (yes I know its the wrong way around but that's how its worked out on my current contract). I've done quite a bit of re-factoring to support mocking - injecting dependencies, adding additional interfaces etc - all of which have improve...

How can I rhino mock a method that returns the passed in argument?

I want a mocked interface method that returns the value that is passed in to it, in this case a string. The method signature is: string GetLooUp( string thingToLookUp ) I thought this anonymous delegate would work, but it throws an exception on this declaration. Maybe this isn't the right approach? Expect.Call( mockIThing.GetLookUp...

Rhino mocks .Repeat.Any() not working for me

I was having problems with a second call on a mock in my test run, so I moved the double calls into the test method. I have this: RefBundle mockIRefBundle = mocks.StrictMock<IRefBundle>(); Expect.Call(mockIRefBundle.MaxTrackItems).Return( 6 ).Repeat.Any(); int q = mockIRefBundle.MaxTrackItems; int z = mockIRefBundle.MaxTrackItems; I...

RhinoMock : Mocks Vs StrictMocks Vs DynamicMocks

I understand the difference between a Mock and a Stub. But different types of Mocks in RhinoMock framework confuses me. Could someone explain the concepts of Mocks Vs StrictMocks Vs DynamicMocks in terms of RhinoMock framework. your answers are greatly appreciated. ...

Unit testing/How to assert a non-mocked method was called/C#/Rhino Mocks/NUnit

Hi, I have a MailService which permit me to send Email which implement the following Interface. public interface IMailService { bool SendRegisteringEmail(RegisterModel registerModel); bool SendMail(MailMessage mailMessage); MailMessage CreateRegisteringMailMessage(RegisterModel registerModel); IAppSettingsRepository ...

Is "Record" Deprecated in Rhino Mocks

The latest version of Rhino mocks supports Arrange, Act Assert methodology. Does that mean that the record method that it used in previous version is deprecated? I thought it was (deprecated), but as I was reading "The Art of Unit Testing" he uses the Record method when he introduces Rhino Mocks. So now I am not so sure.... Any one k...

Why is mocking preferred with Interfaces?

I have been looking at examples of mocking using Moq and Rhino Mocks and all the examples seem to mock interfaces. Why is this? I have heard they can mock static classes, but what about non-static classes? ...