public async Task PublishAsync_throws_when_notification_handler_collection_creation_fails() { Mock.Get(_instanceFactory) .Setup(f => f.Invoke(It.IsAny <Type>())) .Returns((Func <Type, object>)(type => { throw new InvalidCastException(); })); using var scope = AsyncScopedLifestyle.BeginScope(_containerFixture.Container); var noNotification = new EchoNotification(); Func <Task> publishFunc = () => _sut.PublishAsync(noNotification); await publishFunc.Should().ThrowExactlyAsync <ArgumentException>().WithMessage("Handler collection creation failed*"); Mock.Get(_instanceFactory) .Verify(f => f.Invoke(It.Is <Type>(t => t == typeof(IEnumerable <INotificationHandler <EchoNotification> >))), Times.Once()); }
public async Task PublishAsync_succeeds_with_single_handler() { Mock.Get(_instanceFactory) .Setup(f => f.Invoke(It.IsAny <Type>())) .Returns((Func <Type, object>)_containerFixture.Container.GetInstance); using var scope = AsyncScopedLifestyle.BeginScope(_containerFixture.Container); var echoNotification = new EchoNotification(); Func <Task> publishFunc = () => _sut.PublishAsync(echoNotification); await publishFunc.Should().NotThrowAsync(); scope.GetInstance <StringWriter>().ToString().Should().Be("Echo;"); Mock.Get(_instanceFactory) .Verify(f => f.Invoke(It.Is <Type>(t => t == typeof(IEnumerable <INotificationHandler <EchoNotification> >))), Times.Once()); }