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

New Extension for Portugal #164

Merged
merged 4 commits into from
Jul 18, 2018
Merged

New Extension for Portugal #164

merged 4 commits into from
Jul 18, 2018

Conversation

jpassarellijr
Copy link
Contributor

Generate random Tax identification number (NIF and NIPC) for Portugal. Added Facts in the ExtensionTest.

Copy link
Owner

@bchavez bchavez left a comment

Choose a reason for hiding this comment

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

Hi @jpassarellijr, thank you very much for this pull request. 🇵🇹 It looks like a great addition! Good job! 👍 I look forward to merging this.

However, I do have a few concerns, they are highlighted below. Let me know if you have any questions!

Thanks,
Brian

return p.context[Key] as string;
}

var id = new int[1] { NifIdentify[new Random().Next(0, NifIdentify.Length)] };
Copy link
Owner

@bchavez bchavez Jul 18, 2018

Choose a reason for hiding this comment

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

Could you change new Random().Next(... call here? Preferably, it would be p.Random.Number(0, length - 1) or p.Random.Int(0, length - 1). Generally, the source of all randomness needs to come from an existing Bogus Randomizer managed by Bogus to ensure some level of sanity when it comes to providing deterministic behavior. #100 and #101 more details if you're intrested.

When we create new Random objects like this, we break the deterministic behavior for users especially when there is no seed for new Random(). Ultimately, we need to avoid using new Random() objects in Bogus and stick to using an existing Randomizer.

Hope this makes sense.

/// <param name="c">Object will receive the NIPC value</param>
public static string Nipc(this Company c)
{
var id = new int[1] { NipcIdentify[new Random().Next(0, NipcIdentify.Length)] };
Copy link
Owner

Choose a reason for hiding this comment

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

Line here too should change: new Random().Next( with c.Random.Int(0, length-1) or c.Random.Number(0, length-1). See previous comment. 👍

@jpassarellijr
Copy link
Contributor Author

First, thank you for acknowledgement, i´m so glad!
And about the concerns, sorry! My mistake, forgot change this.
Wrote the concept but forgot change for use Randomizer component.
I´m changed now :)

Some name refactoring in the API extension.
Bug fix out of bounds array length - 1.
Use Random.ArrayElement utility helper.
Updated README extensions docs.
@bchavez bchavez merged commit 77ec1e7 into bchavez:master Jul 18, 2018
@bchavez
Copy link
Owner

bchavez commented Jul 18, 2018

Congrats on your first pull request @jpassarellijr ! 👍 😎

Your changes are now live in Bogus v22.3.2 🎉

Thanks again for your help!
Brian

🚶 😎 "So don't delay... act now supplies are running out..."

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