-
Notifications
You must be signed in to change notification settings - Fork 6
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
Migrate to ASP.NET Core 6.0 #720
Conversation
537da18
to
fdc08fd
Compare
…ysis.NetAnalyzers
e1fe670
to
04acfaa
Compare
SonarCloud Quality Gate failed. |
@@ -11,7 +11,7 @@ namespace OutOfSchool.Tests.Common.TestDataGenerators | |||
public static class AddressGenerator | |||
{ | |||
private static readonly Faker<Address> faker = new Faker<Address>() | |||
.RuleFor(x => x.Id, f => f.IndexFaker) | |||
.RuleFor(x => x.Id, f => f.IndexFaker++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the IndexFaker is used to generate Address.Id it causes an exception System.InvalidOperationException : The instance of entity type 'Address' cannot be tracked because another instance with the key value '{Id: 1}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
I saw a workaround to avoid this exception here
Line 43 in c906c60
fakeProvider.ActualAddress.Id = 5; |
Using
f.IndexFaker++
solves this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not really good idea to change the generator trying to fix the problem with data.
Seems it was used in a wrong way.
It is better to find the reason why collection already contains the address with id 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because IndexFaker has an initial value of 0. When entity with Id=0 is added to the DB context, EF implicitly changes Id value to 1. When the second entity with Id=1 is generated and added to the DB context it causes the exception. I think that for the testing purposes that fix is sufficient enough. At the same time I agree that better solution can be found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Steps to test: