コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteCommandHub"/> class.
 /// </summary>
 /// <param name="endpointInformationStorage">The object that provides notification of the signing in and signing out of endpoints.</param>
 /// <param name="builder">The object that is responsible for building the command proxies.</param>
 /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="endpointInformationStorage"/> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="builder"/> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />.
 /// </exception>
 internal RemoteCommandHub(
     IStoreInformationAboutEndpoints endpointInformationStorage,
     CommandProxyBuilder builder,
     SystemDiagnostics systemDiagnostics)
     : base(
         endpointInformationStorage,
         (endpoint, type) => (CommandSetProxy)builder.ProxyConnectingTo(endpoint, type),
         systemDiagnostics)
 {
     {
         Lokad.Enforce.Argument(() => builder);
     }
 }
コード例 #2
0
        public void ProxyConnectingToMethodWithRetryCount()
        {
            var remoteEndpoint = new EndpointId("other");

            var local      = new EndpointId("local");
            var retryCount = -1;
            var timeout    = TimeSpan.MinValue;
            CommandInvokedMessage         intermediateMsg = null;
            SendMessageAndWaitForResponse sender          = (e, m, r, t) =>
            {
                retryCount = r;
                timeout    = t;

                intermediateMsg = m as CommandInvokedMessage;
                return(Task <ICommunicationMessage> .Factory.StartNew(
                           () => new SuccessMessage(remoteEndpoint, new MessageId()),
                           new CancellationToken(),
                           TaskCreationOptions.None,
                           new CurrentThreadTaskScheduler()));
            };

            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var builder = new CommandProxyBuilder(local, sender, configuration.Object, systemDiagnostics);
            var proxy   = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockCommandSetWithTaskReturn>(remoteEndpoint);

            var result = proxy.MyRetryMethod(10);

            result.Wait();

            Assert.IsTrue(result.IsCompleted);
            Assert.IsFalse(result.IsCanceled);
            Assert.IsFalse(result.IsFaulted);

            Assert.AreEqual(
                CommandId.Create(typeof(InteractionExtensionsTest.IMockCommandSetWithTaskReturn).GetMethod("MyRetryMethod")),
                intermediateMsg.Invocation.Command);
            Assert.AreEqual(0, intermediateMsg.Invocation.Parameters.Length);
            Assert.AreEqual(10, retryCount);
            Assert.AreEqual(TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds), timeout);
        }
コード例 #3
0
        public void ProxyConnectingToMethodWithTypedTaskReturnWithFailedExecution()
        {
            var remoteEndpoint = new EndpointId("other");

            var local = new EndpointId("local");
            CommandInvokedMessage         intermediateMsg = null;
            SendMessageAndWaitForResponse sender          = (e, m, r, t) =>
            {
                intermediateMsg = m as CommandInvokedMessage;
                return(Task <ICommunicationMessage> .Factory.StartNew(
                           () => new FailureMessage(remoteEndpoint, new MessageId()),
                           new CancellationToken(),
                           TaskCreationOptions.None,
                           new CurrentThreadTaskScheduler()));
            };

            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var builder = new CommandProxyBuilder(local, sender, configuration.Object, systemDiagnostics);
            var proxy   = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockCommandSetWithTypedTaskReturn>(remoteEndpoint);

            var result = proxy.MyMethod(10);

            Assert.Throws <AggregateException>(result.Wait);

            Assert.IsTrue(result.IsCompleted);
            Assert.IsFalse(result.IsCanceled);
            Assert.IsTrue(result.IsFaulted);
            Assert.IsAssignableFrom(typeof(CommandInvocationFailedException), result.Exception.InnerExceptions[0]);

            Assert.AreEqual(
                CommandId.Create(typeof(InteractionExtensionsTest.IMockCommandSetWithTypedTaskReturn).GetMethod("MyMethod")),
                intermediateMsg.Invocation.Command);
            Assert.AreEqual(1, intermediateMsg.Invocation.Parameters.Length);
            Assert.AreEqual(typeof(int), intermediateMsg.Invocation.Parameters[0].Parameter.Type);
            Assert.AreEqual("input", intermediateMsg.Invocation.Parameters[0].Parameter.Name);
            Assert.AreEqual(10, intermediateMsg.Invocation.Parameters[0].Value);
        }