Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parser plugins during SubscriptionItemUpdatedPlugin item creation #1143

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Stripe.Tests.XUnit/subscriptions/_fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public subscription_fixture()
Items = new List<StripeSubscriptionItemUpdateOption>
{
new StripeSubscriptionItemUpdateOption { Id = Subscription.Items.Data[0].Id, Deleted = true },
new StripeSubscriptionItemUpdateOption { Id = Subscription.Items.Data[1].Id, Quantity = 5 }
new StripeSubscriptionItemUpdateOption
{
Id = Subscription.Items.Data[1].Id,
Quantity = 5,
Metadata = new Dictionary<string, string>{ {"key", "value"} }
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public void updated_has_right_quantity()
fixture.SubscriptionUpdated.Items.Data[0].Quantity.Should().Be(fixture.SubscriptionUpdateOptions.Items[1].Quantity);
}

[Fact]
public void updated_has_metadata_keys()
{
fixture.SubscriptionUpdated.Items.Data[0].Metadata.Should().ContainKeys(fixture.SubscriptionUpdateOptions.Items[1].Metadata.Keys);
}

[Fact]
public void updated_has_metadata_values()
{
fixture.SubscriptionUpdated.Items.Data[0].Metadata.Should().ContainValues(fixture.SubscriptionUpdateOptions.Items[1].Metadata.Values);
}

[Fact]
public void ended_should_not_be_null()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public bool Parse(ref string requestString, JsonPropertyAttribute attribute, Pro
// it must have a json attribute matching stripe's key, and only one
var attr = prop.GetCustomAttributes<JsonPropertyAttribute>().SingleOrDefault();
if (attr == null) continue;

RequestStringBuilder.ApplyParameterToRequestString(ref requestString,
$"items[{itemIndex}][{attr.PropertyName}]", value.ToString());
// a JsonPropertyAttribute is required to supply a property name to parser plugins.
var indexedItemAttribute = new JsonPropertyAttribute($"items[{itemIndex}][{attr.PropertyName}]");
RequestStringBuilder.ProcessPlugins(ref requestString, indexedItemAttribute, prop, value, propertyParent);
}

itemIndex++;
Expand Down