I am trying to write unit tests for a custom ServiceAuthorizationManager. The call to CheckAccessCore takes an OperationContext as a parameter. To instantiate an OperationContext, one must pass an IContextChannel to the constructor. Using MOQ, I've declared an IContextChannel:
private OperationContext _context;
private Mock<IContextChannel> _contextChannelMock;
Then I attempt to create the OperationContext:
_context = new OperationContext(_contextChannelMock.Object);
But this line throws an exception:
Result Message: Initialization method Urs.EnterpriseServices.Providers.Tests.UrsServiceAuthorizationManager_Tests.SetUp threw exception. System.InvalidOperationException: System.InvalidOperationException: Invalid IContextChannel passed to OperationContext. Must be either a server dispatching channel or a client proxy channel..
How do I mock, a server dispatching channel?
You can't directly. See if WCFMock will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With