Exemplo n.º 1
0
        public void SerializeDecimalTiersProperly()
        {
            var options = new PlanCreateOptions
            {
                Tiers = new List <PlanTierOptions>
                {
                    new PlanTierOptions
                    {
                        UnitAmountDecimal = 0.003m,
                        FlatAmountDecimal = 0.12m,
                        UpTo = 10,
                    },
                    new PlanTierOptions
                    {
                        UnitAmountDecimal = 0.004m,
                        FlatAmountDecimal = 0.24m,
                        UpTo = PlanTierUpTo.Inf,
                    }
                },
            };

            Assert.Equal(
                "tiers[0][flat_amount_decimal]=0.12&tiers[0][unit_amount_decimal]=0.003&tiers[0][up_to]=10&" +
                "tiers[1][flat_amount_decimal]=0.24&tiers[1][unit_amount_decimal]=0.004&tiers[1][up_to]=inf",
                FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 2
0
        public void SerializeTrialEnd()
        {
            var testCases = new[]
            {
                new
                {
                    options = new CustomerCreateOptions
                    {
                        TrialEnd = DateTime.Parse("Fri, 13 Feb 2009 23:31:30Z"),
                    },
                    want = "trial_end=1234567890",
                },
                new
                {
                    options = new CustomerCreateOptions
                    {
                        TrialEnd = SubscriptionTrialEnd.Now,
                    },
                    want = "trial_end=now",
                },
            };

            foreach (var testCase in testCases)
            {
                Assert.Equal(testCase.want, FormEncoder.CreateQueryString(testCase.options));
            }
        }
Exemplo n.º 3
0
        public void SerializeItems()
        {
            var options = new SubscriptionCreateOptions
            {
                CustomerId = "cus_123",
                Items      = new List <SubscriptionItemOption>
                {
                    new SubscriptionItemOption
                    {
                        PlanId   = "plan_123",
                        Quantity = 2
                    },
                    new SubscriptionItemOption
                    {
                        PlanId   = "plan_124",
                        Quantity = 3
                    },
                },
            };

            Assert.Equal(
                "customer=cus_123&" +
                "items[0][plan]=plan_123&items[0][quantity]=2&" +
                "items[1][plan]=plan_124&items[1][quantity]=3",
                FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 4
0
        public void SerializeSubscriptionBillingCycleAnchor()
        {
            var testCases = new[]
            {
                new
                {
                    options = new UpcomingInvoiceOptions
                    {
                        SubscriptionBillingCycleAnchor = DateTime.Parse("Fri, 13 Feb 2009 23:31:30Z"),
                    },
                    want = "subscription_billing_cycle_anchor=1234567890",
                },
                new
                {
                    options = new UpcomingInvoiceOptions
                    {
                        SubscriptionBillingCycleAnchor = SubscriptionBillingCycleAnchor.Now,
                    },
                    want = "subscription_billing_cycle_anchor=now",
                },
                new
                {
                    options = new UpcomingInvoiceOptions
                    {
                        SubscriptionBillingCycleAnchor = SubscriptionBillingCycleAnchor.Unchanged,
                    },
                    want = "subscription_billing_cycle_anchor=unchanged",
                },
            };

            foreach (var testCase in testCases)
            {
                Assert.Equal(testCase.want, FormEncoder.CreateQueryString(testCase.options));
            }
        }
Exemplo n.º 5
0
        public void SerializeTrialEndNow()
        {
            var options = new SubscriptionCreateOptions
            {
                TrialEnd = SubscriptionTrialEnd.Now,
            };

            Assert.Equal("trial_end=now", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 6
0
        public void SerializeTrialEndDateTime()
        {
            var options = new SubscriptionCreateOptions
            {
                TrialEnd = DateTime.Parse("Fri, 13 Feb 2009 23:31:30Z"),
            };

            Assert.Equal("trial_end=1234567890", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 7
0
        public void EnumEncodeUnknownValue()
        {
            var options = new TestOptions
            {
                Enum = TestOptions.TestEnum.TestTwo,
            };

            Assert.Equal("enum=TestTwo", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 8
0
        public void SerializeObjectProperly()
        {
            var options_bool = new PaymentIntentConfirmOptions
            {
                OffSession = true,
            };

            Assert.Equal("off_session=True", FormEncoder.CreateQueryString(options_bool));
        }
Exemplo n.º 9
0
        public void EnumEncodeValidValue()
        {
            var options = new TestOptions
            {
                Enum = TestOptions.TestEnum.TestOne,
            };

            Assert.Contains("enum=test_one", FormEncoder.CreateQueryString(options));
        }
        public void SerializeDateTime()
        {
            var options = new ListOptionsWithCreated
            {
                Created = DateTime.Parse("Fri, 13 Feb 2009 23:31:30Z"),
            };

            Assert.Equal("created=1234567890", FormEncoder.CreateQueryString(options));
        }
        public void SerializeDateTimeNull()
        {
            var options = new ListOptionsWithCreated
            {
                Created = (DateTime?)null,
            };

            Assert.Equal(string.Empty, FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 12
0
        public void Serialize()
        {
            var options = new CouponCreateOptions
            {
                PercentOff = 25,
                Duration   = "forever",
            };

            Assert.Equal("percent_off=25&duration=forever", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 13
0
        public virtual Uri AuthorizeUrl(OAuthAuthorizeUrlOptions options, bool express = false)
        {
            string path = "/oauth/authorize";

            if (express)
            {
                path = "/express" + path;
            }

            options = this.SetupOAuthAuthorizeUrlOptions(options);

            return(new Uri(this.Client.ConnectBase + path + "?" +
                           FormEncoder.CreateQueryString(options)));
        }
        public void Serialize()
        {
            var options = new AccountCreateOptions
            {
                Individual = new PersonCreateOptions
                {
                    FirstName = "first name",
                    LastName  = "last name",
                },
            };

            Assert.Equal(
                "individual[first_name]=first+name&individual[last_name]=last+name",
                FormEncoder.CreateQueryString(options));
        }
        public void SerializeDateRangeOptions()
        {
            var options = new ListOptionsWithCreated
            {
                Created = new DateRangeOptions
                {
                    GreaterThanOrEqual = DateTime.Parse("Fri, 13 Feb 2009 23:31:30Z"),
                    LessThan           = DateTime.Parse("Sun, 1 May 2044 01:28:21Z"),
                },
            };

            Assert.Equal(
                "created[gte]=1234567890&created[lt]=2345678901",
                FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 16
0
        public void UrlEncodesKeysAndValues()
        {
            var options = new TestOptions
            {
                Dictionary = new Dictionary <string, object>
                {
                    { "#", "1 2 3" },
                    { "bar&baz", "+foo?" },
                },
                String = "[éàü]",
            };

            Assert.Equal(
                "dictionary[%23]=1+2+3&dictionary[bar%26baz]=%2Bfoo%3F&string=[%C3%A9%C3%A0%C3%BC]",
                FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 17
0
        private static Uri BuildUri(ICulqiClient client, HttpMethod method, string path, BaseOptions options, RequestOptions requestOptions)
        {
            var b = new StringBuilder();

            b.Append(requestOptions?.BaseUrl ?? client.ApiBase);
            b.Append(path);

            if ((method != HttpMethod.Post) && (options != null))
            {
                var queryString = FormEncoder.CreateQueryString(options);
                if (!string.IsNullOrEmpty(queryString))
                {
                    b.Append("?");
                    b.Append(queryString);
                }
            }

            return(new Uri(b.ToString()));
        }
Exemplo n.º 18
0
        public void IgnoresCulture()
        {
            var currentCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");

                var dec = 123.45m;
                Assert.Equal("123,45", dec.ToString(CultureInfo.CurrentCulture));

                var options = new TestOptions {
                    Decimal = dec
                };
                Assert.Equal("decimal=123.45", FormEncoder.CreateQueryString(options));
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
Exemplo n.º 19
0
        public void SerializeTiersProperly()
        {
            var options = new PlanCreateOptions
            {
                Tiers = new List <PlanTierOptions>
                {
                    new PlanTierOptions
                    {
                        UnitAmount = 1000,
                        UpTo       = 10,
                    },
                    new PlanTierOptions
                    {
                        UnitAmount = 2000,
                        UpTo       = PlanTierUpTo.Inf,
                    }
                },
            };

            Assert.Equal(
                "tiers[0][unit_amount]=1000&tiers[0][up_to]=10&" +
                "tiers[1][unit_amount]=2000&tiers[1][up_to]=inf",
                FormEncoder.CreateQueryString(options));
        }
        public void SerializeObjectProperly()
        {
            var options = new BankAccountListOptions();

            Assert.Equal("object=bank_account", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 21
0
        public void CreateQueryString()
        {
            var testCases = new[]
            {
                // No data
                new
                {
                    data = new TestOptions {
                    },
                    want = string.Empty
                },

                // AnyOf
                new
                {
                    data = new TestOptions
                    {
                        AnyOf = "foo",
                    },
                    want = "any_of=foo"
                },
                new
                {
                    data = new TestOptions
                    {
                        AnyOf = new Dictionary <string, string> {
                            { "foo", "bar" }
                        },
                    },
                    want = "any_of[foo]=bar"
                },
                new
                {
                    data = new TestOptions
                    {
                        AnyOf = null, // AnyOf itself is null
                    },
                    want = string.Empty
                },
                new
                {
                    data = new TestOptions
                    {
                        AnyOf = (string)null, // AnyOf is not null but AnyOf.Value is null
                    },
                    want = string.Empty
                },
                new
                {
                    data = new TestOptions
                    {
                        AnyOf = (Dictionary <string, string>)null, // same as above, AnyOf.Value is null
                    },
                    want = string.Empty
                },

                // Array
                new
                {
                    data = new TestOptions
                    {
                        Array = new[] { "1", "2", "3" },
                    },
                    want = "array[0]=1&array[1]=2&array[2]=3"
                },
                new
                {
                    data = new TestOptions
                    {
                        Array = new string[] { },
                    },
                    want = "array="
                },

                // Bool
                new
                {
                    data = new TestOptions
                    {
                        Bool = false,
                    },
                    want = "bool=False"
                },
                new
                {
                    data = new TestOptions
                    {
                        Bool = true,
                    },
                    want = "bool=True"
                },

                // DateRangeOptions
                new
                {
                    data = new TestOptions
                    {
                        DateRangeOptions = new DateRangeOptions
                        {
                            LessThan           = DateTime.Parse("Sat, 01 Jan 2000 05:00:00Z"),
                            GreaterThanOrEqual = DateTime.Parse("Sat, 01 Jan 2000 00:00:00Z"),
                        }
                    },
                    want = "date_filter[gte]=946684800&date_filter[lt]=946702800"
                },

                // DateTime
                new
                {
                    data = new TestOptions
                    {
                        DateTime = DateTime.Parse("Sat, 01 Jan 2000 00:00:00Z"),
                    },
                    want = "datetime=946684800"
                },

                // Decimal
                new
                {
                    data = new TestOptions
                    {
                        Decimal = 1.2345m,
                    },
                    want = "decimal=1.2345"
                },
                new
                {
                    data = new TestOptions
                    {
                        Decimal = 0.0m,
                    },
                    want = "decimal=0.0"
                },

                // Dictionary
                new
                {
                    data = new TestOptions
                    {
                        Dictionary = new Dictionary <string, object> {
                            { "foo", "bar" }
                        },
                    },
                    want = "dictionary[foo]=bar"
                },
                new
                {
                    data = new TestOptions
                    {
                        Dictionary = new Dictionary <string, object> {
                            { "empty", string.Empty }
                        },
                    },
                    want = "dictionary[empty]="
                },
                new
                {
                    data = new TestOptions
                    {
                        Dictionary = new Dictionary <string, object> {
                            { "null", null }
                        },
                    },
                    want = "dictionary[null]="
                },
                new
                {
                    data = new TestOptions
                    {
                        Dictionary = new Dictionary <string, object>
                        {
                            { "foo", new Dictionary <string, object> {
                                  { "bar", "baz" }
                              } },
                        },
                    },
                    want = "dictionary[foo][bar]=baz"
                },

                // Enum
                new
                {
                    data = new TestOptions
                    {
                        Enum = TestOptions.TestEnum.TestOne,
                    },
                    want = "enum=test_one"
                },
                new
                {
                    data = new TestOptions
                    {
                        Enum = TestOptions.TestEnum.TestTwo,
                    },
                    want = "enum=TestTwo"
                },

                // List
                new
                {
                    data = new TestOptions
                    {
                        List = new List <object> {
                            "foo", "bar"
                        },
                    },
                    want = "list[0]=foo&list[1]=bar"
                },
                new
                {
                    data = new TestOptions
                    {
                        List = new List <object> {
                            string.Empty, 0
                        },
                    },
                    want = "list[0]=&list[1]=0"
                },
                new
                {
                    data = new TestOptions
                    {
                        List = new List <object> {
                        },
                    },
                    want = "list="
                },
                new
                {
                    data = new TestOptions
                    {
                        List = new List <object>
                        {
                            new Dictionary <string, object> {
                                { "foo", "bar" }
                            },
                            new Dictionary <string, object> {
                                { "foo", "baz" }
                            },
                        },
                    },
                    want = "list[0][foo]=bar&list[1][foo]=baz"
                },

                // Long
                new
                {
                    data = new TestOptions
                    {
                        Long = 123,
                    },
                    want = "long=123"
                },
                new
                {
                    data = new TestOptions
                    {
                        Long = 0,
                    },
                    want = "long=0"
                },

                // String
                new
                {
                    data = new TestOptions
                    {
                        String = "foo",
                    },
                    want = "string=foo"
                },
                new
                {
                    data = new TestOptions
                    {
                        String = string.Empty,
                    },
                    want = "string="
                },
            };

            foreach (var testCase in testCases)
            {
                Assert.Equal(testCase.want, FormEncoder.CreateQueryString(testCase.data));
            }
        }
Exemplo n.º 22
0
        public void SerializeObjectProperly()
        {
            var options = new CardListOptions();

            Assert.Equal("object=card", FormEncoder.CreateQueryString(options));
        }
Exemplo n.º 23
0
        public void Serialize()
        {
            var testCases = new[]
            {
                // No data
                new
                {
                    data = new ChargeCreateOptions {
                    },
                    want = string.Empty,
                },

                // Source is a non-null, non-empty string
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = "tok_visa",
                    },
                    want = "source=tok_visa",
                },

                // Source is a non-null, empty string
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = string.Empty,
                    },
                    want = "source=",
                },

                // Source is a null string
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = (string)null,
                    },
                    want = string.Empty,
                },

                // Source is a non-null CardCreateNestedOptions
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = new CardCreateNestedOptions
                        {
                            Number   = "4242424242424242",
                            ExpMonth = 1,
                            ExpYear  = 2030,
                        },
                    },
                    want = "source[object]=card&source[exp_month]=1&source[exp_year]=2030&source[number]=4242424242424242",
                },

                // Source is a null CardCreateNestedOptions
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = (CardCreateNestedOptions)null,
                    },
                    want = string.Empty,
                },

                // Source is null
                new
                {
                    data = new ChargeCreateOptions
                    {
                        Source = null,
                    },
                    want = string.Empty,
                },
            };

            foreach (var testCase in testCases)
            {
                Assert.Equal(testCase.want, FormEncoder.CreateQueryString(testCase.data));
            }
        }