Skip to content

Conversation

@gentledepp
Copy link
Contributor

Using the newly added static method and field, the test can be written like:


    /// <summary>
    /// Tests the navigation flow when user fails login first time but succeeds second time.
    /// </summary>
    [Test]
    public async Task NavigateToFirstViewAsync_WhenNotLoggedIn_SuccessfulLoginSecondTry()
    {
        // Arrange
        _sessionMock.Setup(x => x.IsLoggedIn).Returns(false);
        var failedLoginResult = NavigateResult.FromResult(new LoginResult("damn..."));
        var successLoginResult = NavigateResult.FromResult(new LoginResult(new ClaimsPrincipal()));

        _navigatorMock.SetupSequence(x => x.NavigateAndWaitAsync("/login", NavigateType.Modal, It.IsAny<CancellationToken>()))
                      .ReturnsAsync(failedLoginResult)
                      .ReturnsAsync(successLoginResult);

        // Act
        await _strategy.NavigateToFirstViewAsync();

        // Assert
        _navigatorMock.Verify(x => x.NavigateAsync("/splash", NavigateType.Normal, It.IsAny<CancellationToken>()), Times.Once);
        _navigatorMock.Verify(x => x.NavigateAndWaitAsync("/login", NavigateType.Modal, It.IsAny<CancellationToken>()), Times.Exactly(2));
        _navigatorMock.Verify(x => x.NavigateAsync("/main", NavigateType.ReplaceRoot, It.IsAny<CancellationToken>()), Times.Once);
    }


@gentledepp
Copy link
Contributor Author

@OmidID this is a minor but important change. Please consider ;-)

@OmidID OmidID merged commit 995752b into AvaloniaInside:develop Mar 8, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants