I’m trying to unit test my use of the Okta .NET SDK, in particular the group API.
I’m mocking the output of the ListGroups
, but new Group()
instantiates a group that has no Id
property. In real-life scenarios, all groups returned from that endpoint will have an Id
property set.
I’ve tried using Mock API:
var mockGroup = new Mock<Group>();
var groupId = Guid.NewGuid().ToString()[..12];
mockGroup.Setup(g => g.Id).Returns(groupId);
which buids, but fails at runtime:
System.NotSupportedException : Unsupported expression: g => g.Id
Non-overridable members (here: Group.get_Id) may not be used in setup / verification expressions.
This is because Group
is a class and not an interface.
Would you consider introducing an IGroup interface, and returning it from ListGroups
instead of Group
to allow mocking?
Thank you