In My Project i have a method PreAction() which is used in all the Methods. PreAction() contains the Operation context object i.e
OperationContext currentContext = OperationContext.Current
So when am trying to Invoke a Method X in that method I am using the PreAction() Method. So as the operation context is of service model, I am getting an exception indicating that Object reference not set to an instance of an object.
So how to overcome this scenario ? Is there a way to use the Mcoking and can we resolve this scenario?
Thanks!!!
It seems you need an integration test rather then a unit test. In this case you should create a proxy of your service and validate the returned result and perhaps the persisted result.
But apart from that you best create a series of unit tests on your logic layer. All these classes should be build in a way that they don't depends on the PreActions of your serive.
Make sure you can stub or mock all your depending properties and interfaces.