}
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
I do not know the reasons why. Maybe someone with more knowledge of
the Rhino MOcks engine could explain.
I found that when I used:
x.Expect(x => x.SomeProperty).Return(myProperty);
Reference to x.SomeProperty would only return myProperty within the
same unit. The moment I tried to push this stub into a class
constructor for another class, it returned NULL to that class.
I struggled with this, until I found x.Stub().
I replaced the line above for:
x.Stub(x => x.SomeProperty).Return(myProperty);
Please be aware that x.SomeProperty is a readonly property which is
why I needed to declare it this way.
If anyone could shed light on why this is necessary I would be
interested.
Thanks.
On Dec 7, 7:32 pm, Fabien Arcellier <fabien.arcell...@gmail.com>
Tim
Sent from my iPhone
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
However, if I am trying to debug it and need to hover over properties
to find out what they hold, the thing goes pear shaped. Because when
I hover over the property, I have made that 'once only' call.
If I use, x.Stub though, it works as many times as I like!
Here is an example of what I was doing.
[TestFixture]
public class TestStubAgainstExpect
{
[Test]
public void TestStub()
{
var bin = MockRepository.GenerateStub<IBin>();
bin.Expect(x => x.IsFull).Return(false);
var dustBin = MockRepository.GenerateStub<IDustbin>();
dustBin.Expect(x => x.IsFull).Return(false);
var myHouse = MockRepository.GenerateStub<IHouse>();
//can not debug/hover over
myHouse.Expect(x => x.Bin).Return(bin);
myHouse.Expect(x => x.Dustbin).Return(dustBin);
//can debug/hover over
// myHouse.Stub(x => x.Bin).Return(bin);
// myHouse.Stub(x => x.Dustbin).Return(dustBin);
var cleaner = new Cleaner();
cleaner.EmptyTheBins(myHouse);
}
}
public class Cleaner
{
internal Cleaner()
{
}
public void EmptyTheBins(IHouse house)
{
if (house.Bin.IsFull)
{
//empty the bins
}
}
}
public interface IBin
{
bool IsFull { get;}
}
public interface IHouse
{
IBin Bin { get; }
IDustbin Dustbin { get; }
}
public interface IDustbin
{
bool IsFull { get; }
}
On Dec 22, 11:35 am, Tim Barcz <timba...@gmail.com> wrote:
> I'd prefer something that compiles
>
> Sent from my iPhone
>
> On Dec 21, 2009, at 11:36 PM, John Bierman <zkbier...@gmail.com> wrote:
>
>
>
> > Does the one that I sent you originally suffice?
>
> > On Mon, Dec 21, 2009 at 7:45 PM, Tim Barcz <timba...@gmail.com> wrote:
> > I would love to... However can you provide a test for me to comment
> > on.
>
> > Tim
>
> > Sent from my iPhone
>
> > > For more options, visit this group athttp://groups.google.com/group/rhinomocks?hl=en
> > > .
>
> > --
>
> > You received this message because you are subscribed to the Google
> > Groups "Rhino.Mocks" group.
> > To post to this group, send email to rhino...@googlegroups.com.
> > To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com
> > .
> > For more options, visit this group athttp://groups.google.com/group/rhinomocks?hl=en
> > .
>
> > --
>
I could not fail to notice that you are not Asserting that your
expectations have been met!
i.e. :
[Test]
public void TestStub()
{
// Arrange
var bin = MockRepository.GenerateStub<IBin>();
// I would Stub this call instead of using Expect
bin.Stub(x => x.IsFull).Return(false);
var dustBin = MockRepository.GenerateStub<IDustbin>();
// I would Stub this call instead of using Expect
dustBin.Stub(x => x.IsFull).Return(false);
var myHouse = MockRepository.GenerateStub<IHouse>();
myHouse.Expect(x => x.Bin).Return(bin);
myHouse.Expect(x => x.Dustbin).Return(dustBin);
// Act
var cleaner = new Cleaner();
cleaner.EmptyTheBins(myHouse);
// Assert
// This line is missing
myHouse.VerifyAllExpectations();
}
But then again, I'm not entirely sure what is actually being
tested ....
My rule of thumb is as follows: If the object is not being tested, use
a Stub. If the object is being tested set an Expectation
So, in the example above, I have assumed that it is your IHouse
implementation that is being tested, and not the IBin or IDustbin
implementations.
Stub = when a particular member is invoked, I want x to happen
(every time).
Expect = when a particular member is invoked, I am expecting x to
occur.
Expectations can occur multiple times simply by using .Times(n), i.e.
myHouse.Expect(x => x.Bin).Return(bin).Times(2);
however, your test will fail with the call to
myHouse.VerifyAllExpectations(), since the call is only ever made once
(unless you are stepping through in debug mode and inspecting your
objects).
> > > .- Hide quoted text -
My example was pretty rushed and didn't explain what happened in
production. You are right, the example didn't seem to test anything.
But it did prove that x.Stub could be called many times and x.Expect
could only be called once.
If you change my example and make:
var bin = new Bin();
And bin is a property of house:
var house = new House();
house.Stub(x => x.Bin).Return(bin);
By using x.Stub instead of x.Expect, I can push house through a
business object that I am trying to test. That business object may
make modifications to bin and therefore call bin - as a property of
house - many times. Allowing me to test that bin comes out of the
business object with the data I expect.
I normally push a mocked/fake/stubbed data access layer into the
business object, so that I am testing the workflow through a business
layer. I don't believe this to be a 'unit' test, but it is still a
test I can run, using unit test methods.
On Dec 22, 4:55 pm, bill richards <bill.richa...@greyskin.co.uk>
wrote:
I've never tried that, but it seems more granular and specific than my
'push my object through and hope the data is right when it comes out
the other end' way.
Thanks for that!
On Dec 22, 4:55 pm, bill richards <bill.richa...@greyskin.co.uk>
wrote:
> ...
>
> read more »