示例#1
0
        public void CustomerTestClass_Load_TimeoutFail()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://api.mercadopago.com");

            Dictionary <string, string> config = new Dictionary <string, string>();

            config.Add("clientSecret", Environment.GetEnvironmentVariable("CLIENT_SECRET"));
            config.Add("clientId", Environment.GetEnvironmentVariable("CLIENT_ID"));
            SDK.SetConfiguration(config);

            ResourceTestClass resource = new ResourceTestClass();
            ResourceTestClass result   = new ResourceTestClass();

            try
            {
                result = resource.Load("567");
            }
            catch (Exception ex)
            {
                Assert.Pass();
                return;
            }

            Assert.Fail();
        }
示例#2
0
        public void DummyClassMethod_Update_CheckUri()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            DummyClass resource = new DummyClass();

            resource.address = "Evergreen 123";
            resource.email   = "*****@*****.**";

            DummyClass result = new DummyClass();

            try
            {
                result = resource.Update();
            }
            catch
            {
                // should never get here
                Assert.Fail();
                return;
            }

            Assert.AreEqual("PUT", result.GetLastApiResponse().HttpMethod);
            Assert.AreEqual("https://httpbin.org/put?access_token=" + Environment.GetEnvironmentVariable("ACCESS_TOKEN"), result.GetLastApiResponse().Url);
        }
示例#3
0
        public void ResourceTestClass_Create_ProperTimeoutSuccess()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            ResourceTestClass resource = new ResourceTestClass();

            resource.CardNumber = "123456789";
            resource.Holder     = "Wayne";

            ResourceTestClass result = new ResourceTestClass();

            try
            {
                result = resource.Save();
            }
            catch
            {
                // should never get here
                Assert.Fail();
                return;
            }

            JObject       jsonResponse = result.GetJsonSource();
            List <JToken> lastName     = MPCoreUtils.FindTokens(jsonResponse, "CardNumber");

            Assert.AreEqual("123456789", lastName.First().ToString());

            List <JToken> year = MPCoreUtils.FindTokens(jsonResponse, "Holder");

            Assert.AreEqual("Wayne", year.First().ToString());
        }
示例#4
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // Make a Clean Test
     SDK.CleanConfiguration();
 }
        public void AppConfigInvalidConfigurationTests()
        {
            SDK.CleanConfiguration();

            Exception auxException = null;

            try
            {
                Configuration config = null;
                SDK.SetConfiguration(config);
            }
            catch (ArgumentException exception)
            {
                Assert.AreEqual("config parameter cannot be null", exception.Message, "Exception must have \"config parameter cannot be null\" message");
                auxException = exception;
            }
            Assert.IsInstanceOf <ArgumentException>(auxException, "Exception type must be \"ArgumentException\"");

            auxException = null;
            try
            {
                SDK.SetConfiguration(GetConfigurationByFileName("MPConf_invalid_App"));
            }
            catch (Exception exception)
            {
                auxException = exception;
            }
            Assert.IsNull(auxException, "Exception must be \"null\"");
            Assert.IsNull(SDK.ClientSecret, "Client Secret must be \"null\" at this point");
            Assert.IsNull(SDK.ClientId, "Client Id must be \"null\" at this point");
            Assert.IsNull(SDK.AccessToken, "Access Token must be \"null\" at this point");
            Assert.IsNull(SDK.AppId, "App Id must be \"null\" at this point");
        }
示例#6
0
        public void MPIPN_PaymentNotification_MustBeOk()
        {
            SDK.CleanConfiguration();
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            var payment =
                new Payment
            {
                TransactionAmount = 100m,
                Description       = "IPN Test",
                Token             = GenerateSingleUseCardToken(),
                PaymentMethodId   = "visa",
                ExternalReference = "1234",
                Installments      = 1,
                Payer             = new Payer
                {
                    Email = "*****@*****.**"
                }
            };

            payment.Save();

            Ipn.HandleNotification(Ipn.Payment, payment.Id.ToString(), onMerchantOrderReceived: null, onPaymentReceived: p =>
            {
                Assert.AreEqual(p.Id, payment.Id);
                Assert.AreEqual(p.Description, payment.Description);
                Assert.AreEqual(p.TransactionAmount, payment.TransactionAmount);
                Assert.AreEqual(p.ExternalReference, payment.ExternalReference);
                Assert.Pass();
            });

            Assert.Fail();
        }
        public void MPIPN_ShouldBeOk()
        {
            SDK.CleanConfiguration();
            SDK.SetAccessToken(Environment.GetEnvironmentVariable("ACCESS_TOKEN"));

            Payment payment = new Payment();
            Payer   payer   = new Payer();

            payer.Email = "*****@*****.**";

            payment.TransactionAmount = (float)100;
            payment.Token             = GenerateSingleUseCardToken(); // 1 use card token
            payment.Description       = "Pago de seguro";
            payment.PaymentMethodId   = "visa";
            payment.Installments      = 1;
            payment.Payer             = payer;

            payment.Save();

            var resource = MPIPN.Manage <Payment>(MPIPN.Topic.payment, payment.Id.ToString());

            Assert.IsTrue(resource.GetType().IsSubclassOf(typeof(MPBase)));
            Assert.AreEqual(payment.Id, ((Payment)resource).Id);
            Assert.AreEqual(payment.Description, ((Payment)resource).Description);
            Assert.AreEqual(payment.PaymentMethodId, ((Payment)resource).PaymentMethodId);
        }
示例#8
0
        public void DummyClassMethod_Update_CheckUri()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            var accessToken = Guid.NewGuid().ToString();

            SDK.AccessToken = accessToken;

            DummyClass resource = new DummyClass();

            resource.address = "Evergreen 123";
            resource.email   = "*****@*****.**";

            DummyClass result = new DummyClass();

            try
            {
                result = resource.Update();
            }
            catch
            {
                // should never get here
                Assert.Fail();
                return;
            }

            Assert.AreEqual("PUT", result.GetLastApiResponse().HttpMethod);
            Assert.AreEqual("https://httpbin.org/put?access_token=" + accessToken, result.GetLastApiResponse().Url);
        }
示例#9
0
        public void MerchantOrder_UpdateShouldBeOk()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://api.mercadopago.com");

            Dictionary <string, string> config = new Dictionary <string, string>();

            config.Add("clientSecret", Environment.GetEnvironmentVariable("CLIENT_SECRET"));
            config.Add("clientId", Environment.GetEnvironmentVariable("CLIENT_ID"));
            SDK.SetConfiguration(config);

            MerchantOrder merchantOrderInternal = new MerchantOrder()
            {
                ID = "1"
            };

            try
            {
                var result = merchantOrderInternal.Update();
            }
            catch (MPException mpException)
            {
                Assert.Fail();
            }

            Assert.Pass();
        }
示例#10
0
        public void DummyClassMethod_Create_CheckUri()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            DummyClass resource = new DummyClass();

            resource.address = "Evergreen 123";
            resource.email   = "*****@*****.**";

            DummyClass result = new DummyClass();

            try
            {
                result = resource.Save();
            }
            catch
            {
                Assert.Fail();
                return;
            }

            Assert.AreEqual("POST", result.GetLastApiResponse().HttpMethod);

            Assert.AreEqual(string.Format("https://httpbin.org/post?access_token={0}", Environment.GetEnvironmentVariable("ACCESS_TOKEN")), result.GetLastApiResponse().Url);
        }
示例#11
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     SDK.CleanConfiguration();
     SDK.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID");
     SDK.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
 }
示例#12
0
        public void MPIPN_MustNotGetMerchantOrderById_OnNullMerchantOrderHandler()
        {
            SDK.CleanConfiguration();
            var merchantOrderId = "xxxx";

            Ipn.HandleNotification(Ipn.MerchantOrder, merchantOrderId, onPaymentReceived: x => { }, onMerchantOrderReceived: null);
            // No API Call is performed, therefore test passes
        }
示例#13
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     SDK.CleanConfiguration();
     SDK.SetBaseUrl("https://api.mercadopago.com");
     AccessToken     = Environment.GetEnvironmentVariable("ACCESS_TOKEN");
     SDK.AccessToken = AccessToken;
 }
示例#14
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072;
     // HardCoding Credentials
     SDK.CleanConfiguration();
     SDK.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID");
     SDK.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
 }
        public void AppConfigValidConfigurationTests()
        {
            SDK.CleanConfiguration();

            SDK.SetConfiguration(GetConfigurationByFileName("MPConf_valid_App.config"));
            Assert.AreEqual("CLIENT_SECRET", SDK.ClientSecret, "Client Secret must be \"CLIENT_SECRET\" at this point");
            Assert.AreEqual("CLIENT_ID", SDK.ClientId, "Client Id must be \"CLIENT_ID\" at this point");
            Assert.AreEqual("ACCESS_TOKEN", SDK.AccessToken, "Access Token must be \"ACCESS_TOKEN\" at this point");
            Assert.AreEqual("APP_ID", SDK.AppId, "App Id must be \"APP_ID\" at this point");
        }
示例#16
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // Environment.GetEnvironmentVariable("ACCESS_TOKEN");
     SDK.CleanConfiguration();
     SDK.SetBaseUrl("https://api.mercadopago.com");
     SDK.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID");
     SDK.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
 }
示例#17
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // HardCoding Credentials
     AccessToken = Guid.NewGuid().ToString();
     // Make a Clean Test
     SDK.CleanConfiguration();
     SDK.SetBaseUrl("https://api.mercadopago.com");
     SDK.AccessToken = AccessToken;
 }
示例#18
0
 public void SetUp()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // Credentials
     AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");
     PublicKey   = Environment.GetEnvironmentVariable("PUBLIC_KEY");
     // Make a Clean Test
     SDK.CleanConfiguration();
     SDK.AccessToken = AccessToken;
 }
示例#19
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // HardCoding Credentials
     AccessToken = "TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963"; //Environment.GetEnvironmentVariable("ACCESS_TOKEN");
     PublicKey   = "TEST-90189146-5027-424e-a3fd-f55d376c98c9";                                        //Environment.GetEnvironmentVariable("PUBLIC_KEY");
     // Make a Clean Test
     SDK.CleanConfiguration();
     SDK.SetBaseUrl("https://api.mercadopago.com");
     SDK.AccessToken = AccessToken;
 }
示例#20
0
 public void Init()
 {
     // Avoid SSL Cert error
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     // HardCoding Credentials
     AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");
     PublicKey   = Environment.GetEnvironmentVariable("PUBLIC_KEY");
     // Make a Clean Test
     SDK.CleanConfiguration();
     SDK.SetBaseUrl("https://api.mercadopago.com");
     SDK.AccessToken = AccessToken;
 }
示例#21
0
 public void GetAccessToken_ShouldThrowException()
 {
     try
     {
         SDK.CleanConfiguration();
         MPCredentials.GetAccessToken();
     }
     catch (MPException mpException)
     {
         Assert.AreEqual("\"client_id\" and \"client_secret\" can not be \"null\" when getting the \"access_token\"", mpException.Message);
         return;
     }
 }
示例#22
0
        public void DummyClassMethod_RequestMustBeCachedButNotRetrievedFromCache()
        {
            SDK.CleanConfiguration();
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            string id = new Random().Next(0, int.MaxValue).ToString();

            SDK.SetBaseUrl("https://httpbin.org");

            var firstResult = DummyClass.FindById(id, true);

            Assert.IsFalse(firstResult.GetLastApiResponse().IsFromCache);
        }
示例#23
0
        //[Test()]
        public void DummyClassMethod_RequestMustBeRetrievedFromCache()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("http://requestbin.net/r/1dhut4j1");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            string id = new Random().Next(0, int.MaxValue).ToString();

            var firstResult = DummyClass.FindById(id, true);

            Thread.Sleep(1000);

            var cachedResult = DummyClass.FindById(id, true);

            Assert.IsTrue(cachedResult.GetLastApiResponse().IsFromCache);
        }
示例#24
0
        public void DummyClassMethod_RequestMustBeRetrievedFromCache()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Guid.NewGuid().ToString();

            string id = new Random().Next(0, int.MaxValue).ToString();

            var firstResult = DummyClass.FindById(id, true);

            Thread.Sleep(1000);

            var cachedResult = DummyClass.FindById(id, true);

            Assert.IsTrue(cachedResult.GetLastApiResponse().IsFromCache);
        }
示例#25
0
        public void DummyClassMethod_RequestMustBeRetrievedFromCacheButItsNotThere()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            string id1 = (new Random().Next(0, int.MaxValue) - 78).ToString();
            string id2 = (new Random().Next(0, int.MaxValue) - 3).ToString();

            var firstResult = DummyClass.FindById(id1, true);

            Thread.Sleep(1000);

            var notRetrievedFromCacheResult = DummyClass.FindById(id2, true);

            Assert.IsFalse(notRetrievedFromCacheResult.GetLastApiResponse().IsFromCache);
        }
        public void InvalidHashMapConfigurationTests()
        {
            SDK.CleanConfiguration();

            Dictionary <string, string> hashConfigurations = null;
            Exception auxException = null;

            try
            {
                SDK.SetConfiguration(hashConfigurations);
            }
            catch (ArgumentException exception)
            {
                Assert.AreEqual("Invalid configurationParams parameter", exception.Message,
                                "Exception must have \"Invalid configurationParams parameter\" message");
                auxException = exception;
            }
            Assert.IsInstanceOf <ArgumentException>(auxException, "Exception type must be \"ArgumentException\"");

            hashConfigurations = new Dictionary <string, string>();
            hashConfigurations.Add("clientSecret", null);
            auxException = null;
            try
            {
                SDK.SetConfiguration(hashConfigurations);
            }
            catch (Exception exception)
            {
                auxException = exception;
            }
            Assert.IsNull(auxException, "Exception must be \"null\"");

            hashConfigurations["clientSecret"] = "CLIENT_SECRET";
            hashConfigurations["clientId"]     = "";
            auxException = null;
            try
            {
                SDK.SetConfiguration(hashConfigurations);
            }
            catch (Exception exception)
            {
                auxException = exception;
            }
            Assert.IsNull(auxException, "Exception must be \"null\"");
            Assert.AreEqual("CLIENT_SECRET", SDK.ClientSecret, "Client Secret must be \"CLIENT_SECRET\" at this point");
        }
示例#27
0
        public void DummyClassMethod_SeveralRequestAreNotRetrievedFromCacheInFirstAttempt()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Guid.NewGuid().ToString();

            string id1 = (new Random().Next(0, int.MaxValue) - 15).ToString();
            string id2 = (new Random().Next(0, int.MaxValue) - 666).ToString();
            string id3 = (new Random().Next(0, int.MaxValue) - 71).ToString();

            var firstResult  = DummyClass.FindById(id1, true);
            var secondResult = DummyClass.FindById(id2, true);
            var thirdResult  = DummyClass.FindById(id3, true);

            Assert.IsFalse(firstResult.GetLastApiResponse().IsFromCache);
            Assert.IsFalse(secondResult.GetLastApiResponse().IsFromCache);
            Assert.IsFalse(thirdResult.GetLastApiResponse().IsFromCache);
        }
示例#28
0
        public void MPBase_ParsePath_ShouldReplaceParamInUrlWithValues()
        {
            SDK.CleanConfiguration();
            SDK.AccessToken = "as987ge9ev6s5df4g32z1xv54654";

            var dummy = new DummyClass
            {
                id            = 111,
                email         = "*****@*****.**",
                address       = "Evergreen 123",
                maritalStatus = "divorced",
                hasCreditCard = true
            };

            try
            {
                string processedPath = CreatePath("https://api.mercadopago.com/v1/getpath/slug/:id/pUnexist/:unexist", null, null);
            }
            catch (Exception ex)
            {
                Assert.AreEqual("No argument supplied/found for method path", ex.Message);
            }

            string processedPath0 = CreatePath("/v1/getpath/slug", null, null);

            Assert.AreEqual("https://api.mercadopago.com/v1/getpath/slug?access_token=as987ge9ev6s5df4g32z1xv54654", processedPath0);

            string processedPath1 = CreatePath($"/v1/putpath/slug/{dummy.id}/pEmail/{dummy.email}", null, null);

            Assert.AreEqual("https://api.mercadopago.com/v1/putpath/slug/111/pEmail/[email protected]?access_token=as987ge9ev6s5df4g32z1xv54654", processedPath1);

            string processedPath2 = CreatePath($"/v1/putpath/slug/{dummy.id}/pHasCreditCard/{dummy.hasCreditCard}", null, null);

            Assert.AreEqual("https://api.mercadopago.com/v1/putpath/slug/111/pHasCreditCard/True?access_token=as987ge9ev6s5df4g32z1xv54654", processedPath2);

            string processedPath3 = CreatePath($"/v1/putpath/slug/{dummy.id}/pEmail/{dummy.email}/pAddress/{dummy.address}", null, null);

            Assert.AreEqual("https://api.mercadopago.com/v1/putpath/slug/111/pEmail/[email protected]/pAddress/Evergreen 123?access_token=as987ge9ev6s5df4g32z1xv54654", processedPath3);

            string processedPath4 = CreatePath($"/v1/putpath/slug/{dummy.id}/pEmail/{dummy.email}/pAddress/{dummy.address}/pMaritalstatus/{dummy.maritalStatus}/pHasCreditCard/{dummy.hasCreditCard}", null, null);

            Assert.AreEqual("https://api.mercadopago.com/v1/putpath/slug/111/pEmail/[email protected]/pAddress/Evergreen 123/pMaritalstatus/divorced/pHasCreditCard/True?access_token=as987ge9ev6s5df4g32z1xv54654", processedPath4);
        }
示例#29
0
        public void CustomerTestClass_Load_TimeoutFail()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            ResourceTestClass resource = new ResourceTestClass();
            ResourceTestClass result   = new ResourceTestClass();

            try
            {
                result = resource.Load("567");
            }
            catch (Exception)
            {
                Assert.Pass();
                return;
            }

            Assert.Fail();
        }
        public static void Initialize(bool useAccessToken, bool useClientCredentials)
        {
            // Avoid SSL Cert error
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072;

            // Make a Clean Test
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://api.mercadopago.com");

            if (useAccessToken)
            {
                SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");
            }

            if (useClientCredentials)
            {
                SDK.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID");
                SDK.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
            }
        }