Esempio n. 1
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);
        }
        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")
                })
            };
        }