Пример #1
0
        public void Register_Copy_Map()
        {
            var registry = new MapRegistry();

            registry.Copy <CmsKey>()
            .Map(x => x.Key);

            var task = registry.Register <TestItem>();

            Assert.That(task, Is.Not.Null);
            Assert.That(task.Maps.Count, Is.EqualTo(6));
            Assert.That(task.Maps[5] is MapItem <CmsKey, Guid>);
        }
Пример #2
0
        private ICache Setup(Action <IMapTask <TestEntity> > fit)
        {
            var mapRegistry   = new MapRegistry();
            var mapper        = new Mapper(mapRegistry);
            var root          = Substitute.For <ISite>();
            var cacheRegistry = new CacheRegistry(new TestCacheConfig());
            var cacheStore    = new CacheStore();
            var cache         = new Cache(cacheStore, cacheRegistry, root);
            var queryFactory  = Substitute.For <IQueryFactory>();
            var cmsFetcher    = Substitute.For <ICmsFetcher>();
            var registry      = new Registry(mapRegistry, mapper, cacheRegistry, queryFactory, cmsFetcher);

            mapRegistry.Copy <CmsKey>()
            .Map(x => x.Key, "key");
            mapRegistry.Copy <Model>()
            .Map(x => x.Name, "alias");

            registry.Register <TestInfo>();

            registry.Register <TestItem>()
            .MatchMany(x => x.Infos);

            fit(registry.Register <TestEntity>());

            var guid1 = Guid.NewGuid().ToString("N");
            var guid2 = Guid.NewGuid().ToString("N");
            var guid3 = Guid.NewGuid().ToString("N");
            var guid4 = Guid.NewGuid().ToString("N");
            var guid5 = Guid.NewGuid().ToString("N");
            var guid6 = Guid.NewGuid().ToString("N");

            var entity = new Dictionary <string, string>
            {
                { "key", guid1 },
                { "alias", "test" },
                { "id", "1000" },
                { "list", "a,b,c" },
                { "item", guid3 },
                { "items", guid2 + "," + guid4 }
            };
            var content = new UmbracoContent(entity);

            var item1 = new Dictionary <string, string>
            {
                { "key", guid2 },
                { "alias", "testItem1" },
                { "itemId", "1" },
                { "price", "10.00" },
                { "onSale", "true" },
                { "infos", guid5 + "," + guid6 }
            };
            var content1 = new UmbracoContent(item1);

            var item2 = new Dictionary <string, string>
            {
                { "key", guid3 },
                { "alias", "testItem2" },
                { "itemId", "2" },
                { "price", "20.00" },
                { "onSale", "true" }
            };
            var content2 = new UmbracoContent(item2);

            var item3 = new Dictionary <string, string>
            {
                { "key", guid4 },
                { "alias", "testItem3" },
                { "itemId", "3" },
                { "price", "30.00" },
                { "onSale", "true" }
            };
            var content3 = new UmbracoContent(item3);

            var info1 = new Dictionary <string, string>
            {
                { "key", guid5 },
                { "alias", "testInfo1" },
                { "infoId", "1" },
                { "info", "info1" }
            };
            var contentInfo1 = new UmbracoContent(info1);

            var info2 = new Dictionary <string, string>
            {
                { "key", guid6 },
                { "alias", "testInfo2" },
                { "infoId", "2" },
                { "info", "info2" }
            };
            var contentInfo2 = new UmbracoContent(info2);

            var mapItem     = mapRegistry.For <TestItem>() as MapTask <TestItem>;
            var mapEntity   = mapRegistry.For <TestEntity>() as MapTask <TestEntity>;
            var mapInfo     = mapRegistry.For <TestInfo>() as MapTask <TestInfo>;
            var queryItem   = Substitute.For <ICmsQuery <TestItem> >();
            var queryEntity = Substitute.For <ICmsQuery <TestEntity> >();
            var queryInfo   = Substitute.For <ICmsQuery <TestInfo> >();

            queryFactory.Create(root, mapItem).Returns(queryItem);
            queryFactory.Create(root, mapEntity).Returns(queryEntity);
            queryFactory.Create(root, mapInfo).Returns(queryInfo);

            var entityContents = new IContent[] { content };
            var itemContents   = new IContent[] { content1, content2, content3 };
            var infoContents   = new IContent[] { contentInfo2, contentInfo1 };

            cmsFetcher.Fetch(queryItem).Returns(itemContents);
            cmsFetcher.Fetch(queryEntity).Returns(entityContents);
            cmsFetcher.Fetch(queryInfo).Returns(infoContents);

            return(cache);
        }