Non-virtual methods cannot be intercepted
I am new to FakeItEasy and will try to solve the problem.
I have a class
public class Events
{
public List<Events> SaveEvents()
{
// Call to repository and return 1(success) or -1(fail)
//If the repository return 1 then need to make another call to save the action in db
//Sample Code here
AuditLogService log = new AuditLogService();
log.CallLog();
}
}
Here's the test code:
[TestMethod]
public void EventValidation()
{
//Arrange
var Fakeevents = A.Fake<Events>();
var log = A.Fake<AuditLogService>();
var _EventsController = new EventsController(Fakeevents);
_EventsController.SaveEvents();
A.CallTo(
() => Fakeevents.SaveEvents().Retunr(1).AssignsOutAndRefParameters(status)
A.CallTo(
() => log.CallLog()).MustHaveHappened(Repeated.AtLeast.Once);
}
I am getting error like "Non virtual methods can not be intercepted"
I want to check if Calllog method is called after success or not.
Can anyone help me with this.
I have a method and inside the method I run another class and call the class method. I want to check from fakeItEasy if a method has been called.
+3
source to share
1 answer
Unfortunately, your headline says it all. Non-virtual members cannot be tricked, configured, or intercepted, as stated in the documentation under " Which members can be overridden? ".
There is nothing FakeItEasy can do for you unless you make it a virtual member (or promote it to an interface and spoof the interface or something).
+5
source to share