I am trying to execute a unit test this ServizioController class:
public class ServizioController : IServizioController
{
public virtual void PerformAction(Super.Core.Servizio servizio)
{
}
public virtual bool Start()
{ throw new NotImplementedException(); }
public virtual bool Stop()
{ throw new NotImplementedException(); }
public virtual bool Continue()
{ throw new NotImplementedException(); }
}
This is normal if this class is part of a test or library project. But when it is in Project Service, Moq throws me this error:
Invalid setup on a non-overridable member: x => x.Start()
My test is as follows:
[TestMethod]
public void ServizioController_PerformAction_Start()
{
bool _start, _stop, _continue;
_start = _stop = _continue = false;
Super.Core.Servizio s = new Super.Core.Servizio()
{
Action = ServizioAction.START.ToString()
};
var mock = new Mock<ServizioController>() { CallBase = true };;
mock.Setup(x => x.Start())
.Callback(() => _start = true);
mock.Setup(x => x.Stop())
.Callback(() => _stop = true);
mock.Setup(x => x.Continue())
.Callback(() => _continue = true);
mock.Object.PerformAction(s);
Assert.IsTrue(_start);
Assert.IsFalse(_stop);
Assert.IsFalse(_continue);
}
I am ready to continue, so this class is going to join the library class, but if someone could explain this behavior to me, I would be more than happy ...
thank,
source
share