-1

I have following Unit Test:

    [Test]
    public void ReportGeneratorCancelTwiceTest()
    {
        var logger = this.mockRepository.StrictMock<ILog>();
        this.manager = new ReportGeneratorManager(logger, new Guid(), 5, null);
        using (this.mockRepository.Record())
        {
            Expect.Call(() => this.log.LogWarning(null, null, null, null)).IgnoreArguments().Repeat.AtLeastOnce();
        }

        using (this.mockRepository.Playback())
        {
            var action = new Action(() => this.OnStart());
            action.BeginInvoke(null, null);
            Thread.Sleep(5000);
            this.OnStop();
            Thread.Sleep(5000);
            this.OnStop();
        }
    }

    private void OnStart()
    {
        this.manager.StartManager();
    }

    private void OnStop()
    {
        this.manager.StopManager();
    }
}

I'm expecting a LogWarning, which will be called in StopManager() method

  public void StopManager()
    {
        if (this.RunningTask > 0)
        {
            this.logger.LogEvent(this.Id.ToString(), string.Format(CultureInfo.InvariantCulture, "System"), string.Format(CultureInfo.InvariantCulture, "Cancelling tasks"));
            this.CancellationTokenSource.Cancel();
        }
        else
        {
            this.logger.LogWarning(this.Id.ToString(), string.Format(CultureInfo.InvariantCulture, "System"), string.Format(CultureInfo.InvariantCulture, "Tasks are already in cancelled state"));
        }            
    }

So considering the Playback() block in mockRepository, the first call on OnStop() should cancel the tasks, and then it is clear that the second call to OnStop() Logs the LogWarning, which I expected, but I'm receiving following Rhino Mocks exception:

 Rhino.Mocks.Exceptions.ExpectationViolationException : ILog.LogWarning("00000000-0000-0000-0000-000000000000", "System", "Tasks are already in cancelled state"); Expected #0, Actual #1.

The expection is thrown at the LogWarning in StopManager() during the FIRST call to the method, which does not make any sense to me.

What is the issue here ?

Osman Esen
  • 1,704
  • 2
  • 21
  • 46

1 Answers1

1

You've told Rhino to expect a call to LogWarning with four arguments, but you only call it with three. It probably thinks you're calling a different overload.

Colin Grealy
  • 615
  • 4
  • 12
  • I am calling it with four arguments ? – Osman Esen Oct 27 '15 at 23:11
  • No, you're not. `this.logger.LogWarning(this.Id.ToString(), string.Format(CultureInfo.InvariantCulture, "System"), string.Format(CultureInfo.InvariantCulture, "Tasks are already in cancelled state"));` That's only 3. – Colin Grealy Oct 28 '15 at 00:39