Instead of saving, OperationContextwrap it with an abstraction that you can replace by making sure that the objects represented by the context you need are in the abstraction - something like this
interface IContextService
{
Message RequestMessage{ get;}
string SessionId{ get;}
}
Then execute an implementation that uses a real OperationContext
class ContextService : IContextService
{
public Message RequestMessage
{
get
{
return OperationContext.Current.RequestContext.RequestMessage;
}
}
public string SessionId
{
get
{
return OperationContext.Current.SessionId;
}
}
}
If you type IContextServicein your class, you can now test by providing a fake version
source
share