public static void InstanceContextMode_Single() { SingleInstanceContextSimpleService.ClearCounts(); var services = new ServiceCollection(); var serviceInstance = new SingleInstanceContextSimpleService(); services.AddSingleton(serviceInstance); string serviceAddress = "http://localhost/dummy"; var serviceDispatcher = TestHelper.BuildDispatcher <SingleInstanceContextSimpleService>(services, serviceAddress); IChannel mockChannel = new MockReplyChannel(services.BuildServiceProvider()); var dispatcher = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel); Assert.Equal(1, SingleInstanceContextSimpleService.AddBindingParametersCallCount); Assert.Equal(1, SingleInstanceContextSimpleService.ApplyDispatchBehaviorCount); Assert.Equal(1, SingleInstanceContextSimpleService.ValidateCallCount); var requestContext = TestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait(); requestContext = TestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait(); Assert.Equal(1, SingleInstanceContextSimpleService.CreationCount); Assert.Equal(0, SingleInstanceContextSimpleService.DisposalCount); Assert.Equal(2, serviceInstance.CallCount); }
public static void InstanceContextMode_Single() { SingleInstanceContextSimpleService.ClearCounts(); var serviceInstance = new SingleInstanceContextSimpleService(); System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <SingleInstanceContextSimpleService, ISimpleService>( (services) => { services.AddSingleton(serviceInstance); }); factory.Open(); ISimpleService channel = factory.CreateChannel(); ((System.ServiceModel.Channels.IChannel)channel).Open(); Assert.Equal(1, SingleInstanceContextSimpleService.AddBindingParametersCallCount); Assert.Equal(1, SingleInstanceContextSimpleService.ApplyDispatchBehaviorCount); Assert.Equal(1, SingleInstanceContextSimpleService.ValidateCallCount); string echo = channel.Echo("hello"); echo = channel.Echo("hello"); Assert.Equal(1, SingleInstanceContextSimpleService.CreationCount); Assert.Equal(0, SingleInstanceContextSimpleService.DisposalCount); Assert.Equal(2, serviceInstance.CallCount); ((System.ServiceModel.Channels.IChannel)channel).Close(); factory.Close(); TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory); }
public static void InstanceContextMode_Single_NoInjection() { SingleInstanceContextSimpleService.ClearCounts(); var factory = ExtensibilityHelper.CreateChannelFactory <SingleInstanceContextSimpleService, ISimpleService>(); factory.Open(); var channel = factory.CreateChannel(); ((System.ServiceModel.Channels.IChannel)channel).Open(); Assert.Equal(1, SingleInstanceContextSimpleService.AddBindingParametersCallCount); Assert.Equal(1, SingleInstanceContextSimpleService.ApplyDispatchBehaviorCount); Assert.Equal(1, SingleInstanceContextSimpleService.ValidateCallCount); var echo = channel.Echo("hello"); echo = channel.Echo("hello"); Assert.Equal(1, SingleInstanceContextSimpleService.CreationCount); Assert.Equal(0, SingleInstanceContextSimpleService.DisposalCount); ((System.ServiceModel.Channels.IChannel)channel).Close(); factory.Close(); TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory); }