Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1554 CaYC Replace Moq with NSubstitute #5774

Merged
merged 5 commits into from
Oct 28, 2024

Conversation

vnaskos-sonar
Copy link
Contributor

@vnaskos-sonar vnaskos-sonar commented Oct 25, 2024

SLVS-1554

Part of SLVS-1183

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title CaYC Replace Moq with NSubstitute SLVS-1554 CaYC Replace Moq with NSubstitute Oct 25, 2024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests look a lot cleaner! I like that I can read them from a glance (although we still have a few that have around 20 lines of code, which is not ideal)

But the helper methods have a lot of optional and out parameters. I think we could improve that by introducing notifications for different cases as fields and then just mock them accordingly in each test (see other feedback)


private static INotification CreateNotification(string id = null, bool oncePerSession = true, params INotificationAction[] actions)
private IInfoBar ShowNotification(out INotification notification, string id = null, bool oncePerSession = true, bool disabled = false, params INotificationAction[] actions)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having an out parameter, please add the INotification as a field and use the field instead.
You can have multiple notification fields for different cases:

INotification oncePerSessionNotification
INotification multipleTimesPerSession
INotification notificationWithActions etc

Copy link
Contributor Author

@vnaskos-sonar vnaskos-sonar Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've introduced a new record AttachedNotification which hold the INotification and IInfoBar, I believe it helped a lot with readability. No more out var 😁

}

private static Mock<IInfoBarManager> CreateInfoBarManager(INotification notification, Mock<IInfoBar> infoBar)
private void AttachNotification(INotification notification, out IInfoBar infoBar)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for IInfoBar. Instead of using out parameter use a field. It simplifies the code a lot and makes it cleaner

Copy link

@vnaskos-sonar vnaskos-sonar merged commit bb4d5e6 into feature/hardening-8-7 Oct 28, 2024
3 checks passed
@vnaskos-sonar vnaskos-sonar deleted the vn/slvs-1183-cayc branch October 28, 2024 07:59
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