Something wrong in mock.Raise() on this kind of stub. It seems this
stub behavior is not available inside the event handler?
My test like this:
[Test]
public void should_insert_a_new_item_before_the_current_row
()
{
// Arrange , _mockView = MockRepository.GenerateStub()
_mockView.IndexOfCurrentRow = 1;
// Action
_presenter.InitView();
// This still works
Assert.That(_mockView.IndexOfCurrentRow, Is.EqualTo
(1));
_mockView.Raise(x => x.InsertItem += null, this,
EventArgs.Empty);
// Assert
Assert.That(_mockView.List.Count, Is.EqualTo
(_stubList.Count + 1));
// This will fail, the property stub doesn't work in
view.Raise()??
Assert.That(_mockView.IndexOfCurrentRow, Is.EqualTo
(1));
}
I have an event in presenter do the insertItem,
protected virtual void InsertItem(object sender, EventArgs e)
{
var list = _view.List;
int rowIndex = _view.IndexOfCurrentRow; // This will
always be zero, no matter what I set in test. Unless I change
_mockview from GenerateStub to GeneratMock(), but then I can't stub
view.List property anymore.
var newBO = ...;
list.Insert(rowIndex, newBO);
_view.List = list;
_view.IndexOfCurrentRow = rowIndex;
> var mock = MockRepository.CreateStub<IFoo>();
>
> mock.Value = 5;
>
> Assert.Equal(5, mock.Value);
>
> mock.Value = 6;
>
> Assert.Equal(6, mock.Value);
>