From: Heiko H. <rdr...@gm...> - 2007-09-11 11:09:37
|
Hello... This is my first post and I already got some complains.. I know its a great start, but here we go... Giving this code: IDbObject foo = _mocks.NewMock<IDbObject>(); Stub.On(foo).SetProperty("Id"); Expect.Once.On(foo).SetProperty("Id"); foo.Id = 123; _mocks.Verify.......; It will generate an exception. The reason is that the above code will not satisfy my expection, since the stub which was defined 1st, will catch the assignment and so the expection will never be reached. I think that an expection is much more important then a stub (Which is kinda a "Fallback" only). For example... I want to test a controller for a view, and Verify that the events are propperly setup and processed... I cannot create an implicit setup for the view (which creates the view and stubs all events), and then attach a real expection onto the view, that will allow me to sneak a mockEvent in, so i can fire it from the outside, and verify that the controler does its work. I currently need to declare an implicit setup, which defines expections, since those can be removed by adding a "fake" Handler on the Mock e.g.: //Inside CreateViewAndSetupBasicEvents Function Expect.Once.On(mockedView).EventAdd("Save", Is.Anything); //Inside my "real" test function... mockedView.Save += null; Expect.Once.On(mockedView).EventAdd("Save", Is.Anything) .Will(MockEvent.Hookup(mockevent)); mockEvent.Raise(); Hope this makes sense.... I know i could "fix" it, by creating the view 1st and then adding the expections, and THEN finally adding all the stubs... But i kinda got attached to my setup functions so i can create and setup a basic mock with one call... Without that I would have to move the creation of the mock around, and I feel like i am "loosing" some clarity in my test, if I move to much into the "general" setup method. -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer |