public void TestDispatch_MethodExists_Success()
        {
            var svcFile = ".\\Services.svc";

            File.WriteAllText(
                svcFile,
                String.Format(CultureInfo.InvariantCulture, "<% @ ServiceHost Service=\"{0}\" %>", typeof(TestService).FullName)
                );
            try
            {
                var configuration = new RpcServerConfiguration();
                configuration.ServiceTypeLocatorProvider = conf => new FileBasedServiceTypeLocator();

                using (var server = new RpcServer(configuration))
                    using (var transportManager = new NullServerTransportManager(server))
                        using (var transport = new NullServerTransport(transportManager))
                            using (var requestContext = DispatchTestHelper.CreateRequestContext())
                                using (var argumentsBuffer = new MemoryStream())
                                    using (var waitHandle = new ManualResetEventSlim())
                                    {
                                        var message = Guid.NewGuid().ToString();
                                        using (var argumentsPacker = Packer.Create(argumentsBuffer, false))
                                        {
                                            argumentsPacker.PackArrayHeader(1);
                                            argumentsPacker.Pack(message);
                                        }

                                        argumentsBuffer.Position = 0;

                                        var target = new LocatorBasedDispatcher(server);
                                        MessagePackObject response = MessagePackObject.Nil;
                                        requestContext.MethodName = "Echo:TestService:1";
                                        requestContext.MessageId  = 1;
                                        requestContext.SetTransport(transport);
                                        requestContext.ArgumentsUnpacker = Unpacker.Create(argumentsBuffer);
                                        transport.Sent +=
                                            (sender, e) =>
                                        {
                                            response = Unpacking.UnpackString(e.Context.GetReturnValueData()).Value;
                                            waitHandle.Set();
                                        };
                                        target.Dispatch(transport, requestContext);

                                        Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));

                                        Assert.That(message == response, "{0} != {1}", message, response);
                                    }
            }
            finally
            {
                File.Delete(svcFile);
            }
        }
		public void TestDispatch_MethodExists_Success()
		{
			var svcFile = ".\\Services.svc";
			File.WriteAllText(
				svcFile,
				String.Format( CultureInfo.InvariantCulture, "<% @ ServiceHost Service=\"{0}\" %>", typeof( TestService ).FullName )
			);
			try
			{
				var configuration = new RpcServerConfiguration();
				configuration.ServiceTypeLocatorProvider = conf => new FileBasedServiceTypeLocator();

				using ( var server = new RpcServer( configuration ) )
				using ( var transportManager = new NullServerTransportManager( server ) )
				using ( var transport = new NullServerTransport( transportManager ) )
				using ( var requestContext = DispatchTestHelper.CreateRequestContext() )
				using ( var argumentsBuffer = new MemoryStream() )
				using ( var waitHandle = new ManualResetEventSlim() )
				{
					var message = Guid.NewGuid().ToString();
					using ( var argumentsPacker = Packer.Create( argumentsBuffer, false ) )
					{
						argumentsPacker.PackArrayHeader( 1 );
						argumentsPacker.Pack( message );
					}

					argumentsBuffer.Position = 0;

					var target = new LocatorBasedDispatcher( server );
					MessagePackObject response = MessagePackObject.Nil;
					requestContext.MethodName = "Echo:TestService:1";
					requestContext.MessageId = 1;
					requestContext.SetTransport( transport );
					requestContext.ArgumentsUnpacker = Unpacker.Create( argumentsBuffer );
					transport.Sent +=
						( sender, e ) =>
						{
							response = Unpacking.UnpackString( e.Context.GetReturnValueData() ).Value;
							waitHandle.Set();
						};
					target.Dispatch( transport, requestContext );

					Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );

					Assert.That( message == response, "{0} != {1}", message, response );
				}
			}
			finally
			{
				File.Delete( svcFile );
			}
		}
        public void TestDispatch_MethodNotExists_NoMethodError()
        {
            using (var server = new RpcServer())
                using (var transportManager = new NullServerTransportManager(server))
                    using (var transport = new NullServerTransport(transportManager))
                        using (var requestContext = DispatchTestHelper.CreateRequestContext())
                            using (var argumentsBuffer = new MemoryStream())
                                using (var waitHandle = new ManualResetEventSlim())
                                {
                                    var message = Guid.NewGuid().ToString();
                                    using (var argumentsPacker = Packer.Create(argumentsBuffer, false))
                                    {
                                        argumentsPacker.PackArrayHeader(1);
                                        argumentsPacker.Pack(message);
                                    }

                                    argumentsBuffer.Position = 0;

                                    var target = new LocatorBasedDispatcher(server);
                                    MessagePackObject response = MessagePackObject.Nil;
                                    requestContext.MethodName = "Echo:TestServices:1";
                                    requestContext.MessageId  = 1;
                                    requestContext.SetTransport(transport);
                                    requestContext.ArgumentsUnpacker = Unpacker.Create(argumentsBuffer);
                                    transport.Sent +=
                                        (sender, e) =>
                                    {
                                        response = Unpacking.UnpackString(e.Context.GetErrorData()).Value;
                                        waitHandle.Set();
                                    };
                                    target.Dispatch(transport, requestContext);

                                    Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));

                                    Assert.That(RpcError.NoMethodError.Identifier == response, "{0} != {1}", message, response);
                                }
        }
		public void TestDispatch_MethodNotExists_NoMethodError()
		{
			using ( var server = new RpcServer() )
			using ( var transportManager = new NullServerTransportManager( server ) )
			using ( var transport = new NullServerTransport( transportManager ) )
			using ( var requestContext = DispatchTestHelper.CreateRequestContext() )
			using ( var argumentsBuffer = new MemoryStream() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				var message = Guid.NewGuid().ToString();
				using ( var argumentsPacker = Packer.Create( argumentsBuffer, false ) )
				{
					argumentsPacker.PackArrayHeader( 1 );
					argumentsPacker.Pack( message );
				}

				argumentsBuffer.Position = 0;

				var target = new LocatorBasedDispatcher( server );
				MessagePackObject response = MessagePackObject.Nil;
				requestContext.MethodName = "Echo:TestServices:1";
				requestContext.MessageId = 1;
				requestContext.SetTransport( transport );
				requestContext.ArgumentsUnpacker = Unpacker.Create( argumentsBuffer );
				transport.Sent +=
					( sender, e ) =>
					{
						response = Unpacking.UnpackString( e.Context.GetErrorData() ).Value;
						waitHandle.Set();
					};
				target.Dispatch( transport, requestContext );

				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );

				Assert.That( RpcError.NoMethodError.Identifier == response, "{0} != {1}", message, response );
			}
		}