Esempio n. 1
0
 public PromotionDataTableMapper(PromotionDto.PromotionLanguageDataTable promotionLanguageTable, PromotionDto.PromotionDataTable promotionTable,
                                 CampaignDto.CampaignDataTable campaignTable)
 {
     _promotionDataTable         = promotionTable;
     _promotionLanguageDataTable = promotionLanguageTable;
     _campaignDataTable          = campaignTable;
 }
        private static IEnumerable <MappedColumnInfo> ToMappedColumnInfos(PromotionDto.PromotionDataTable table)
        {
            var mappedColumns = new[]
            {
                new MappedColumnInfo("Name", "name", type.@string, new FilterOptions(Format.PipeSeparated, Tokenization.Words)),
                new MappedColumnInfo("ApplicationId", type.@string),
                new MappedColumnInfo("Status", type.@string),
                new MappedColumnInfo("StartDate", "start_time", type.timepoint, r => ToStandardDateTime(r, "StartDate"), false),
                new MappedColumnInfo("EndDate", "end_time", type.timepoint, r => ToStandardDateTime(r, "EndDate"), false),
                new MappedColumnInfo("CouponCode", type.@string),
                new MappedColumnInfo("OfferAmount", type.@double, r => double.Parse(r["OfferAmount"].ToString()).ToString("0.00", CultureInfo.InvariantCulture)),
                new MappedColumnInfo("OfferType", type.@string),
                new MappedColumnInfo("PromotionGroup", type.@string),
                new MappedColumnInfo("CampaignId", "campaign_key", type.@string),
                new MappedColumnInfo("ExclusivityType", type.@string),
                new MappedColumnInfo("Priority", type.@string),
                new MappedColumnInfo("Created", type.@long, r => ToUtcEpochTime(r, "Created")),
                new MappedColumnInfo("Modified", type.@long, r => ToUtcEpochTime(r, "Modified")),
                new MappedColumnInfo("ModifiedBy", type.@string),
                new MappedColumnInfo("PromotionType", type.@string, new FilterOptions(Format.PipeSeparated, Tokenization.Words)),
                new MappedColumnInfo("PerOrderLimit", type.@int),
                new MappedColumnInfo("ApplicationLimit", type.@int),
                new MappedColumnInfo("CustomerLimit", type.@int)
            }.ToLookup(mc => mc.ColumnName, mc => mc);
            var ignoredColumnNames = new HashSet <string> {
                "PromotionId", "Params"
            };

            return(ToMappedColumnInfosInternal(table.Columns.Cast <DataColumn>(), mappedColumns, ignoredColumnNames));
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the data and data bind.
        /// </summary>
        /// <param name="sortExpression">The sort expression.</param>
        private void LoadDataAndDataBind(string sortExpression)
        {
            PromotionDto dto = PromotionManager.GetPromotionDto();

            if (dto.Promotion != null)
            {
                PromotionDto.PromotionDataTable table = dto.Promotion;
                table.Columns.Add(new DataColumn("TotalUsed", typeof(Int32)));

                // Get existing statistics
                DataTable usageStatistics = PromotionManager.GetPromotionUsageStatistics();

                // Populate extra column that can be used for display purpose
                foreach (PromotionDto.PromotionRow row in table)
                {
                    int totalUsed = 0;
                    System.Data.DataRow[] rows = usageStatistics.Select(String.Format("PromotionId = {0}", row.PromotionId));
                    if (rows != null && rows.Length > 0)
                    {
                        totalUsed = (int)rows[0]["TotalUsed"];
                    }

                    row["TotalUsed"] = totalUsed;
                }

                DataView view = table.DefaultView;
                view.Sort             = sortExpression;
                MyListView.DataSource = view;
            }

            MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("PromotionId");
            MyListView.DataBind();
        }
Esempio n. 4
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));
        }
        public static PromotionDto.PromotionDataTable WithRow(this PromotionDto.PromotionDataTable table, int promotionId, string name, string promotionType,
                                                              int campaignId, Guid applicationId = default(Guid), string status = "active",
                                                              DateTime?startDate     = null,
                                                              DateTime?endDate       = null, string couponCode        = "", decimal offerAmount    = 20, int offerType       = 1,
                                                              string exclusivityType = "none", int priority           = 1, DateTime?created        = null, DateTime?modified = null,
                                                              string modifiedBy      = "admin", string promotionGroup = "entry", int perOrderLimit = 0,
                                                              int applicationLimit   = 0, XDocument settingsXml       = null, int customerLimit    = 0)
        {
            var row = table.NewPromotionRow();

            row.ApplicationId    = applicationId == default(Guid) ? ApplicationId : applicationId;
            row.ApplicationLimit = applicationLimit;
            row.CampaignId       = campaignId;
            row.CouponCode       = couponCode;
            row.Created          = created ?? DateTime.MinValue;
            row.CustomerLimit    = customerLimit;
            row.EndDate          = endDate ?? DateTime.MaxValue;
            row.ExclusivityType  = exclusivityType;
            row.Modified         = modified ?? DateTime.MinValue;
            row.ModifiedBy       = modifiedBy;
            row.Name             = name;
            row.OfferAmount      = offerAmount;
            row.OfferType        = offerType;

            if (settingsXml != null)
            {
                var stream = new MemoryStream();
                settingsXml.Save(stream);
                row.Params = stream.ToArray();
            }
            else
            {
                row.Params = new byte[0];
            }

            row.PerOrderLimit  = perOrderLimit;
            row.Priority       = priority;
            row.PromotionGroup = promotionGroup;
            row.PromotionId    = promotionId;
            row.PromotionType  = promotionType;
            row.StartDate      = startDate ?? DateTime.MinValue;
            row.Status         = status;

            table.AddPromotionRow(row);
            return(table);
        }
        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 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")
                })
            };
        }