Example #1
0
        public void ShouldThrowInvalidOperationExceptionWhenDefaultExtensionCannotBeFound()
        {
            // Arrange
            var extensions = new Dictionary <string, Func <ServiceFactory, IExtensionBase> >();
            var extender   = new ExtenderProxy <string>(proxy => new Extender <string>(new ExtenderCore <string>(extensions), proxy, _ => null));
            var component  = new TestItem("TEST-ITEM");

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

            // Assert
            Assert.Equal("Default extension could not by found.", exception.Message);
        }
Example #2
0
        public void ShouldUseDefaultExtensionWhenConcreteExtensionIsNull()
        {
            // Arrange
            var defaultExtension = Mock.Of <IExtension <string, object> >(MockBehavior.Strict);
            var extensions       = new Dictionary <string, Func <ServiceFactory, IExtensionBase> >(new Dictionary <string, Func <ServiceFactory, IExtensionBase> >
            {
                [typeof(TestItem).FullName] = _ => null,
                [typeof(object).FullName]   = _ => defaultExtension
            });

            var extender  = new ExtenderProxy <string>(proxy => new Extender <string>(new ExtenderCore <string>(extensions), proxy, _ => null));
            var component = new TestItem("TEST-ITEM");

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

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