Skip to content

Commit

Permalink
SLVS-1498 Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Jan 9, 2025
1 parent acde5c9 commit 3219aae
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,24 @@ public async Task CheckServerTrustedAsync_CertificateIsValid_DoesNotShowNotifica

private static string BuildUri(string scheme, string host) => $"{scheme}://{host}";

private static bool IsExpectedNotification(INotification x) =>
x.Id == HttpConfigurationListener.ServerCertificateInvalidNotificationId
&& x.Message == SLCoreStrings.ServerCertificateInfobar_CertificateInvalidMessage
&& HasExpectedActions(x);
private bool IsExpectedNotification(INotification x)
{
VerifyNotificationHasExpectedActions(x);

return x.Id == HttpConfigurationListener.ServerCertificateInvalidNotificationId && x.Message == SLCoreStrings.ServerCertificateInfobar_CertificateInvalidMessage;
}

private static bool HasExpectedActions(INotification notification) =>
notification.Actions.Count() == 2
&& notification.Actions.Any(x => x.CommandText == SLCoreStrings.ServerCertificateInfobar_LearnMore)
&& notification.Actions.Any(x => x.CommandText == SLCoreStrings.ServerCertificateInfobar_ShowLogs);
private void VerifyNotificationHasExpectedActions(INotification notification)
{
notification.Actions.Should().HaveCount(2);
notification.Actions.Should().Contain(x => IsExpectedAction(x, SLCoreStrings.ServerCertificateInfobar_LearnMore));
notification.Actions.Should().Contain(x => IsExpectedAction(x, SLCoreStrings.ServerCertificateInfobar_ShowLogs));

notification.Actions.First().Action.Invoke(null);
notification.Actions.Last().Action.Invoke(null);
browserService.Received(1).Navigate(DocumentationLinks.SslCertificate);
outputWindowService.Received(1).Show();
}

private static bool IsExpectedAction(INotificationAction notificationAction, string expectedText) => notificationAction.CommandText == expectedText && !notificationAction.ShouldDismissAfterAction;
}

0 comments on commit 3219aae

Please sign in to comment.