rhino-mocks

Mocking lambda in rhino mocks

I am trying to use Rhino Mocks to mock the following lambda, but keep hitting a brick wall var result = rep.Find<T>(x => (x as IEntity).ID == (entity as IEntity).ID).FirstOrDefault(); Any ideas? ...

Integration Test Example With Rhino Mocks

I have two classes. I would like to verify that the properties are called on one of the classes. public classA { public IBInterface Foo {get;set;} public LoadData() { Foo.Save(1.23456, 1.23456); } } public classB : IBInterface { public decimal ApplePrice {get; set;} public deci...

Returning a complex data type from arguments with Rhino Mocks

I'm trying to set up a stub with Rhino Mocks which returns a value based on what the parameter of the argument that is passed in. Example: //Arrange var car = new Car(); var provider= MockRepository.GenerateStub<IDataProvider>(); provider.Stub( x => x.GetWheelsWithSize(Arg<int>.Is.Anything)) .Return(new List<IWheel> { ...

Rhino Mocks Sample How to Mock Property

How can I test that "TestProperty" was set a value when ForgotMyPassword(...) was called? > public interface IUserRepository { User GetUserById(int n); } public interface INotificationSender { void Send(string name); int TestProperty { get; set; } } public class User { ...

Case insensitive expectations in Rhino Mocks

I'm using Rhino Mocks to expect a call. There is a single parameter which is a string. But I'm not bothered about the case of the string. I want the test to pass even if the case is wrong. So I'm doing the following: //expect log message to be called with a string parameter. //We want to ignore case when verifiyig so we use a cons...

What is the best testing pattern for checking that parameters are being used properly?

I'm using Rhino Mocks to try to verify that when I call a certain method, that the method in turn will properly group items and then call another method. Something like this: //Arrange var bucketsOfFun = new BucketGame(); var balls = new List<IBall> { new Ball { Color = Color.Red }, ...

How do I test a method on a class that calls another method in the same class using Rhino Mocks

I have a class that solves an equation using an approximation, evaluates the approximation and then refines the approximation(bisection method), rinse and repeat until the answer appears. In order to do that it needs to go and get various values from other complex classes. It also need to repeatedly call a method within itself to work ou...

Rhino mock vs Typemock vs JustMock vs...

I need to choose mock framework to new project. What are the pros and cons for those frameworks? Any comparison table? I know that JustMock is i beta stage but it's look very good right now (very similar to TypeMock) Edit: I'v What about MS Mole? ...

How to mock WCF Web Services with Rhino Mocks.

How do I test a class that utilizes proxy clients generated by a Web Service Reference? I would like to mock the client, but the generated client interface doesn't contain the close method, which is required to properly terminate the proxy. If I don't use the interface, but instead a concrete reference, I get access to the close method ...

How do I mock this value using Rhino Mocks

Here is the method I'm trying to test: public override void CalculateReductionOnYield() { log.LogEnter(); if (illus.RpFundStreams.Count <= 0) { throw new InvalidDataException("No regular premium fund streams which are required in order to calculate reduction on yield"); } // Add th...

Mock dll methods for unit tests

I am trying to write a unit test for a method, which has a call to method from dll. Is there anyway i can mock the dll methods so that i can unit test? public string GetName(dllobject, int id) { var eligibileEmp = dllobject.GetEligibleEmp(id); <---------trying to mock ...

Mock a void method which change the input value

Hi, How could I mock a void method with parameters and change the value parameters? I want to test a class (SomeClassA) which has a dependency on another class (SomeClassB). I would like to mock SomeClassB. public class SomeClassA { private SomeClassB objectB; private bool GetValue(int x, object y) { objectB.GetVa...

Mocking a non-settable child property with Rhino Mocks

I currently have interfaces much like the following: interface IService { void Start(); IHandler ServiceHandler { get; } } interface IHandler { event EventHandler OnMessageReceived; } Using Rhino Mocks, it's easy enough to mock IService, but it doesn't assign any IHandler instance to the ServiceHandler property. Therefore w...

Rhino Mocks and ordered test with unordered calls

I'm using Rhino.Mocks for testing the system. I'm going to check the order of calling .LoadConfig and .Backup methods. I need .LoadConfig to be the first. Currently the code is like this: var module1 = mocks.Stub<IBackupModule>(); var module2 = mocks.Stub<IBackupModule>(); module1.Expect(x => x.Name).Return("test"); module2.Expect(x ...

Mocking objects with complex Lambda Expressions as parameters

I´m encountering this problem trying to mock some objects that receive complex lambda expressions in my projects. Mostly with with proxy objects that receive this type of delegate: Func<Tobj, Fun<TParam1, TParam2, TResult>> I have tried to use Moq as well as RhinoMocks to acomplish mocking those types of objects, however both fail. ...

Disable selected automated tests at runtime

Is is posable to disable selected automated tests at runtime? I'm using VSTS and rhino mocks and have some intergation tests that require an external dependancy to be installed (MQ). Not all the developers on my team have this installed. Currently all the tests that require MQ inherit from a base class that checks if MQ is installed an...

Rhino Mocks Partial Mock

I am trying to test the logic from some existing classes. It is not possible to re-factor the classes at present as they are very complex and in production. What I want to do is create a mock object and test a method that internally calls another method that is very hard to mock. So I want to just set a behaviour for the secondary meth...

How to mock a property setter on a PartialMock using Rhino Mocks

I'd like to prevent the real setter code being invoked on a property on a partial class. What is the syntax for this? My current code to stub out the getter (I'd like to also stub out the setter): var user = MockRepository.GeneratePartialMock<User>(ctor params...); user.MyProperty = "blah"; Something like this? user.Stub(u => u.MyP...

Stubbing out methods that explicitly implement an interface using Rhino Mocks

How can I stub out methods that explicitly implement an interface using Rhino Mocks? As I understand it, Rhino Mocks requires stubbed out methods to be virtual, and explicitly implemented interface members are not virtual. ...

How to assert if a method was called within another method in RhinoMocks?

I have a class that has two methods. One method needs to call the other method and in my test I want to assert that it was called. public class Tasks : ITasks { public void MethodOne() { MethodTwo(1); } public int MethodTwo(int i) { return i + 1; } } I want to mock Tasks and do something like tasks.AssertWasCalled...