unoplatform / uno.extensions

Libraries to ease common developer tasks associated with building multi-platform mobile, desktop and web applications using Uno Platform or WinAppSDK.
https://platform.uno/
Other
72 stars 46 forks source link

[Hosting][Documentation] Overview should have instructions on overriding services in UITests #1498

Open Youssef1313 opened 1 year ago

Youssef1313 commented 1 year ago

Scenario:

The app uses an implementation of a specific service that connects to a server. The developer wants to create a mock implementation for that service for purpose of service.

Youssef1313 commented 1 year ago

@nickrandolph I'm not sure if this is actually possible today. So, if not possible, consider this as a feature request rather than documentation request.

nickrandolph commented 1 year ago

This is already possible. If you look at the ToDo sample, it has mock services for use during Dev/test.

nickrandolph commented 1 year ago

Cc @lukeblevins can we add this to the docs

Youssef1313 commented 1 year ago

This is already possible. If you look at the ToDo sample, it has mock services for use during Dev/test.

I'm not able to find these mock services.

nickrandolph commented 1 year ago

This is already possible. If you look at the ToDo sample, it has mock services for use during Dev/test.

I'm not able to find these mock services.

Here's where one of them is registered: https://github.com/unoplatform/uno.todo/blob/824c6c4cb54b19f9ae98164d975fa2551ec3bc96/src/ToDo/ServiceCollectionExtensions.cs#L23

GitHub
uno.todo/src/ToDo/ServiceCollectionExtensions.cs at 824c6c4cb54b19f9ae98164d975fa2551ec3bc96 · unoplatform/uno.todo
Uno Platform "Uno To Do" reference app. Contribute to unoplatform/uno.todo development by creating an account on GitHub.
Youssef1313 commented 1 year ago

Oh I was looking in https://github.com/unoplatform/uno.extensions/tree/main/testing/TestHarness/TestHarness.Shared/Ext/Navigation/Apps/ToDo.

Though the current approach isn't too flexible. I'm looking for something more similar to https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0#inject-mock-services

xperiandri commented 2 months ago

With some reflection, I achieved a similar result. I have not tested this for Uno host but for the generic host it works. @Youssef1313 I can share the code but it is in F# Unfortunately MS had not opened the necessary APIs to call them directly