コード例 #1
0
        public void Can_be_deconstructed()
        {
            var expectedDescription = new RecipientDescription(
                Guid.NewGuid(),
                "My name is",
                typeof(SomeType),
                Lifetime.Singleton,
                CollisionStrategy.UseAllMethodsMatching);

            var expectedResult   = 42;
            var expectedDuration = TimeSpan.FromSeconds(1);

            var invocation = new CompletedInvocation <int>(
                expectedDescription,
                expectedResult,
                expectedDuration);

            var((id, name, type, lifetime, strategy), result, duration) = invocation;

            Assert.Equal(expectedDescription.Id, id);
            Assert.Equal(expectedDescription.Name, name);
            Assert.Equal(expectedDescription.Type, type);
            Assert.Equal(expectedDescription.Lifetime, lifetime);
            Assert.Equal(expectedDescription.CollisionStrategy, strategy);
            Assert.Equal(expectedResult, result);
            Assert.Equal(expectedDuration, duration);
        }
コード例 #2
0
        public static AggregatedResponse <TResponse> CreateFrom <TResponse>(
            IEnumerable <RecipientRunner <TResponse> > invocations)
        {
            var completed  = new List <CompletedInvocation <TResponse> >();
            var faulted    = new List <FaultedInvocation>();
            var incomplete = new List <IncompleteInvocation>();

            foreach (var invocation in invocations)
            {
                var recipientDescription = RecipientDescriptionFactory.CreateFrom(invocation.Recipient);

                if (invocation.CompletedSuccessfully)
                {
                    var completedInvocation = new CompletedInvocation <TResponse>(
                        recipientDescription,
                        invocation.Result,
                        invocation.Duration);

                    completed.Add(completedInvocation);
                }
                else if (invocation.Faulted)
                {
                    var faultedInvocation = new FaultedInvocation(
                        recipientDescription,
                        invocation.Exception,
                        invocation.Duration);

                    faulted.Add(faultedInvocation);
                }
                else
                {
                    incomplete.Add(new IncompleteInvocation(recipientDescription));
                }
            }

            return(new AggregatedResponse <TResponse>(completed, faulted, incomplete));
        }