Hi, I have posted a longer description here: http://stackoverflow.com/questions/4927546/rhinomocks-generic-creation-of-mocks
In summary, how do I prepare a generic method, in which I pass a mock object (of different types), and a method name I need to stub, and it adds a predefined stubs for that method calls. I.e. if I have an interface IFace1, which has a method string DoIFace1Stuff(string), and another interface IFace2 with method string DoIFace2Stuff(string), I would like to prepare stubs/mocks for these to interfaces with exactly the same code without duplicating the declarations for AAA syntax. I need to test multiple classes, which depend on these injected interfaces, and I need to test the behavior of my tested classes when these interface methods return specific values like null, or throw an exception. So, for only one class/interface I'll do: IFace1 mock = MockRepository.GenerateMock<IFace1>(); mock.Stub(i =>i.DoIFace1Stuff(THROW_VALUE)).Throw(new Exception()); //etc for null - I can use some values to control what I need to happen MyTestClass1 test = new MyTestClass1(mock); test1.TestMethod(THROW_VALUE); Assert.Something(...); Now, as I said, I have few such an interfaces, which have one or many methods with the same signature string Do(string), and many classes I need to check against these interfaces. In order t not repeat the above code for each and every test, how can I create a factory method for my tests, so they generate the proper mock and stub the proper methods, so my tests would look like: IFace1 mock = GenerateStubbedMock(typeof(IFace1), "DoIFace1Stuff); MyTestClass1 test = new MyTestClass1(mock); .... do and assert Or maybe generic method like: T GenerateStubbedMock<T>(methodname, or some delgate, or???) Cheers Sunny P.S. This is Rhino 3.6 -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
