Пример #1
0
        public async Task ShouldThrowInvalidOperationExceptionWhenDefaultExtensionCannotBeFound()
        {
            // Arrange
            var extensions = new Dictionary <string, Func <ServiceFactory, IAsyncExtensionBase> >();
            var extender   = new AsyncExtenderProxy <string>(proxy => new AsyncExtender <string>(new AsyncExtenderCore <string>(extensions), proxy, _ => null));
            var component  = new TestItem("TEST-ITEM");

            // Act
            var exception = await Assert
                            .ThrowsAsync <InvalidOperationException>(() => extender
                                                                     .Extend(component));

            // Assert
            Assert.Equal("Default extension could not by found.", exception.Message);
        }
Пример #2
0
        public async Task ShouldUseDefaultExtensionWhenConcreteExtensionIsNull()
        {
            // Arrange
            var defaultExtension = Mock.Of <IAsyncExtension <string, object> >(MockBehavior.Strict);
            var extensions       = new Dictionary <string, Func <ServiceFactory, IAsyncExtensionBase> >(new Dictionary <string, Func <ServiceFactory, IAsyncExtensionBase> >
            {
                [typeof(TestItem).FullName] = _ => null,
                [typeof(object).FullName]   = _ => defaultExtension
            });

            var extender  = new AsyncExtenderProxy <string>(proxy => new AsyncExtender <string>(new AsyncExtenderCore <string>(extensions), proxy, _ => null));
            var component = new TestItem("TEST-ITEM");

            Mock.Get(defaultExtension)
            .Setup(d => d.Extend(component, extender))
            .Returns(Task.CompletedTask);

            // Act & Assert
            await extender.Extend(component);
        }