Mocking replaces an unavailable dependency with a controlled implementation, allowing UI development and testing to continue before the real functionality exists. section 8.1.1
Use a mock implementation to:
- Implement an interface with predictable results, such as returning a completed login task with true. section 8.1.1
- Build and run the app while the real service is unavailable. section 8.1.1
- Exercise UI behavior and support later unit testing, but not real authenticated API calls. section 8.1.1
Mocking an authentication service
Define IAuthService with LoginAsync returning Task<bool>. Implement MockAuthService, return Task.FromResult(true), store it in LoginPage, and await it when the login button is clicked. Disable the button and show progress while the call runs. section 8.1.1
Listing 8.4 MockAuthService
namespace MauiStockTake.UI.Services;
public class MockAuthService : IAuthService
{
public Task<bool> LoginAsync() => Task.FromResult(true);
}
Inspect the compact MockAuthService implementation that satisfies IAuthService without contacting a real authentication system. section 8.1.1




















