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));
        }
Example #2
0
 public PromotionDataTableMapper(PromotionDto.PromotionLanguageDataTable promotionLanguageTable, PromotionDto.PromotionDataTable promotionTable,
                                 CampaignDto.CampaignDataTable campaignTable)
 {
     _promotionDataTable         = promotionTable;
     _promotionLanguageDataTable = promotionLanguageTable;
     _campaignDataTable          = campaignTable;
 }
Example #3
0
        private static Promotion GetMockedPromotionWithSettings(XDocument settingsXml)
        {
            var stream = new MemoryStream();

            settingsXml.Save(stream);
            var settings = stream.ToArray();

            var promotionDto   = new PromotionDto();
            var promotionTable = new PromotionDto.PromotionDataTable();

            promotionDto.Tables.Add(promotionTable);
            var promotionRow = promotionTable.AddPromotionRow("", ApplicationGuid, "", DateTime.MinValue, DateTime.MaxValue, "", 0, 0, "", 0, "", 0, DateTime.MinValue,
                                                              DateTime.MinValue, "", "", 0, 0, settings, 0, 0);
            var promotionLanguageTable = new PromotionDto.PromotionLanguageDataTable();

            promotionDto.Tables.Add(promotionLanguageTable);
            var promotionLanguageRow = promotionLanguageTable.AddPromotionLanguageRow("", "en-US", promotionRow);
            var campaignDto          = new CampaignDto();
            var campaignTable        = new CampaignDto.CampaignDataTable();

            campaignDto.Tables.Add(campaignTable);
            var campaignRow = campaignTable.AddCampaignRow(ApplicationGuid, DateTime.MinValue, DateTime.MaxValue, "", DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, "", true, false, "");

            return(new Promotion(promotionLanguageRow, promotionRow, campaignRow));
        }
        internal IEnumerable <ConfigurationAttribute> ConvertToAttributes(PromotionDto.PromotionLanguageDataTable promotionLanguageTable, PromotionDto.PromotionDataTable promotionTable,
                                                                          CampaignDto.CampaignDataTable campaignTable)
        {
            var campaignAttributes          = ToAttributesInternal(ToMappedColumnInfos(campaignTable));
            var promotionAttributes         = ToAttributesInternal(ToMappedColumnInfos(promotionTable));
            var promotionLanguageAttributes = ToAttributesInternal(ToMappedColumnInfos(promotionLanguageTable));

            return(campaignAttributes
                   .Where(ca => !promotionAttributes.Select(pa => pa.Name).Contains(ca.Name))
                   .Where(ca => !promotionLanguageAttributes.Select(pla => pla.Name).Contains(ca.Name))
                   .Concat(promotionAttributes.Where(pa => !promotionLanguageAttributes.Select(pla => pla.Name).Contains(pa.Name)))
                   .Concat(promotionLanguageAttributes));
        }
        public static PromotionDto.PromotionLanguageDataTable WithRow(this PromotionDto.PromotionLanguageDataTable table, int promotionLanguageId, int promotionId,
                                                                      string languageCode,
                                                                      string displayName)
        {
            var row = table.NewPromotionLanguageRow();

            row.DisplayName         = displayName;
            row.LanguageCode        = languageCode;
            row.PromotionId         = promotionId;
            row.PromotionLanguageId = promotionLanguageId;

            table.AddPromotionLanguageRow(row);
            return(table);
        }
        public void IndexAds()
        {
            var builder = new ContainerBuilder();

            var          appConfigMock   = new Mock <IAppConfig>();
            const string applicationName = "Test";
            const string scope           = "TestScope";

            appConfigMock.Setup(c => c.ApplicationId).Returns(() => applicationName);
            appConfigMock.Setup(c => c.Scope).Returns(() => scope);
            appConfigMock.Setup(c => c.Enable).Returns(() => true);
            appConfigMock.Setup(c => c.EnableAds).Returns(() => true);
            builder.Register(c => appConfigMock.Object);

            var fileSystemMock = new Mock <IFileSystem>();
            var xmlStream      = new MemoryStream();

            fileSystemMock.Setup(fsm => fsm.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>())).Returns(xmlStream);
            builder.Register(c => fileSystemMock.Object);

            builder.RegisterType <FileHelper>();

            var          promotionLanguageDataTable = new PromotionDto.PromotionLanguageDataTable().WithRow(1, 1000001, "en-us", "20% off on Chateau");
            const string promotionTypeInclude       = "BuyXGetYDiscounted";
            var          applicationId      = Guid.Parse("024b3344-402a-4100-8764-384263b729c1");
            var          promotionDataTable = new PromotionDto.PromotionDataTable().WithRow(1000001, "20% off on Chateau [NO LANGUAGE]", promotionTypeInclude, 1, applicationId,
                                                                                            startDate: new DateTime(2012, 1, 1, 8, 17, 0, DateTimeKind.Local),
                                                                                            endDate: new DateTime(2020, 12, 31, 8, 17, 0, DateTimeKind.Local),
                                                                                            created: new DateTime(2012, 9, 21, 7, 19, 11, DateTimeKind.Local),
                                                                                            modified: new DateTime(2012, 10, 4, 7, 6, 28, DateTimeKind.Local));
            var campaignDataTable = new CampaignDto.CampaignDataTable().WithRow(
                1, "Wine", applicationId, created: new DateTime(2008, 10, 7, 22, 14, 13, DateTimeKind.Local),
                exported: new DateTime(1970, 1, 1, 1, 0, 0, DateTimeKind.Local), modified: new DateTime(2012, 10, 4, 7, 5, 9, DateTimeKind.Local));
            var promotionDataTableMapper = new PromotionDataTableMapper(promotionLanguageDataTable, promotionDataTable, campaignDataTable);

            builder.Register(c => promotionDataTableMapper);

            var promotionEntryCodes1 = new Mock <IPromotionEntryCodes>();

            promotionEntryCodes1.Setup(pm => pm.PromotionType).Returns(promotionTypeInclude);
            promotionEntryCodes1
            .Setup(pm => pm.Included(It.IsAny <Promotion>()))
            .Returns <Promotion>(p => p.PromotionRow.PromotionType == promotionTypeInclude ? new[] { "WHATEVER" } : Enumerable.Empty <string>());
            promotionEntryCodes1.Setup(pm => pm.Excluded(It.IsAny <Promotion>())).Returns <Promotion>(p => Enumerable.Empty <string>());
            builder.Register(c => promotionEntryCodes1.Object);

            builder.RegisterType <PromotionEntryCodeProvider>();

            var indexSystemMock = new Mock <IIndexSystemMapper>();

            builder.Register(c => indexSystemMock.Object);

            builder.RegisterType <AdsIndexBuilder>();

            var expectedXElement = XElement.Parse(@"<operations>
                                                        <clear>
                                                          <ad/>
                                                        </clear>
                                                        <add>
                                                          <ad>
                                                            <campaign_name>Wine</campaign_name>
                                                            <campaign_created>1223410453000</campaign_created>
                                                            <campaign_exported>0</campaign_exported>
                                                            <campaign_modified>1349327109000</campaign_modified>
                                                            <campaign_modified_by>admin</campaign_modified_by>
                                                            <campaign_is_active>True</campaign_is_active>
                                                            <campaign_is_archived>False</campaign_is_archived>
                                                            <name>20% off on Chateau</name>
                                                            <application_id>" + applicationId + @"</application_id>
                                                            <status>active</status>
                                                            <start_time>2012-01-01T07:17:00Z</start_time>
                                                            <end_time>2020-12-31T07:17:00Z</end_time>
                                                            <offer_amount>20.00</offer_amount>
                                                            <offer_type>1</offer_type>
                                                            <promotion_group>entry</promotion_group>
                                                            <campaign_key>1</campaign_key>
                                                            <exclusivity_type>none</exclusivity_type>
                                                            <priority>1</priority>
                                                            <created>1348204751000</created>
                                                            <modified>1349327188000</modified>
                                                            <modified_by>admin</modified_by>
                                                            <promotion_type>BuyXGetYDiscounted</promotion_type>
                                                            <per_order_limit>0</per_order_limit>
                                                            <application_limit>0</application_limit>
                                                            <customer_limit>0</customer_limit>
                                                            <locale>en_US</locale>
                                                            <locale_filter>en_US</locale_filter>
                                                            <ad_key>1000001_en_US</ad_key>
                                                            <included>locale_filter:'en_US' AND ad_key_included:'1000001_en_US'</included>
                                                            <live_products>4</live_products>
                                                          </ad>
                                                        </add>
                                                      </operations>");

            var container = builder.Build();

            container.Resolve <AdsIndexBuilder>().Build(false);
            XElement xml;

            using (var reader = new StreamReader(new MemoryStream(xmlStream.ToArray())))
            {
                xml = XElement.Parse(reader.ReadToEnd());
            }

            try
            {
                Assert.That(xml.ElementsEquivalentTo(expectedXElement));
            }
            catch (AssertionException)
            {
                Console.WriteLine("Expected:");
                Console.WriteLine(expectedXElement);
                Console.WriteLine();
                Console.WriteLine("Actual:");
                Console.WriteLine(xml);
                throw;
            }
        }
        public void Setup()
        {
            _adAttributeHelper = new AdAttributeHelper();

            _attributes = _adAttributeHelper.ConvertToAttributes(new PromotionDto.PromotionLanguageDataTable(), new PromotionDto.PromotionDataTable(),
                                                                 new CampaignDto.CampaignDataTable());
            var search = new SearchOptions(null, Format.PipeSeparated, true, true);
            var filter = new FilterOptions(Format.PipeSeparated, Tokenization.CaseInsensitive);
            var sort   = new SortOptions(Normalization.CaseInsensitive);

            _expectedConfigurationAttributes = new[]
            {
                new ConfigurationAttribute("ad_key", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("name", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("application_id", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("status", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("coupon_code", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("offer_amount", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("offer_type", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("promotion_group", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_key", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("exclusivity_type", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("priority", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("created", type.@long, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("modified", type.@long, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("modified_by", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("promotion_type", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("per_order_limit", type.@int, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("application_limit", type.@int, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("customer_limit", type.@int, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_name", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_created", type.@long, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_exported", type.@long, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_modified", type.@long, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_modified_by", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_is_active", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_is_archived", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("campaign_comments", type.@string, Present.Yes, search, filter, sort),
                new ConfigurationAttribute("locale_filter", type.@string, Present.Yes, search, filter, sort)
            };

            var campaignTable = new CampaignDto.CampaignDataTable();
            var campaignId    =
                campaignTable.AddCampaignRow(Guid.Parse("0351ca45-b49f-4002-8433-1008a1f6fa6b"), DateTime.MinValue, DateTime.MinValue, "CampaignNameTest",
                                             new DateTime(2012, 08, 20, 07, 07, 11, DateTimeKind.Local), new DateTime(2012, 08, 21, 0, 0, 0, DateTimeKind.Local),
                                             new DateTime(2012, 08, 21, 13, 02, 37, DateTimeKind.Local), "CampaignModifiedByTest", true, false, "CommentsTest")
                .CampaignId;
            var promotionTable = new PromotionDto.PromotionDataTable();
            var promotionRow   = promotionTable.AddPromotionRow("NameTest", Guid.Parse("0351ca45-b49f-4002-8433-1008a1f6fa6b"), "active",
                                                                new DateTime(2012, 08, 20, 07, 37, 00, DateTimeKind.Local),
                                                                new DateTime(2012, 08, 23, 07, 37, 00, DateTimeKind.Local), "CouponCodeTest", 100.5m, 1,
                                                                "PromotionGroupTest", campaignId, "ExclusivityTypeTest", 3,
                                                                new DateTime(2012, 08, 20, 07, 39, 07, DateTimeKind.Local),
                                                                new DateTime(2012, 11, 06, 12, 43, 16, DateTimeKind.Local), "ModifiedByTest", "PromotionTypeTest", 4, 5,
                                                                new byte[] { 1, 2, 3 }, 6, 10);
            var promotionLanguageTable = new PromotionDto.PromotionLanguageDataTable();

            promotionLanguageTable.AddPromotionLanguageRow("DisplayNameTestSE", "sv-SE", promotionRow);
            promotionLanguageTable.AddPromotionLanguageRow("DisplayNameTestFI", "sv-FI", promotionRow);

            var promotionDataTableMapper   = new PromotionDataTableMapper(promotionLanguageTable, promotionTable, campaignTable);
            var promotionEntryCodeProvider = new PromotionEntryCodeProvider(promotionDataTableMapper, Enumerable.Empty <IPromotionEntryCodes>());

            _ads = _adAttributeHelper.ConvertToAds(promotionDataTableMapper, promotionEntryCodeProvider);

            _expectedAds = new[]
            {
                new Ad(new[]
                {
                    //CampaignTable
                    new Attribute("campaign_name", "CampaignNameTest"),
                    new Attribute("campaign_created", "1345439231000"),
                    new Attribute("campaign_exported", "1345500000000"),
                    new Attribute("campaign_modified", "1345546957000"),
                    new Attribute("campaign_modified_by", "CampaignModifiedByTest"),
                    new Attribute("campaign_is_active", "True"),
                    new Attribute("campaign_is_archived", "False"),
                    new Attribute("campaign_comments", "CommentsTest"),

                    //PromotionTable
                    new Attribute("application_id", "0351ca45-b49f-4002-8433-1008a1f6fa6b"),
                    new Attribute("status", "active"),
                    new Attribute("start_time", "2012-08-20T05:37:00Z"),
                    new Attribute("end_time", "2012-08-23T05:37:00Z"),
                    new Attribute("coupon_code", "CouponCodeTest"),
                    new Attribute("offer_amount", "100.50"),
                    new Attribute("offer_type", "1"),
                    new Attribute("promotion_group", "PromotionGroupTest"),
                    new Attribute("campaign_key", campaignId.ToString()),
                    new Attribute("exclusivity_type", "ExclusivityTypeTest"),
                    new Attribute("priority", "3"),
                    new Attribute("created", "1345441147000"),
                    new Attribute("modified", "1352202196000"),
                    new Attribute("modified_by", "ModifiedByTest"),
                    new Attribute("promotion_type", "PromotionTypeTest"),
                    new Attribute("per_order_limit", "4"),
                    new Attribute("application_limit", "5"),
                    new Attribute("customer_limit", "6"),
                    new Attribute("max_entry_discount_quantity", "10"),

                    //PromotionLanguageTable
                    new Attribute("ad_key", promotionRow.PromotionId + "_sv_SE"),
                    new Attribute("name", "DisplayNameTestSE"),
                    new Attribute("locale", "sv_SE"),
                    new Attribute("locale_filter", "sv_SE"),
                    new Attribute("included", "locale_filter:'sv_SE'"),

                    //Static Attributes
                    new Attribute("live_products", "4")
                }),
                new Ad(new[]
                {
                    //CampaignTable
                    new Attribute("campaign_name", "CampaignNameTest"),
                    new Attribute("campaign_created", "1345439231000"),
                    new Attribute("campaign_exported", "1345500000000"),
                    new Attribute("campaign_modified", "1345546957000"),
                    new Attribute("campaign_modified_by", "CampaignModifiedByTest"),
                    new Attribute("campaign_is_active", "True"),
                    new Attribute("campaign_is_archived", "False"),
                    new Attribute("campaign_comments", "CommentsTest"),

                    //PromotionTable
                    new Attribute("application_id", "0351ca45-b49f-4002-8433-1008a1f6fa6b"),
                    new Attribute("status", "active"),
                    new Attribute("start_time", "2012-08-20T05:37:00Z"),
                    new Attribute("end_time", "2012-08-23T05:37:00Z"),
                    new Attribute("coupon_code", "CouponCodeTest"),
                    new Attribute("offer_amount", "100.50"),
                    new Attribute("offer_type", "1"),
                    new Attribute("promotion_group", "PromotionGroupTest"),
                    new Attribute("campaign_key", campaignId.ToString()),
                    new Attribute("exclusivity_type", "ExclusivityTypeTest"),
                    new Attribute("priority", "3"),
                    new Attribute("created", "1345441147000"),
                    new Attribute("modified", "1352202196000"),
                    new Attribute("modified_by", "ModifiedByTest"),
                    new Attribute("promotion_type", "PromotionTypeTest"),
                    new Attribute("per_order_limit", "4"),
                    new Attribute("application_limit", "5"),
                    new Attribute("customer_limit", "6"),
                    new Attribute("max_entry_discount_quantity", "10"),

                    //PromotionLanguageTable
                    new Attribute("ad_key", promotionRow.PromotionId + "_sv_FI"),
                    new Attribute("name", "DisplayNameTestFI"),
                    new Attribute("locale", "sv_FI"),
                    new Attribute("locale_filter", "sv_FI"),
                    new Attribute("included", "locale_filter:'sv_FI'"),

                    //Static Attributes
                    new Attribute("live_products", "4")
                })
            };
        }