Hi,
Thx but that doesn't solve the issue now i am getting error inside the
Presenter where I am passing the "ViewStub" the error says
"System.InvalidOperationException: Previous method 'ISampleView.get_Name();'
requires a return value or an exception to throw.."
Also as you have suggested i tried to use the stub method but when i set
property using viewStub.Stub(x => x.Name).Return("zz") then i get error "
System.InvalidOperationException: You are trying to set an expectation on a
property that was defined to use PropertyBehavior.", so i removed the
property setting command and instead set directly viewStub.ErrorDisplay =
"ZZ" that worked .
Thx for the help
Rgds,
Raghu
On Thu, Mar 5, 2009 at 7:43 PM, andreister <[email protected]> wrote:
>
> As far as you create a strict mock, it will throw on any unexpected
> calls. Not sure why you need to look on its properties in debugger,
> but you'd probably have to put something like
>
> viewStub.Stub(x => x.Name).Return("zz")
>
> for the fields you use. Back to your example - should work if you
> update mock creation to
>
> ISampleView viewStub = mocks.Stub<ISampleView>();
>
>
> Hope this helps,
> Andrew
>
>
> On Mar 4, 7:09 pm, rags <[email protected]> wrote:
> > I am trying write Unit Test cases for the below mentioned interface,
> > but I am getting error in the Properties of the Interface after
> > i call the CreateMock Method.
> >
> > My Interface
> > -----------------
> >
> > public interface ISampleView
> > {
> > string Name { get; set; }
> > string ErrorDisplay { get; set; }
> > event EventHandler SaveClicked;
> > }
> >
> > MyPresenter
> > -------------------
> > public class SamplePresenter
> > {
> > private ISampleView _view;
> >
> > public SamplePresenter(ISampleView view)
> > {
> > this._view=view;
> >
> > //Wire up the events
> > this._view.SaveClicked +=new EventHandler
> > (view_SaveClicked);
> > }
> >
> > public void SetName()
> > {
> > this._view.Name = "Name";
> > }
> >
> > public void view_SaveClicked(object sender, EventArgs e)
> > {
> > if (this._view.Name == null || this._view.Name ==
> > String.Empty)
> > {
> > this._view.ErrorDisplay = "Please Enter the Name";
> > }
> > else
> > {
> > this._view.ErrorDisplay = "Success";
> > }
> > }
> > }
> >
> > My Unit Test Script
> > ------------------------------
> > [TestMethod]
> > public void Test_SaveClick_Exception()
> > {
> > //Set the Expectation
> > string expectedResult = "Please Enter the Name";
> >
> > // Mock the View
> > MockRepository mocks = new MockRepository();
> > ISampleView viewStub = mocks.CreateMock<ISampleView>();
> >
> > // When I go and check the Properties in the Viewstub variable (thru
> > add watch) ), I am getting the error "Getting error requires a return
> > value or an exception to throw"
> >
> > //Raise the save Event
> > viewStub.SaveClicked += null;
> > IEventRaiser raiser = LastCall.IgnoreArguments
> > ().GetEventRaiser();
> > mocks.ReplayAll();
> >
> > // Create Presenter With Mocked View and set the value
> > SamplePresenter presenter = new SamplePresenter(viewStub);
> >
> > //Raise the Event
> > raiser.Raise(viewStub, EventArgs.Empty);
> >
> > Assert.AreEqual(expectedResult, viewStub.ErrorDisplay,
> > "Test_SaveClick_Exception");
> >
> > }
> >
>
--
Rgds,
Raghu
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---