Hi!

I have the following codes. My expectation was, that this is working,
but it doesn't. Can anybody explain me why this constallation does not
work? I get always the Exception

Rhino.Mocks.Exceptions.ExpectationViolationException:
ICommunicator.add_IsConnected(System.EventHandler); Expected #1,
Actual #0.

But I have not defined an expectation for the event call.

How I would have to adjust the test so that it works?


My codes:


public interface ICommunicator
{
    event EventHandler IsConnected;
    bool Connect(string server);
    bool Disconnect();
    void SendMessage(string message);
}

public class Controller : IController
{
    private readonly ICommunicator communicator;
    private readonly IConfigurationSerialization
configurationSerialization;

    public Controller(ICommunicator communicator,
IConfigurationSerialization configurationSerialization)
    {
        this.communicator = communicator;
        this.configurationSerialization = configurationSerialization;

        communicator.IsConnected += Communicator_SendMessageSucceed;
    }

    internal void Communicator_SendMessageSucceed(object sender,
EventArgs e)
    {
        //do something
    }

    public void LoadConfiguration()
    {
        ExceptionCatcher(() => TryLoadConfiguration());
    }

    public virtual bool TryLoadConfiguration()
    {
        //do something
        return true;
    }

    public virtual T ExceptionCatcher<T>(Func<T> func)
    {
        try
        {
            return func();
        }
        catch (NotSupportedException ex)
        {
            //do special things
        }
        catch (Exception ex)
        {
            throw new Exception("unexpected error", ex);
        }

        return default(T);
    }
}

[Test]
public void
The_Method_LoadConfiguration_Calls_All_Essential_Methods_R_R_With_Interface_Dependency_Mocks()
{
    var mockRepository = new MockRepository();
    var controllerPartialMock =
mockRepository.PartialMock<Controller>(mockRepository.DynamicMock<ICommunicator>(),
 
mockRepository.DynamicMock<IConfigurationSerialization>());

    using (mockRepository.Record())
    {
        Expect.Call(controllerPartialMock.ExceptionCatcher(() =>
true)).CallOriginalMethod(OriginalCallOptions.CreateExpectation).IgnoreArguments().Return(true);
 
Expect.Call(controllerPartialMock.TryLoadConfiguration()).Return(true);
    }

    using (mockRepository.Playback())
    {
        controllerPartialMock.LoadConfiguration();
    }
}

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