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)); }
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)); }
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)); }
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); }
public void Recipient_can_be_created_from_type() { _ = TypeRecipient.Create( registry: new TypeInspectorRegistry(), () => new SomeType(), name: null, lifetime: Lifetime.Transient, IgnoreRecipient); }
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); }
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))); }
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); }
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); }
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); }
public void Error_if_invalid_lifetime() { Assert.Throws <ArgumentException>(() => { _ = TypeRecipient.Create( registry: new TypeInspectorRegistry(), () => new SomeType(), name: null, lifetime: (Lifetime)42, IgnoreRecipient); }); }
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); }
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); }
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); }
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); }