/// <summary>
        ///		Creates <see cref="ServerResponseContext"/> which contains specified required states.
        /// </summary>
        /// <param name="transport">The transport to be bound to the context.</param>
        /// <returns><see cref="ServerResponseContext"/> for the unit testing argument.</returns>
        public static ServerResponseContext CreateResponseContext(IContextBoundableTransport transport)
        {
            var result = new ServerResponseContext();

            result.SetTransport(transport);
            return(result);
        }
Esempio n. 2
0
        private void TestGetServiceInvokerCore <TArg1, TArg2, TResult>(
            EventHandler <ServiceInvokedEventArgs <TResult> > invoked,
            RpcServerConfiguration configuration,
            TArg1 arg1,
            TArg2 arg2,
            Action <ServerResponseContext> assertion
            )
        {
            using (var target = new ServiceInvokerGenerator(true))
                using (var server = new RpcServer())
                    using (var transportManager = new NullServerTransportManager(server))
                        using (var transport = new NullServerTransport(transportManager))
                        {
                            var service = new Service <TArg1, TArg2, TResult>();
                            service.Invoked += invoked;

                            var serviceDescription = new ServiceDescription("Service", () => service);
                            var targetOperation    = service.GetType().GetMethod("Invoke");

                            using (var requestContext = new ServerRequestContext())
                            {
                                requestContext.ArgumentsBufferPacker = Packer.Create(requestContext.ArgumentsBuffer, false);
                                requestContext.ArgumentsBufferPacker.PackArrayHeader(2);
                                requestContext.ArgumentsBufferPacker.Pack(arg1);
                                requestContext.ArgumentsBufferPacker.Pack(arg2);
                                requestContext.ArgumentsBuffer.Position = 0;
                                requestContext.MessageId         = 123;
                                requestContext.ArgumentsUnpacker = Unpacker.Create(requestContext.ArgumentsBuffer, false);

                                var responseContext = new ServerResponseContext();
                                responseContext.SetTransport(transport);
                                try
                                {
                                    var result = target.GetServiceInvoker(RpcServerRuntime.Create(configuration, this._serializationContext), serviceDescription, targetOperation);

                                    result.InvokeAsync(requestContext, responseContext).Wait(TimeSpan.FromSeconds(1));

                                    assertion(responseContext);
                                }
                                finally
                                {
                                    if (this._isDumpEnabled)
                                    {
                                        try
                                        {
                                            target.Dump();
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.Error.WriteLine("Failed to dump: {0}", ex);
                                        }
                                    }
                                }
                            }
                        }
        }
		private static void TestCore( Action<ServerResponseContext, ServerTransport> test )
		{
			using ( var server = new RpcServer() )
			using ( var manager = new NullServerTransportManager( server ) )
			using ( var transport = new NullServerTransport( manager ) )
			using ( var target = new ServerResponseContext() )
			{
				target.SetTransport( transport );
				test( target, transport );
			}
		}
Esempio n. 4
0
		/// <summary>
		///		Creates <see cref="ServerResponseContext"/> which contains specified required states.
		/// </summary>
		/// <param name="transport">The transport to be bound to the context.</param>
		/// <returns><see cref="ServerResponseContext"/> for the unit testing argument.</returns>
		public static ServerResponseContext CreateResponseContext( IContextBoundableTransport transport )
		{
			var result = new ServerResponseContext();
			result.SetTransport( transport );
			return result;
		}