Exemplo n.º 1
0
        public void Error_if_returning_task_without_result()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeAsyncComputingType(), name: null, Lifetime.Transient, IgnoreRecipient);

            Assert.Throws <InvalidOperationException>(() => recipient.ReplyWith <Task>(42));
        }
Exemplo n.º 2
0
        public void Error_if_void_returning()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeComputingType(), name: null, Lifetime.Transient, IgnoreRecipient);

            Assert.Throws <InvalidOperationException>(() => recipient.Accept(42));
        }
Exemplo n.º 3
0
        public void Error_if_response_type_not_supported()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            Assert.Throws <InvalidOperationException>(() => recipient.ReplyWith <Guid>(42));
        }
Exemplo n.º 4
0
        public void Recipient_type_is_visible()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            Assert.Same(typeof(SomeType), recipient.Type);
        }
Exemplo n.º 5
0
 public void Recipient_can_be_created_from_type()
 {
     _ = TypeRecipient.Create(
         registry: new TypeInspectorRegistry(),
         () => new SomeType(),
         name: null,
         lifetime: Lifetime.Transient,
         IgnoreRecipient);
 }
Exemplo n.º 6
0
        public void Recipient_has_a_name()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: "My name is", Lifetime.Transient, IgnoreRecipient);

            Assert.NotNull(recipient.Name);
            Assert.NotEmpty(recipient.Name);
        }
Exemplo n.º 7
0
        public void Error_if_request_or_response_types_are_null()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            Assert.Throws <ArgumentNullException>(() => recipient.CanReplyWith(typeof(int), null !));
            Assert.Throws <ArgumentNullException>(() => recipient.CanReplyWith(null !, typeof(string)));
        }
Exemplo n.º 8
0
        public void Recipient_must_return_something_async()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeAsyncComputingType(), name: null, Lifetime.Transient, IgnoreRecipient);

            bool accepts = recipient.CanReplyWith(typeof(int), typeof(Task));

            Assert.False(accepts);
        }
Exemplo n.º 9
0
        public void Recipient_replies_with_async_response_type()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeAsyncType(), name: null, Lifetime.Transient, IgnoreRecipient);

            bool canAccept = recipient.CanReplyWith(typeof(int), typeof(string));

            Assert.True(canAccept);
        }
Exemplo n.º 10
0
        public void Recipient_accepts_input_parameter_type()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            bool canAccept = recipient.CanAccept(typeof(int));

            Assert.True(canAccept);
        }
Exemplo n.º 11
0
 public void Error_if_invalid_lifetime()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         _ = TypeRecipient.Create(
             registry: new TypeInspectorRegistry(),
             () => new SomeType(),
             name: null,
             lifetime: (Lifetime)42,
             IgnoreRecipient);
     });
 }
Exemplo n.º 12
0
        public async Task Recipient_accepts_request_and_replies_with_task()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeAsyncType(), name: null, Lifetime.Transient, IgnoreRecipient);

            var input   = 42;
            var runners = recipient.Accept(input);
            var runner  = runners[0];
            await runner.Start();

            Assert.Equal(input.ToString(), runner.Result);
        }
Exemplo n.º 13
0
        public async Task Recipient_replies_with_response()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            var input   = 42;
            var runners = recipient.ReplyWith <string>(input);
            var runner  = runners[0];
            await runner.Start();

            Assert.Equal(input.ToString(), runner.Result);
        }
Exemplo n.º 14
0
        public void Can_be_cloned()
        {
            var registry = new TypeInspectorRegistry();

            var recipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            var clone = recipient.Clone();

            Assert.NotNull(clone);
            Assert.IsType <TypeRecipient>(clone);
            Assert.Equal(recipient.Name, clone.Name);
            Assert.Equal(recipient.Lifetime, clone.Lifetime);
            Assert.Equal(recipient.Type, (clone as TypeRecipient) !.Type);
        }
Exemplo n.º 15
0
        public void Has_expected_lifetime()
        {
            var registry = new TypeInspectorRegistry();

            var transientRecipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Transient, IgnoreRecipient);

            var scopedRecipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Scoped, IgnoreRecipient);

            var singletonRecipient = TypeRecipient.Create(
                registry, () => new SomeType(), name: null, Lifetime.Singleton, IgnoreRecipient);

            Assert.Equal(Lifetime.Transient, transientRecipient.Lifetime);
            Assert.Equal(Lifetime.Scoped, scopedRecipient.Lifetime);
            Assert.Equal(Lifetime.Singleton, singletonRecipient.Lifetime);
        }