コード例 #1
0
        private static EntryConverter Build(ICatalogSystemMapper catalogSystem)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <EntryConverter>();
            builder.Register(c => catalogSystem);
            builder.Register(c => new Mock <IMetaDataMapper>().Object);
            builder.Register(c => new Mock <IPriceServiceMapper>().Object);
            builder.Register(c => new Mock <IConfiguration>().Object);
            builder.Register(c => new Mock <IUrlResolver>().Object);

            var keyLookup = new Mock <IKeyLookup>();

            keyLookup
            .Setup(kl => kl.Value(It.IsAny <CatalogEntryDto.CatalogEntryRow>(), It.IsAny <string>()))
            .Returns <CatalogEntryDto.CatalogEntryRow, string>((e, l) => AttributeHelper.CreateKey(e.Code, l));
            builder.Register(c => keyLookup.Object);

            builder.Register(c => new PromotionEntryCodeProvider(c.Resolve <PromotionDataTableMapper>(), Enumerable.Empty <IPromotionEntryCodes>()));
            builder.Register(c => new PromotionDataTableMapper(
                                 new PromotionDto.PromotionLanguageDataTable(),
                                 new PromotionDto.PromotionDataTable(),
                                 new CampaignDto.CampaignDataTable()));

            builder.RegisterAssemblyTypes(typeof(IFormatRule).Assembly).As <IFormatRule>();
            builder.RegisterType <Formatter>();

            var container = builder.Build();

            return(container.Resolve <EntryConverter>());
        }
コード例 #2
0
        private static IEnumerable <MappedColumnInfo> ToMappedColumnInfos(PromotionDto.PromotionLanguageDataTable table, PromotionEntryCodeProvider promotionEntryCodeProvider = null)
        {
            var mappedColumns = new[]
            {
                new MappedColumnInfo("PromotionId", "ad_key", type.@string, r => AttributeHelper.CreateKey(r["PromotionId"].ToString(), r["LanguageCode"].ToString())),
                new MappedColumnInfo("PromotionId", "included", type.@string,
                                     r =>
                {
                    var language = r["LanguageCode"].ToString();
                    var includedProductFilter =
                        GetIncludedProductFilter(AttributeHelper.CreateKey(r["PromotionId"].ToString(), language),
                                                 promotionEntryCodeProvider);
                    var includedLocaleFilter = string.Format("locale_filter:'{0}'", language.ToESalesLocale());
                    return(!string.IsNullOrWhiteSpace(includedProductFilter)
                                                             ? string.Format("{0} AND {1}", includedLocaleFilter, includedProductFilter)
                                                             : includedLocaleFilter);
                },
                                     false),
                new MappedColumnInfo("DisplayName", "name", type.@string, new FilterOptions(Format.PipeSeparated, Tokenization.Words)),
                new MappedColumnInfo("LanguageCode", "locale", type.@string, r => r["LanguageCode"].ToString().ToESalesLocale(), false),
                new MappedColumnInfo("LanguageCode", "locale_filter", type.@string, r => r["LanguageCode"].ToString().ToESalesLocale())
            }.ToLookup(mc => mc.ColumnName, mc => mc);
            var ignoredColumnNames = new HashSet <string> {
                "PromotionLanguageId"
            };

            return(ToMappedColumnInfosInternal(table.Columns.Cast <DataColumn>(), mappedColumns, ignoredColumnNames));
        }
コード例 #3
0
        private static ProductIndexBuilder Build(CatalogEntryDto.CatalogEntryDataTable entries, IOperationsWriter writer)
        {
            var appConfig           = new Mock <IAppConfig>();
            var catalogSystem       = new Mock <ICatalogSystemMapper>();
            var indexSystem         = new Mock <IIndexSystemMapper>();
            var keyLookup           = new Mock <IKeyLookup>();
            var metaData            = new Mock <IMetaDataMapper>();
            var priceService        = new Mock <IPriceServiceMapper>();
            var fileSystem          = new Mock <IFileSystem>();
            var entryAdditionalData = new Mock <IEntryAdditionalData>();

            entryAdditionalData
            .Setup(ead => ead.GetCatalogItemSeoRows(It.IsAny <CatalogEntryDto.CatalogEntryRow>()))
            .Returns <CatalogEntryDto.CatalogEntryRow>(e => e.GetSeo());

            catalogSystem.Setup(cs => cs.GetCatalogs()).Returns(new CatalogDto.CatalogDataTable().WithRow("FooCatalog"));
            catalogSystem
            .Setup(cs => cs.StartFindItemsForIndexing(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>()))
            .Returns(entries.Count);
            catalogSystem
            .Setup(cs => cs.ContinueFindItemsForIndexing(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(entries);

            keyLookup
            .Setup(kl => kl.Value(It.IsAny <CatalogEntryDto.CatalogEntryRow>(), It.IsAny <string>()))
            .Returns <CatalogEntryDto.CatalogEntryRow, string>((e, l) => AttributeHelper.CreateKey(e.Code, l));

            fileSystem
            .Setup(fsm => fsm.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>()))
            .Returns(new MemoryStream(new UTF8Encoding(false).GetBytes("<SearchConfig><SearchFilters/></SearchConfig>")));

            var builder = new ContainerBuilder();

            builder.RegisterType <ProductIndexBuilder>();
            builder.Register(c => appConfig.Object);
            builder.Register(c => catalogSystem.Object);
            builder.Register(c => indexSystem.Object);
            builder.Register(c => keyLookup.Object);
            builder.Register(c => writer);
            builder.Register(c => metaData.Object);
            builder.Register(c => priceService.Object);
            builder.Register(c => entryAdditionalData.Object);
            builder.RegisterType <EntryConverter>();
            builder.Register(c => new PromotionEntryCodeProvider(c.Resolve <PromotionDataTableMapper>(), Enumerable.Empty <IPromotionEntryCodes>()));
            builder.Register(c => new PromotionDataTableMapper(
                                 new PromotionDto.PromotionLanguageDataTable(),
                                 new PromotionDto.PromotionDataTable(),
                                 new CampaignDto.CampaignDataTable()));
            builder.RegisterAssemblyTypes(typeof(IFormatRule).Assembly).As <IFormatRule>();
            builder.RegisterType <Formatter>();
            builder.RegisterType <Configuration>().As <IConfiguration>();
            builder.Register(c => fileSystem.Object);
            builder.RegisterType <AdAttributeHelper>();
            builder.RegisterType <UrlResolver>().As <IUrlResolver>();
            var container = builder.Build();

            return(container.Resolve <ProductIndexBuilder>());
        }
コード例 #4
0
        private static ContainerBuilder Builder()
        {
            var appConfig = new Mock <IAppConfig>();

            appConfig.Setup(ac => ac.EnableAds).Returns(true);
            var catalogSystem = new Mock <ICatalogSystemMapper>();

            catalogSystem.Setup(cs => cs.GetCatalogs()).Returns(new CatalogDto.CatalogDataTable().WithRow("FooCatalog"));
            catalogSystem
            .Setup(cs => cs.StartFindItemsForIndexing(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>()))
            .Returns(1);
            catalogSystem.Setup(cs => cs.ContinueFindItemsForIndexing(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new CatalogEntryDto.CatalogEntryDataTable().WithRow(1, "CODE1", "foo1").WithRow(2, "CODE2", "foo2"));
            var metaData     = new Mock <IMetaDataMapper>();
            var priceService = new Mock <IPriceServiceMapper>();
            var keyLookup    = new Mock <IKeyLookup>();

            keyLookup.Setup(kl => kl.Value(It.IsAny <CatalogEntryDto.CatalogEntryRow>(), It.IsAny <string>()))
            .Returns <CatalogEntryDto.CatalogEntryRow, string>((e, l) => AttributeHelper.CreateKey(e.Code, l));
            var configuration = new Mock <IConfiguration>();

            configuration.Setup(c => c.ProductAttributes).Returns(new[] { new ConfigurationAttribute("name", type.@string, Present.Yes) });
            var indexSystem = new Mock <IIndexSystemMapper>();
            var urlResolver = new Mock <IUrlResolver>();

            var builder = new ContainerBuilder();

            builder.RegisterType <ProductIndexBuilder>();
            builder.RegisterType <EntryConverter>();
            builder.Register(c => catalogSystem.Object);
            builder.Register(c => metaData.Object);
            builder.Register(c => priceService.Object);
            builder.Register(c => keyLookup.Object);
            builder.Register(c => configuration.Object);
            builder.RegisterType <Formatter>();
            builder.RegisterAssemblyTypes(typeof(Formatter).Assembly).As <IFormatRule>();
            builder.RegisterType <AdsIndexBuilder>();
            builder.Register(c => appConfig.Object);
            builder.RegisterType <FileHelper>();
            builder.Register(c => new PromotionDto.PromotionLanguageDataTable().WithRow(1, 2, "sv-se", "FooAd-SE"));
            builder.Register(c => new PromotionDto.PromotionDataTable().WithRow(2, "FooAd", "FooBarType", 3));
            builder.Register(c => new CampaignDto.CampaignDataTable().WithRow(3, "FooCampaign"));
            builder.RegisterType <PromotionDataTableMapper>();
            builder.RegisterType <PromotionEntryCodeProvider>();
            builder.Register(c => indexSystem.Object);
            builder.Register(c => new ESalesVariantHelper(Enumerable.Empty <CatalogRelationDto.CatalogEntryRelationRow>()));
            builder.Register(c => urlResolver.Object);

            return(builder);
        }
        public PromotionEntryCodeProvider(PromotionDataTableMapper promotionDataTableMapper, IEnumerable <IPromotionEntryCodes> promotionEntryCodes)
        {
            var promotions      = promotionDataTableMapper.Promotions;
            var providers       = promotionEntryCodes.ToDictionary(pec => pec.PromotionType);
            var adKeysWithCodes = (from p in promotions
                                   where providers.ContainsKey(p.PromotionRow.PromotionType)
                                   let provider = providers[p.PromotionRow.PromotionType]
                                                  select new
            {
                AdKey = AttributeHelper.CreateKey(p.PromotionRow.PromotionId.ToString(), p.PromotionLanguageRow.LanguageCode),
                Included = provider.Included(p),
                Excluded = provider.Excluded(p)
            }).ToArray();

            _included = adKeysWithCodes
                        .SelectMany(a => a.Included.Select(i => new { Included = i, a.AdKey }))
                        .ToLookup(i => i.Included, i => i.AdKey);
            _excluded = adKeysWithCodes
                        .SelectMany(a => a.Excluded.Select(e => new { Excluded = e, a.AdKey }))
                        .ToLookup(e => e.Excluded, e => e.AdKey);
            _adsWithIncluded = new HashSet <string>(adKeysWithCodes.Where(a => a.Included.Any()).Select(a => a.AdKey));
            _adsWithExcluded = new HashSet <string>(adKeysWithCodes.Where(a => a.Excluded.Any()).Select(a => a.AdKey));
        }
コード例 #6
0
        public void EscapeIllegalCharacters()
        {
            var actual = AttributeHelper.CreateKey("foo bar", "sv-se");

            Assert.That(actual, Is.EqualTo("foo+bar_sv_SE"));
        }
コード例 #7
0
        public void EscapeIllegalAndEscapeCharacters()
        {
            var actual = AttributeHelper.CreateKey("fee fi fo+fum", "sv-se");

            Assert.That(actual, Is.EqualTo("fee+fi+fo++fum_sv_SE"));
        }
コード例 #8
0
 public string Value(int id, string language)
 {
     return(AttributeHelper.CreateKey(id.ToString(CultureInfo.InvariantCulture), language));
 }
コード例 #9
0
 public string Value(CatalogEntryDto.CatalogEntryRow entry, string language)
 {
     return(AttributeHelper.CreateKey(entry.CatalogEntryId.ToString(CultureInfo.InvariantCulture), language));
 }
コード例 #10
0
 public string Value(CatalogEntryDto.CatalogEntryRow entry, string language)
 {
     return(AttributeHelper.CreateKey(entry.Code, language));
 }