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

chore: Replace Moq NuGet package with NSubstitute #370

Merged
merged 14 commits into from
Aug 14, 2023

Conversation

amirkaws
Copy link
Contributor

Issue number: #369

Summary

Removing the dependency to Moq library and replace it with NSubstitute Version="5.0.0"

Changes

All dependencies to Moq package are removed across all test projects Including all utilities as well as example test projects.

User experience

This won't change any use experience as only test projects are updated.

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@github-actions github-actions bot added the internal Maintenance changes label Aug 10, 2023
@codecov-commenter
Copy link

Codecov Report

Patch and project coverage have no change.

Comparison is base (ee1f06f) 69.52% compared to head (c0b8ec7) 69.52%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #370   +/-   ##
========================================
  Coverage    69.52%   69.52%           
========================================
  Files           79       79           
  Lines         3491     3491           
========================================
  Hits          2427     2427           
  Misses        1064     1064           
Flag Coverage Δ
unittests 69.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 10, 2023
@amirkaws amirkaws added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 10, 2023
@auto-assign auto-assign bot requested review from hjgraca and sliedig August 10, 2023 18:41
Copy link
Contributor

@sliedig sliedig left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@hjgraca hjgraca left a comment

Choose a reason for hiding this comment

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

Just some comments


await store.Received().SaveInProgress(
Arg.Is<JsonDocument>(t =>
t.ToString() == JsonSerializer.SerializeToDocument(product, new JsonSerializerOptions()).ToString()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of new JsonSerializerOptions() should be Arg.Any<JsonSerializerOptions>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use Arg.Any. It's fails both compilation and runtime
image

Copy link
Contributor

Choose a reason for hiding this comment

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

right if there is a Arg.Is present all args should be specified, in that case should be Arg.Is<JsonSerializerOptions>

.Received(1)
.SaveInProgress(
Arg.Is<JsonDocument>(t =>
t.ToString() == JsonSerializer.SerializeToDocument("fake", new JsonSerializerOptions())
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of new JsonSerializerOptions() should be Arg.Any<JsonSerializerOptions>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use Arg.Any. It's fails both compilation and runtime
image

var eventArgs = new AspectEventArgs
{
Name = methodName,
Args = new object [] { }
Args = Array.Empty<object>()
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

var provider = Substitute.For<IParameterProviderBaseHandler>();
provider.GetAsync<string>(
key,
Arg.Is<ParameterProviderConfiguration?>(x => x != null && x.MaxAge == duration),
Copy link
Contributor

Choose a reason for hiding this comment

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

It was Any implementation but now has a condition, why?

var provider = Substitute.For<IParameterProviderBaseHandler>();
provider.GetAsync<string>(
key,
Arg.Is<ParameterProviderConfiguration?>(x => x != null && x.ForceFetch),
Copy link
Contributor

Choose a reason for hiding this comment

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

All args were Any, now have conditions, why?

providerProxy.Verify(v => v.GetAsync(key, It.IsAny<ParameterProviderConfiguration?>()), Times.Once);
powertoolsConfigurations.Verify(v => v.SetExecutionEnvironment(providerHandler), Times.Once);
cacheManager.DidNotReceive().Get(key);
await providerProxy.Received(1).GetAsync(key, Arg.Is<ParameterProviderConfiguration?>(x => x!.ForceFetch));
Copy link
Contributor

Choose a reason for hiding this comment

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

All args were Any, now have conditions, why?

powertoolsConfigurations.Verify(v => v.SetExecutionEnvironment(providerHandler), Times.Once);
cacheManager.Received(1).Get(key);
await providerProxy.Received(1).GetMultipleAsync(key, Arg.Any<ParameterProviderConfiguration>());
cacheManager.Received(1).Set(key, Arg.Is<Dictionary<string, string?>>(x=>
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic is very different than the current implementation. value Dictiionary is passed with Guids

cacheManager.Verify(v => v.Set(key, value, duration), Times.Once);
powertoolsConfigurations.Verify(v => v.SetExecutionEnvironment(providerHandler), Times.Once);
await providerProxy.Received(1).GetMultipleAsync(key, config);
cacheManager.Received(1).Set(key, Arg.Is<Dictionary<string, string?>>(x=>
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic is very different than the current implementation. value Dictiionary is passed with Guids

).ReturnsAsync(value);
providerHandler.GetAsync<string>(
key,
Arg.Is<ParameterProviderConfiguration?>(x => x != null && !x.ForceFetch),
Copy link
Contributor

Choose a reason for hiding this comment

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

Args is any, why the change?

// Assert
Assert.Equivalent("Root",entity.Name);
Assert.Equal("Root", entity.Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this change is ok, the types are both strings.

@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 14, 2023
@sonarcloud
Copy link

sonarcloud bot commented Aug 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@hjgraca hjgraca merged commit 38e24f4 into aws-powertools:develop Aug 14, 2023
7 checks passed
@amirkaws amirkaws deleted the replace-moq-with-nsubstitute branch August 22, 2023 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Maintenance changes size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants