Repository navigation
Return named records from the order calculation services - #964
Merged
Merged
Conversation
IOrderCalculationService and IShoppingCartSubTotalService returned positional tuples of up to six fields. The field names were not part of the type, so two doubles could be swapped without a compile error, and every mock had to spell out the whole tuple type. Each method now returns a sealed positional record from Grand.Business.Core.Utilities.Checkout; deconstructing callers compile unchanged.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the architecture backlog (item S12: tuple results in the order calculation services)
Type: feature
Issue
IOrderCalculationServiceandIShoppingCartSubTotalServicereturned positional tuples:GetShoppingCartSubTotalfive fields,GetShoppingCartTotalsix,GetShoppingCartShippingTotalthree, andAdjustShippingRateandGetTaxTotaltwo each. The field names are not part of the type, so a caller could swap twodoubles and the compiler would not notice. The signatures were also hard to read and hard to mock: a test had to spell out the whole tuple type inTask.FromResult<(...)>.Solution
Grand.Business.Core.Utilities.Checkout, next toCalculationContext:ShoppingCartSubTotal(DiscountAmount, AppliedDiscounts, SubTotalWithoutDiscount, SubTotalWithDiscount, TaxRates), returned by both interfacesShippingRateAdjustment(ShippingRate, AppliedDiscounts)ShoppingCartShippingTotal(ShippingTotal, TaxRate, AppliedDiscounts)ShoppingCartTaxTotal(TaxTotal, TaxRates)ShoppingCartTotal(Total, DiscountAmount, AppliedDiscounts, AppliedGiftVouchers, RedeemedLoyaltyPoints, RedeemedLoyaltyPointsAmount)Deconstruct, so callers outside this repository that writevar (a, b, ...) = await ...still compile. Inside the repository every caller now reads the results by property, so no caller depends on field position any more. Callers that read tuple fields by name now use the properties (.subTotalWithDiscount→.SubTotalWithDiscount,.shoppingCartTotal→.Total,.shoppingCartShippingTotal→.ShippingTotal,.taxtotal→.TaxTotal).Breaking changes
IOrderCalculationService.GetShoppingCartSubTotal,AdjustShippingRate, bothGetShoppingCartShippingTotaloverloads,GetTaxTotalandGetShoppingCartTotal, and ofIShoppingCartSubTotalService.GetShoppingCartSubTotal, are now records instead of tuples.MissingMethodExceptionuntil it is recompiled, even if its source compiles unchanged. Third-party plugins must be rebuilt against this version.OrderCalculationService/ShoppingCartSubTotalService, or implements one of the interfaces, must change the return type and returnnew ShoppingCartTotal(...)(etc.) instead of a tuple literal.nullinstead of a default tuple.Testing
dotnet build GrandNode.slnx: the whole solution, plugins included, builds with no errors and no new warnings in the files this PR changes.dotnet test src/Tests/Grand.Business.Checkout.Tests(292),dotnet test src/Tests/Grand.Web.Tests(154),dotnet test src/Tests/Grand.Modules.Tests(397) all pass, with the same counts as before the change. The only test changes are the mocks that built a tuple, which now build the record, and the assertions that read tuple fields by name, which now read the properties. No assertion was removed or weakened.develop.