IExtension <OperationContext> testing module for use with WCF service

I am trying to develop extension ( IExtension<OperationContext>) for System.ServiceModel.ObjectContext using TDD. The extension should be used as a repository for the lifelong manager to be used with Windsor Castle.

The problem is the abstraction (bullying) of the OperationContext. Since this is a static object that is automatically created at runtime, I really don't know how to mock it (without TypeMock - which I don't have).

The context operation can be updated if I put in a channel object that implements IChannelFactory, however - this interface is terribly complex and I don’t know what I need to implement in the stub to make it work properly.

Service hosting and its call do not populate OperationContext ...

[TestFixtureSetUp]
    public void FixtureSetup()
    {
        _serviceHost = new TypeResolverServiceHost(typeof(AilDataService));
        _serviceHost.AddServiceEndpoint(typeof (IAilDataService), new BasicHttpBinding(), SvcUrl);
        _serviceHost.Open();

        var endpointAddress = new EndpointAddress(SvcUrl);

        _ailDataService = ChannelFactory<IAilDataService>.CreateChannel(new BasicHttpBinding(), endpointAddress);
    }

    [TestFixtureTearDown]
    public void FixtureCleanup()
    {
        _serviceHost.Close();
    }

    [Test]
    public void Can_Call_Service()
    {
        var reply = _ailDataService.GetMovexProductData("169010", new TaskSettings{MovexDatabase = "MVXCDTATST", MovexServer = "SEJULA03"});

        Assert.That(reply, Is.Not.Null);

        // This fails
        Assert.That(OperationContext.Current!=null);
    }

Any tips?

+3
source share
1 answer

Here is what I did:

    [TestFixture]
public class WcfPerSessionLifestyleManagerTests
{
    private const string SvcUrl = "http://localhost:8732/Design_Time_Addresses/JulaAil.DataService.WcfService/AilDataService/";

    private TypeResolverServiceHost _serviceHost;
    private ChannelFactory<IAilDataService> _factory;
    private IAilDataService _channel;
    private WindsorContainer _container;

    [Test]
    public void Can_Populate_OperationContext_Using_OperationContextScope()
    {
        using (new OperationContextScope((IContextChannel) _channel))
        {
            Assert.That(OperationContext.Current, Is.Not.Null);
        }
    }
}
0
source

Source: https://habr.com/ru/post/1745939/


All Articles