Beispiel #1
0
        public void DummyClassMethod_SeveralRequestAreNotRetrievedFromCacheInFirstAttempt()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public void DummyClassMethod_WitAttributes_CreateNonStaticMethodShouldFindAttribute()
        {
            DummyClass resource = new DummyClass();
            DummyClass result   = new DummyClass();
            Dictionary <string, string> config = new Dictionary <string, string>();

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

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

            Assert.Pass();
        }
Beispiel #4
0
        public void DummyClassMethod_SeveralRequestsMustBeCached()
        {
            SDK.CleanConfiguration();
            SDK.SetBaseUrl("https://httpbin.org");
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            string id1 = (new Random().Next(0, int.MaxValue) - 5).ToString();
            string id2 = (new Random().Next(0, int.MaxValue) - 88).ToString();
            string id3 = (new Random().Next(0, int.MaxValue) - 9).ToString();

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

            Thread.Sleep(1000);

            var firstCachedResult  = DummyClass.FindById(id1, true);
            var secondCachedResult = DummyClass.FindById(id2, true);
            var thirdCachedResult  = DummyClass.FindById(id3, true);

            Assert.IsTrue(firstCachedResult.GetLastApiResponse().IsFromCache);
            Assert.IsTrue(secondCachedResult.GetLastApiResponse().IsFromCache);
            Assert.IsTrue(thirdCachedResult.GetLastApiResponse().IsFromCache);
        }
Beispiel #5
0
        public void IdempotentKey_MustBePresent()
        {
            DummyClass dummy = new DummyClass("Dummy description", DateTime.Now, 1000);

            Assert.IsNotEmpty(dummy.GetType().GUID.ToString());
        }