I have simple navigation service:
public class NavigationService(INavigation navigation) : INavigationService
{
public INavigation Navigation { get; } = navigation;
public void NavigateToControlPage()
{
var page = new ControlPage();
Navigation.PushAsync(page);
}
}
and the test:
[Fact]
public void NavigationToControlPageShouldPushAsyncPage()
{
// Arrange
var navigationMock = new Mock<INavigation>();
var sut = new Ns.NavigationService(navigationMock.Object);
// Act
sut.NavigateToControlPage();
// Assert
navigationMock.Verify(n => n.PushAsync(It.IsAny<ControlPage>()), Times.Once);
}
And this test failes because there is exception:
Microsoft.Maui.Controls.Xaml.XamlParseException : Position 9:11. StaticResource not found for key Grey1
I think the test try to create/open ControlPage
and the static resource doesn’t exist. I am wondering is my way of doing navigation via service good? Also, is my test good? General question how can I test my service? I want to test that method pushes to Navigation
my ControlPage
.