-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-28610]Resolve the Failing InvoiceExtensionsTests #6622
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| ๏ปฟusing Bit.Core.Billing.Extensions; | ||
| ๏ปฟusing System.Globalization; | ||
| using Bit.Core.Billing.Extensions; | ||
| using Stripe; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -356,9 +357,18 @@ public void FormatForProvider_ZeroInvoiceLevelTax_DoesNotAddTax() | |
| [Fact] | ||
| public void FormatForProvider_ComplexScenario_HandlesAllLineTypes() | ||
| { | ||
| // Arrange | ||
| var lineItems = new StripeList<InvoiceLineItem>(); | ||
| lineItems.Data = new List<InvoiceLineItem> | ||
| // Set culture to en-US to ensure consistent decimal formatting in tests | ||
| // This ensures tests pass on all machines regardless of system locale | ||
| var originalCulture = Thread.CurrentThread.CurrentCulture; | ||
| var originalUICulture = Thread.CurrentThread.CurrentUICulture; | ||
| try | ||
| { | ||
| Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); | ||
| Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); | ||
|
|
||
| // Arrange | ||
| var lineItems = new StripeList<InvoiceLineItem>(); | ||
| lineItems.Data = new List<InvoiceLineItem> | ||
| { | ||
| new InvoiceLineItem | ||
| { | ||
|
|
@@ -372,23 +382,29 @@ public void FormatForProvider_ComplexScenario_HandlesAllLineTypes() | |
| new InvoiceLineItem { Description = "Custom Service", Quantity = 2, Amount = 2000 } | ||
| }; | ||
|
|
||
| var invoice = new Invoice | ||
| var invoice = new Invoice | ||
| { | ||
| Lines = lineItems, | ||
| TotalTaxes = [new InvoiceTotalTax { Amount = 200 }] // Additional $2.00 tax | ||
| }; | ||
| var subscription = new Subscription(); | ||
|
|
||
| // Act | ||
| var result = invoice.FormatForProvider(subscription); | ||
|
|
||
| // Assert | ||
| Assert.Equal(5, result.Count); | ||
| Assert.Equal("5 ร Manage service provider (at $6.00 / month)", result[0]); | ||
| Assert.Equal("10 ร Manage service provider (at $4.00 / month)", result[1]); | ||
| Assert.Equal("1 ร Tax (at $8.00 / month)", result[2]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ญ This assertion now expects Can you confirm this change represents correct business logic? Was the original
This is important to verify we're fixing the test correctly, not just making it pass. |
||
| Assert.Equal("Custom Service", result[3]); | ||
| Assert.Equal("1 ร Tax (at $2.00 / month)", result[4]); | ||
| } | ||
| finally | ||
| { | ||
| Lines = lineItems, | ||
| TotalTaxes = [new InvoiceTotalTax { Amount = 200 }] // Additional $2.00 tax | ||
| }; | ||
| var subscription = new Subscription(); | ||
|
|
||
| // Act | ||
| var result = invoice.FormatForProvider(subscription); | ||
|
|
||
| // Assert | ||
| Assert.Equal(5, result.Count); | ||
| Assert.Equal("5 ร Manage service provider (at $6.00 / month)", result[0]); | ||
| Assert.Equal("10 ร Manage service provider (at $4.00 / month)", result[1]); | ||
| Assert.Equal("1 ร Tax (at $8.00 / month)", result[2]); | ||
| Assert.Equal("Custom Service", result[3]); | ||
| Assert.Equal("1 ร Tax (at $2.00 / month)", result[4]); | ||
| Thread.CurrentThread.CurrentCulture = originalCulture; | ||
| Thread.CurrentThread.CurrentUICulture = originalUICulture; | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐จ Consider using
CultureInfo.InvariantCultureinstead ofnew CultureInfo("en-US")for unit tests. Invariant culture is specifically designed for culture-independent operations and makes the intent clearer - you want consistent formatting regardless of system locale, not specifically US formatting.