예제 #1
0
        public void TestSetup()
        {
            _mockOptions = Substitute.For <IConfigurationOptions>();
            _mockOptions.Assemblies.Returns(new[] { Assembly.GetAssembly(GetType()).FullName });
            _mockContainer = Substitute.For <IContainer>();

            _mockImplFactory = Substitute.For <IImplementationFactory>();
            _mockCache       = Substitute.For <IGlassTemplateCacheService>();
            _mockTypeLoader  = Substitute.For <IGlassTypesLoader>();

            _builder = new AutofacGlassFactoryBuilder(_mockOptions, _mockContainer, lookup => _mockCache, _mockTypeLoader, _mockImplFactory);
        }
예제 #2
0
        public GlassInterfaceFactory(IGlassTemplateCacheService templateCache, IImplementationFactory factory)
        {
            if (templateCache == null)
            {
                throw new ArgumentNullException(nameof(templateCache));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            _templateCache = templateCache;
            _factory       = factory;
        }
예제 #3
0
 public FallbackInterceptor(Type interfaceType, object model, IGlassTemplateCacheService templateCache, IImplementationFactory implementationFactory)
 {
     if (interfaceType == null)
     {
         throw new ArgumentNullException(nameof(interfaceType));
     }
     if (model == null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     if (templateCache == null)
     {
         throw new ArgumentNullException(nameof(templateCache));
     }
     if (implementationFactory == null)
     {
         throw new ArgumentNullException(nameof(implementationFactory));
     }
     _interfaceType         = interfaceType;
     _model                 = model;
     _templateCache         = templateCache;
     _implementationFactory = implementationFactory;
 }
예제 #4
0
        public void Initialize()
        {
            _mockService = Substitute.For <ISitecoreService>();

            var typeDictionary = new Dictionary <Type, IEnumerable <GlassInterfaceMetadata> >
            {
                // Type of Glass Factory Interface (and associated 'abstract' implementations)
                {
                    typeof(ITestInterface), new[]
                    {
                        // Base Type, matches no direct template
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IBaseType),
                            ImplementationType = typeof(IBaseTypeModel),
                            IsFallback         = true,
                            ZIndex             = 0
                        },
                        // Actual sitecore template type, inherits BaseType
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IInheritedTemplate),
                            ImplementationType = typeof(IInheritedTemplateLowerPriorityModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        },
                        // Actual sitecore template type, inherits BaseType
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IInheritedTemplate),
                            ImplementationType = typeof(IInheritedTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 1
                        },
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IIntermediateTemplate),
                            ImplementationType = typeof(IIntermediateTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        }
                    }
                },
                {
                    typeof(INestedTestInterface), new[]
                    {
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IIntermediateTemplate),
                            ImplementationType = typeof(IIntermediateTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        },
                        // Base Type, matches no direct template
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IBaseType),
                            ImplementationType = typeof(IBaseTypeModel),
                            IsFallback         = true,
                            ZIndex             = 0
                        },
                    }
                }
            };

            _interfaceMappings = typeDictionary
                                 .SelectMany(pair => pair.Value,
                                             (pair, metadata) => new KeyValuePair <Type, GlassInterfaceMetadata>(pair.Key, metadata))
                                 .ToLookup(pair => pair.Key, pair => pair.Value);

            // Tightly-coupled test dependency... hmm
            _implFactory = new ProxyImplementationFactory((t, model) => new FallbackInterceptor(t, model, _glassFactory.TemplateCacheService, _implFactory));

            _templateCache = new GlassTemplateCacheService(_interfaceMappings, () => _mockService);

            // System Under Test
            _glassFactory = new GlassInterfaceFactory(_templateCache, _implFactory);
        }