I have a repository (InboxRepository) with a dependency of type
ISMLSMSD.

I would like to test that the repository behaves correctly when the
dependency throws an exception in one of the methods.

The InboxRepository has these two overloaded methods:

public void InsertInboxMessage(IInboxItem inboxItem)
{
    // Simply call overloaded method
    InsertInboxMessage(new List<IInboxItem>() { inboxItem });
}

public void InsertInboxMessage(List<IInboxItem> inboxItems)
{
    try
    {
        _sMLSMSD.InsertIntoInbox(inboxItems);
    }
    catch (Exception exception)
    {

        throw new InboxRepositoryException("InsertInboxMessage
failed", exception);
    }
}

The dependency has this method:

public int InsertIntoInbox(List<IInboxItem> inboxMessages)

So I would like to test that my repo wraps an Exception from
dependency in its own specialized InboxRepositoryException.

So I wrote this test:

[Test]
public void CanWrapExceptionInInsertListInboxMessageTest()
{
    var stub = MockRepository.GenerateStub<ISMLSMSD>();
    var implementation = new InboxRepository(stub);

    stub.Stub(s => s.InsertIntoInbox(new List<IInboxItem>() { new
InboxMessage() })).Throw(new Exception("Error"));

    Assert.Throws<InboxRepositoryException>(() =>
implementation.InsertInboxMessage(new List<IInboxItem>() { new
InboxMessage() }));
}

I would assume that the dependency would throw an Exception(“Error”)
and that the exception thrown from repo was the wrapped one.

However – that is not what happens. My test fails with this message:

  Expected: <InboxRepositoryException>
  But was:  null

It seems to me that the Exception is never thrown in the generated
dependency proxy.

Can you help me here to what I’m missing?

Thanks,

:o)

Med venlig hilsen / Best regards

Jesper Lund Stocholm

-- 
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.

Reply via email to