Example #1
0
        public void RetrieveOfferTest()
        {
            // Create a provider.
            Provider provider = new Provider()
            {
                GlobalID = "ProviderID1",
                Name     = "Provider1"
            };

            // Place objects in the Context.
            Context = new CommerceContext(String.Empty);
            Context[Key.Provider] = provider;

            // Add the provider.
            ProviderOperations providerOperations = new ProviderOperations();

            providerOperations.Context = Context;
            Assert.AreEqual(ResultCode.Created, providerOperations.AddOrUpdateProvider());

            // Create an offer.
            Offer offer = new Offer
            {
                GlobalID         = Guid.NewGuid(),
                GlobalProviderID = "ProviderID1",
                OfferType        = OfferType.Earn,
                PercentBack      = 7,
                Active           = true
            };

            // Place objects in the Context.
            Context[Key.Offer] = offer;

            // Add the offer.
            Assert.AreEqual(ResultCode.Created, AddOrUpdateOffer());

            // Retrieve the offer.
            Context[Key.Offer]         = null;
            Context[Key.GlobalOfferID] = offer.GlobalID;
            Offer retrievedOffer = RetrieveOffer();

            // Compare the offers.
            Assert.AreEqual(offer.Id, retrievedOffer.Id);
            Assert.AreEqual(offer.GlobalID, retrievedOffer.GlobalID);
            Assert.AreEqual(offer.GlobalProviderID, retrievedOffer.GlobalProviderID);
            Assert.AreEqual(offer.OfferType, retrievedOffer.OfferType);
            Assert.AreEqual(offer.PercentBack, retrievedOffer.PercentBack);
            Assert.AreEqual(offer.Active, retrievedOffer.Active);

            // Invalid global offer ID
            Context[Key.GlobalOfferID] = Guid.NewGuid();
            Assert.IsNull(RetrieveOffer());
        }
Example #2
0
        public void AddOrUpdateOfferTest()
        {
            // Create a provider.
            Provider provider = new Provider()
            {
                GlobalID = "ProviderID1",
                Name     = "Provider1"
            };

            // Place objects in the Context.
            Context = new CommerceContext(String.Empty);
            Context[Key.Provider] = provider;

            // Add the provider.
            ProviderOperations providerOperations = new ProviderOperations();

            providerOperations.Context = Context;
            Assert.AreEqual(ResultCode.Created, providerOperations.AddOrUpdateProvider());

            // Create an offer.
            Offer offer = new Offer
            {
                GlobalID         = Guid.NewGuid(),
                GlobalProviderID = "ProviderID1",
                OfferType        = OfferType.Earn,
                PercentBack      = 7,
                Active           = true
            };

            // Place objects in the Context.
            Context[Key.Offer] = offer;

            // Add the offer.
            Assert.AreEqual(ResultCode.Created, AddOrUpdateOffer());

            // Update the offer.
            offer.PercentBack = 25;
            Assert.AreEqual(ResultCode.Success, AddOrUpdateOffer());

            // Invalid global provider ID.
            offer.GlobalProviderID = "invalid";
            Assert.AreEqual(ResultCode.InvalidDeal, AddOrUpdateOffer());
        }
Example #3
0
        public void RetrieveMerchantTest()
        {
            // Create a provider.
            Provider provider = new Provider()
            {
                GlobalID = "ProviderID1",
                Name     = "Provider1"
            };

            // Place objects in the Context.
            Context = new CommerceContext(String.Empty);
            Context[Key.Provider] = provider;

            // Add the provider.
            ProviderOperations providerOperations = new ProviderOperations();

            providerOperations.Context = Context;
            Assert.AreEqual(ResultCode.Created, providerOperations.AddOrUpdateProvider());

            // Create a merchant with populated partner merchant records.
            List <PartnerMerchantAuthorizationID> partnerMerchantAuthorizationIDs = new List <PartnerMerchantAuthorizationID>();
            PartnerMerchantAuthorizationID        visaAuthorizationID             = new PartnerMerchantAuthorizationID
            {
                Partner         = CardBrand.Visa,
                AuthorizationID = "VisaMerchant1AuthAndSettlementID1"
            };

            partnerMerchantAuthorizationIDs.Add(visaAuthorizationID);

            PartnerMerchantAuthorizationID masterCardAuthorizationID = new PartnerMerchantAuthorizationID
            {
                Partner         = CardBrand.MasterCard,
                AuthorizationID = "MasterCardMerchant1AuthID1"
            };

            partnerMerchantAuthorizationIDs.Add(masterCardAuthorizationID);

            List <PartnerMerchantSettlementID> partnerMerchantSettlementIDs = new List <PartnerMerchantSettlementID>();
            PartnerMerchantSettlementID        visaSettlementID             = new PartnerMerchantSettlementID
            {
                Partner      = CardBrand.Visa,
                SettlementID = "VisaMerchant1AuthAndSettlementID1"
            };

            partnerMerchantSettlementIDs.Add(visaSettlementID);

            PartnerMerchantSettlementID masterCardSettlementID = new PartnerMerchantSettlementID
            {
                Partner      = CardBrand.MasterCard,
                SettlementID = "MasterCardMerchant1SettlementID1"
            };

            partnerMerchantSettlementIDs.Add(masterCardSettlementID);

            Merchant merchant = new Merchant()
            {
                GlobalID                        = "MerchantID1",
                Name                            = "Merchant1",
                GlobalProviderID                = provider.GlobalID,
                IncludePartnerMerchantIDs       = true,
                PartnerMerchantAuthorizationIDs = partnerMerchantAuthorizationIDs,
                PartnerMerchantSettlementIDs    = partnerMerchantSettlementIDs
            };

            // Place objects in the Context.
            Context[Key.Merchant] = merchant;

            // Add the merchant.
            Assert.AreEqual(ResultCode.Created, AddOrUpdateMerchant());

            // Retrieve the merchant object without the partner merchant info.
            Context[Key.Merchant]                = null;
            Context[Key.GlobalMerchantID]        = merchant.GlobalID;
            Context[Key.IncludePartnerMerchants] = false;
            Merchant retrievedMerchant = RetrieveMerchant();

            // Compare top-level merchant info.
            Assert.AreEqual(merchant.Id, retrievedMerchant.Id);
            Assert.AreEqual(merchant.GlobalID, retrievedMerchant.GlobalID);
            Assert.AreEqual(merchant.Name, retrievedMerchant.Name);

            // Ensure partner merchant info list is in the expected state.
            Assert.IsFalse(retrievedMerchant.IncludePartnerMerchantIDs);
            Assert.IsNotNull(retrievedMerchant.PartnerMerchantAuthorizationIDs);
            Assert.AreEqual(0, retrievedMerchant.PartnerMerchantAuthorizationIDs.Count());

            // Retrieve the merchant object with partner merchant info.
            Context[Key.IncludePartnerMerchants] = true;
            retrievedMerchant = RetrieveMerchant();

            // Compare top-level merchant info.
            Assert.AreEqual(merchant.Id, retrievedMerchant.Id);
            Assert.AreEqual(merchant.GlobalID, retrievedMerchant.GlobalID);
            Assert.AreEqual(merchant.Name, retrievedMerchant.Name);

            // Compare partner merchant info list.
            Assert.IsTrue(retrievedMerchant.IncludePartnerMerchantIDs);
            IEnumerable <PartnerMerchantAuthorizationID> retrievedPartnerMerchantAuthorizationIDs = retrievedMerchant.PartnerMerchantAuthorizationIDs;

            Assert.IsNotNull(retrievedPartnerMerchantAuthorizationIDs);
            Assert.AreEqual(partnerMerchantAuthorizationIDs.Count, retrievedPartnerMerchantAuthorizationIDs.Count());
            IEnumerable <PartnerMerchantSettlementID> retrievedPartnerMerchantSettlementIDs = retrievedMerchant.PartnerMerchantSettlementIDs;

            Assert.IsNotNull(retrievedPartnerMerchantSettlementIDs);
            Assert.AreEqual(partnerMerchantSettlementIDs.Count, retrievedPartnerMerchantSettlementIDs.Count());

            // Compare the first partner merchant authorization ID object.
            PartnerMerchantAuthorizationID initialPartnerMerchantAuthorizationID   = partnerMerchantAuthorizationIDs[0];
            PartnerMerchantAuthorizationID retrievedPartnerMerchantAuthorizationID = retrievedPartnerMerchantAuthorizationIDs.ElementAt(0);

            Assert.AreEqual(initialPartnerMerchantAuthorizationID.Partner, retrievedPartnerMerchantAuthorizationID.Partner);
            Assert.AreEqual(initialPartnerMerchantAuthorizationID.AuthorizationID, retrievedPartnerMerchantAuthorizationID.AuthorizationID);

            // Compare the second partner merchant authorization ID object.
            initialPartnerMerchantAuthorizationID   = partnerMerchantAuthorizationIDs[1];
            retrievedPartnerMerchantAuthorizationID = retrievedPartnerMerchantAuthorizationIDs.ElementAt(1);
            Assert.AreEqual(initialPartnerMerchantAuthorizationID.Partner, retrievedPartnerMerchantAuthorizationID.Partner);
            Assert.AreEqual(initialPartnerMerchantAuthorizationID.AuthorizationID, retrievedPartnerMerchantAuthorizationID.AuthorizationID);

            // Compare the first partner merchant settlement ID object.
            PartnerMerchantSettlementID initialPartnerMerchantSettlementID   = partnerMerchantSettlementIDs[0];
            PartnerMerchantSettlementID retrievedPartnerMerchantSettlementID = retrievedPartnerMerchantSettlementIDs.ElementAt(0);

            Assert.AreEqual(initialPartnerMerchantSettlementID.Partner, retrievedPartnerMerchantSettlementID.Partner);
            Assert.AreEqual(initialPartnerMerchantSettlementID.SettlementID, retrievedPartnerMerchantSettlementID.SettlementID);

            // Compare the second partner merchant authorization ID object.
            initialPartnerMerchantSettlementID   = partnerMerchantSettlementIDs[1];
            retrievedPartnerMerchantSettlementID = retrievedPartnerMerchantSettlementIDs.ElementAt(1);
            Assert.AreEqual(initialPartnerMerchantSettlementID.Partner, retrievedPartnerMerchantSettlementID.Partner);
            Assert.AreEqual(initialPartnerMerchantSettlementID.SettlementID, retrievedPartnerMerchantSettlementID.SettlementID);

            // Finally test an invalid global merchant ID.
            Context[Key.GlobalMerchantID] = "invalid";
            Assert.IsNull(RetrieveMerchant());
        }
Example #4
0
        public void AddOrUpdateMerchantTest()
        {
            // Create a provider.
            Provider provider = new Provider()
            {
                GlobalID = "ProviderID1",
                Name     = "Provider1"
            };

            // Place objects in the Context.
            Context = new CommerceContext(String.Empty);
            Context[Key.Provider] = provider;

            // Add the provider.
            ProviderOperations providerOperations = new ProviderOperations();

            providerOperations.Context = Context;
            Assert.AreEqual(ResultCode.Created, providerOperations.AddOrUpdateProvider());

            // Create a merchant with populated partner merchant records.
            List <PartnerMerchantAuthorizationID> partnerMerchantAuthorizationIDs = new List <PartnerMerchantAuthorizationID>();
            PartnerMerchantAuthorizationID        visaAuthorizationID             = new PartnerMerchantAuthorizationID
            {
                Partner         = CardBrand.Visa,
                AuthorizationID = "VisaMerchant1AuthAndSettlementID1"
            };

            partnerMerchantAuthorizationIDs.Add(visaAuthorizationID);

            PartnerMerchantAuthorizationID masterCardAuthorizationID = new PartnerMerchantAuthorizationID
            {
                Partner         = CardBrand.MasterCard,
                AuthorizationID = "MasterCardMerchant1AuthID1"
            };

            partnerMerchantAuthorizationIDs.Add(masterCardAuthorizationID);

            List <PartnerMerchantSettlementID> partnerMerchantSettlementIDs = new List <PartnerMerchantSettlementID>();
            PartnerMerchantSettlementID        visaSettlementID             = new PartnerMerchantSettlementID
            {
                Partner      = CardBrand.Visa,
                SettlementID = "VisaMerchant1AuthAndSettlementID1"
            };

            partnerMerchantSettlementIDs.Add(visaSettlementID);

            PartnerMerchantSettlementID masterCardSettlementID = new PartnerMerchantSettlementID
            {
                Partner      = CardBrand.MasterCard,
                SettlementID = "MasterCardMerchant1SettlementID1"
            };

            partnerMerchantSettlementIDs.Add(masterCardSettlementID);

            Merchant merchant = new Merchant()
            {
                GlobalID                        = "MerchantID1",
                Name                            = "Merchant1",
                GlobalProviderID                = provider.GlobalID,
                IncludePartnerMerchantIDs       = true,
                PartnerMerchantAuthorizationIDs = partnerMerchantAuthorizationIDs,
                PartnerMerchantSettlementIDs    = partnerMerchantSettlementIDs
            };

            // Place objects in the Context.
            Context[Key.Merchant] = merchant;

            // Add the merchant.
            Assert.AreEqual(ResultCode.Created, AddOrUpdateMerchant());

            // Update the merchant (deactivate a PartnerMerchantAuthorizationID record).
            partnerMerchantAuthorizationIDs.Remove(visaAuthorizationID);
            Assert.AreEqual(ResultCode.Success, AddOrUpdateMerchant());

            // Update the merchant (deactivate a PartnerMerchantSettlementID record).
            partnerMerchantSettlementIDs.Remove(masterCardSettlementID);
            Assert.AreEqual(ResultCode.Success, AddOrUpdateMerchant());

            // Update the merchant (reactivate a PartnerMerchantAuthorizationID record).
            partnerMerchantAuthorizationIDs.Add(visaAuthorizationID);
            Assert.AreEqual(ResultCode.Success, AddOrUpdateMerchant());

            // Update the merchant (reactivate a PartnerMerchantSettlementID record).
            partnerMerchantSettlementIDs.Add(masterCardSettlementID);
            Assert.AreEqual(ResultCode.Success, AddOrUpdateMerchant());

            // Invalid global provider ID.
            merchant.GlobalProviderID = "invalid";
            Assert.AreEqual(ResultCode.InvalidMerchant, AddOrUpdateMerchant());
            merchant.GlobalProviderID = provider.GlobalID;

            // Without PartnerMerchants flagged not populated.
            bool correctExceptionThrown = false;

            merchant.IncludePartnerMerchantIDs = false;
            try
            {
                AddOrUpdateMerchant();
            }
            catch (ArgumentException)
            {
                correctExceptionThrown = true;
            }
            finally
            {
                Context[Key.Merchant] = null;
            }
            Assert.IsTrue(correctExceptionThrown);
        }