My Moq code:
===================
var mock = new Mock();
// start “tracking” sets/gets to this property
mock.Stub(v => v.Value);
// provide a default value for the stub’ed property
mock.Stub(v => v.Value, 5);
Now I can do:
IHaveValue v = mock.Object;
// Initial value was stored
Assert.Equal(5, v.Value);
// New value set which changes the initial value
v.Value = 6;
Assert.Equal(6, v.Value);
=====================
How can I do the similar stub using Rhino? Thanks.
On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> My Moq code:
> ===================
> var mock = new Mock();
> // start "tracking" sets/gets to this property
> mock.Stub(v => v.Value);
> // provide a default value for the stub'ed property
> mock.Stub(v => v.Value, 5);
> Now I can do:
> IHaveValue v = mock.Object;
> // Initial value was stored
> Assert.Equal(5, v.Value);
> // New value set which changes the initial value
> v.Value = 6;
> Assert.Equal(6, v.Value);
> =====================
> How can I do the similar stub using Rhino? Thanks.
> On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> > My Moq code:
> > ===================
> > var mock = new Mock();
> > // start "tracking" sets/gets to this property
> > mock.Stub(v => v.Value);
> > // provide a default value for the stub'ed property
> > mock.Stub(v => v.Value, 5);
> > Now I can do:
> > IHaveValue v = mock.Object;
> > // Initial value was stored
> > Assert.Equal(5, v.Value);
> > // New value set which changes the initial value
> > v.Value = 6;
> > Assert.Equal(6, v.Value);
> > =====================
> > How can I do the similar stub using Rhino? Thanks.
> On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> > My Moq code:
> > ===================
> > var mock = new Mock();
> > // start "tracking" sets/gets to this property
> > mock.Stub(v => v.Value);
> > // provide a default value for the stub'ed property
> > mock.Stub(v => v.Value, 5);
> > Now I can do:
> > IHaveValue v = mock.Object;
> > // Initial value was stored
> > Assert.Equal(5, v.Value);
> > // New value set which changes the initial value
> > v.Value = 6;
> > Assert.Equal(6, v.Value);
> > =====================
> > How can I do the similar stub using Rhino? Thanks.
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));
// 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;
}
On Dec 22, 5:44 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> > My Moq code:
> > ===================
> > var mock = new Mock();
> > // start "tracking" sets/gets to this property
> > mock.Stub(v => v.Value);
> > // provide a default value for the stub'ed property
> > mock.Stub(v => v.Value, 5);
> > Now I can do:
> > IHaveValue v = mock.Object;
> > // Initial value was stored
> > Assert.Equal(5, v.Value);
> > // New value set which changes the initial value
> > v.Value = 6;
> > Assert.Equal(6, v.Value);
> > =====================
> > How can I do the similar stub using Rhino? Thanks.
If you are able to create an isolated test with the issue (meaning it
doesn't contain anything connected with your application) it will be much
easier for others to see what's wrong.
> // 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;
> }
> On Dec 22, 5:44 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> > var mock = MockRepository.CreateStub<IFoo>();
> > mock.Value = 5;
> > Assert.Equal(5, mock.Value);
> > mock.Value = 6;
> > Assert.Equal(6, mock.Value);
> > On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> > > My Moq code:
> > > ===================
> > > var mock = new Mock();
> > > // start "tracking" sets/gets to this property
> > > mock.Stub(v => v.Value);
> > > // provide a default value for the stub'ed property
> > > mock.Stub(v => v.Value, 5);
> > > Now I can do:
> > > IHaveValue v = mock.Object;
> > > // Initial value was stored
> > > Assert.Equal(5, v.Value);
> > > // New value set which changes the initial value
> > > v.Value = 6;
> > > Assert.Equal(6, v.Value);
> > > =====================
> > > How can I do the similar stub using Rhino? Thanks.
-- Software modules coupling is the path to the dark side.
Coupling leads to complexity.
Complexity leads to confusion.
Confusion leads to suffering.
Once you start down the dark path, forever will it dominate your destiny,
consume you it will!
<cvetomir.todorov....@gmail.com> wrote:
> If you are able to create an isolated test with the issue (meaning it
> doesn't contain anything connected with your application) it will be much
> easier for others to see what's wrong.
> On Tue, Dec 23, 2008 at 9:57 PM, FrankM <maodd...@gmail.com> wrote:
> > 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));
> > // 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;
> > }
> > On Dec 22, 5:44 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> > > var mock = MockRepository.CreateStub<IFoo>();
> > > mock.Value = 5;
> > > Assert.Equal(5, mock.Value);
> > > mock.Value = 6;
> > > Assert.Equal(6, mock.Value);
> > > On Tue, Dec 23, 2008 at 1:27 AM, FrankM <maodd...@gmail.com> wrote:
> > > > My Moq code:
> > > > ===================
> > > > var mock = new Mock();
> > > > // start "tracking" sets/gets to this property
> > > > mock.Stub(v => v.Value);
> > > > // provide a default value for the stub'ed property
> > > > mock.Stub(v => v.Value, 5);
> > > > Now I can do:
> > > > IHaveValue v = mock.Object;
> > > > // Initial value was stored
> > > > Assert.Equal(5, v.Value);
> > > > // New value set which changes the initial value
> > > > v.Value = 6;
> > > > Assert.Equal(6, v.Value);
> > > > =====================
> > > > How can I do the similar stub using Rhino? Thanks.
> --
> Software modules coupling is the path to the dark side.
> Coupling leads to complexity.
> Complexity leads to confusion.
> Confusion leads to suffering.
> Once you start down the dark path, forever will it dominate your destiny,
> consume you it will!