Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you mock IContextChannel in a WCF ServiceAuthorizationManager?

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?

like image 343
Steve Avatar asked Apr 29 '13 18:04

Steve


1 Answers

You can't directly. See if WCFMock will help.

like image 176
Sunny Milenov Avatar answered Oct 16 '22 00:10

Sunny Milenov