I need to mock a method from the google calendar api. But it gives an error everytime. I have the following code.
DateTime dateTimeNow = new DateTime(2018, 10, 10, 10, 10, 10);
Event events = new Event
{
Id = "EventA",
Summary = "Summary",
Description = "Desc",
Start = new EventDateTime { Date = "2018-10-10", DateTime = dateTimeNow},
End = new EventDateTime { Date = "2018-10-10", DateTime = dateTimeNow.AddHours(1) },
};
Mock<CalendarService> fakeCalendarService = new Mock<CalendarService>();
fakeCalendarService
.Setup(x => x.Events.Insert(It.IsAny<Event>(), It.IsAny<string>()).Execute())
.Returns(events);
I get the following error message:
Message: System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: x => x.Events.Insert(It.IsAny<Event>(), It.IsAny<String>()).Execute()
I was able to mock other functions but this function:
_service.Events.Insert(newEvent, _calendarId).Execute();
has .Execute() behind it. Because of this statement I don't know how to mock it.