-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of null values with AnyOf (#1661)
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/StripeTests/Services/Charges/ChargeCreateOptionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace StripeTests | ||
{ | ||
using System; | ||
using Stripe; | ||
using Stripe.Infrastructure.FormEncoding; | ||
using Xunit; | ||
|
||
public class ChargeCreateOptionsTest : BaseStripeTest | ||
{ | ||
[Fact] | ||
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters