feat: Easy way to retrieve InteractiveRequestOptions#867
Conversation
|
Humor me for a second here. I still think we should consider adding a As for whether it should throw or not, I think it is fine if it does. If a user expects that a navigation history entry is deserializeable from JSON and its not, then its completely fine to it throw an exception and thus have the test fail. Test assertions also work by throwing exceptions when things are not as expected. The code would look something like this: var actualInteractiveRequestOptions = navigationManager.History.Last().FromJson<InteractiveRequestOptions>();If the The implementation could look something like this: public T? FromJson<T>(JsonSerializerOptions? options = null)
{
options = options ?? JsonSerializerDefaults.Web;
return JsonSerializer.Deserialize<T>(Options.HistoryEntryState, options);
} |
I guess I know what you mean. As far as I am concerned I even would like that API, but (as always there is a but :D) This bid
Right now the docu of the We can also put this back into the shelf and wait until users ask for help and depending on how they might expect an API, they get help. Or if you still think it would be viable to have the generic from the getgo, then I am more than happy to make that work. I just wanted to present my thoughts around that topic. EDIT: I also see the danger that if the Blazor teams introduces more stuff, we are stuck with this very API I am proposing right now. Do we then want to have specific helper methods for every JSON-related call? Personally I would still argue in favor of that but I see that it might not be the way you want to go. |
My plan was to have it on
The general design approach i'm trying to take with bUnit is to enable more generic low level APIs that make it easy to do things, instead of of adding a whole bunch of very specific APIs, even if those are more discoverable. The "fist party support" bUnit includes I like to expose through extension methods, since that is what 3rd parties will have to do, if they want to add support in bUnit for their stuff. Using the same approach for 1st party stuff allows us to eat our own dog food, as it were. Hope this makes sense. |
I do understand that part. Applying Also
Good input. But even that thing is bound to |
|
As far as I can see, we can make due with one generic If other types are stored as JSON in the NavigationOptions.State field, e.g. a custom type the user might be using in their own code, or something from a 3rd party lib, then they can reuse the same |
|
Added my suggestion here. I like the more generic approach. Did forget to update the docs though. |
Okay as I wrote you some days ago. I misunderstood what you meant with generic. |
|
I adopted some additional documentation as well (see last commit) |
|
Looks good to me. Added a few changes. If you like them, squash merge at will :) |
Pull request description
This PR relates and directly closes #859 .
It gives the user an easy way of retrieving the
InteractiveRequestOptionsfrom the NavigationHistoryEntry.PR meta checklist
mainbranch for codeor targeted at
stablebranch for documentation that is live on bunit.dev.Code PR specific checklist