Comments (2)
Hi @mdmoura ,
First, the code you've posted in the issue doesn't compile. Please submit something that can compile on my end otherwise, it's very hard to figure out what's going on with your code.
Also, not sure how you're getting duplicates because the following unit test passes:
[Test]
public void issue_66_unique_global_values()
{
var productsI18N = new Faker<FoodI18N>()
.RuleFor(x => x.Name, y => $"{y.Lorem.Word()} {y.Hashids.Encode(y.IndexGlobal)}");
List<Product> products = new Faker<Product>()
.RuleFor(x => x.ProductsI18N, () => productsI18N.Generate(2).Cast<ProductI18N>().ToList() )
.RuleFor(x => x.IsApproved, x => x.Random.Bool())
.Generate(2000).ToList();
products.SelectMany(p => p.ProductsI18N)
.Cast<FoodI18N>()
.Select(i8 => i8.Name).Distinct().Count().Should().Be(4000);
}
public class Product
{
public List<ProductI18N> ProductsI18N { get; set; }
public bool IsApproved { get; set; }
}
public class FoodI18N : ProductI18N
{
public string Name { get; set; }
}
public class ProductI18N
{
}
I would like to recommend to write a failing unit test in the test project here with what the expected result should be. It would greatly help me reproduce the issue you are seeing.
Thanks,
Brian
👨 🏁 "Louie Louie, oh no... Me gotta go... Aye-yi-yi-yi, I said"
from bogus.
@bchavez sorry that my code did not compile. I am posting new one:
public class Product {
public List<ProductI18N> ProductsI18N { get; set; }
public Boolean IsApproved { get; set; }
}
public class ProductI18N {
public String Name { get; set; }
public String LanguageCode { get; set; }
}
And to create the products:
var productsI18N = new Faker<ProductI18N>()
.RuleFor(x => x.LanguageCode, y => languages[y.IndexFaker % languages.Count])
.RuleFor(x => x.Name, y => $"{y.Lorem.Word().ToFirstLetterUppercase()} {y.Hashids.Encode(y.IndexGlobal)}");
List<Product> products = new Faker<Product>()
.RuleFor(x => x.ProductsI18N, () => productsI18N.Generate(languages.Count).Cast<ProductI18N>().ToList())
.RuleFor(x => x.IsApproved, x => x.Random.Bool())
.Generate(2000).ToList();
var count1 = products.SelectMany(x => x.ProductsI18N).Select(y => new { Name = y.Name, LanguageCode = y.LanguageCode }).Distinct().Count();
var count2 = products.SelectMany(x => x.ProductsI18N).Select(y => new { Name = y.Name.ToLower(), LanguageCode = y.LanguageCode }).Distinct().Count();
I figured out what is the problem. It is true that y.IndexGlobal
gives unique values but y.Hashids.Encode(y.IndexGlobal)
does not give unique values if you consider "abW" equals to "abw" which is what the database where I am inserting the values considers due to its collation ...
When inserting a lot of products these collisions start to occur ... So again, would be nice to in the future integrate a way to set plugins default values. In case of HashIds would be to set the alphabet only with lowercase and numbers and this would be solved.
from bogus.
Related Issues (20)
- Request to add language English (Hong Kong) / locale en_HK
- Faker.Tv() is missing from Bogus.Hollywood HOT 3
- Feature request: New localized data: Word(s).
- Add ability to except random numbers HOT 2
- Update Denmark (da) locale from faker-js
- Nuget for .NET 8.0.x HOT 4
- Random history facts generation
- Are Randomizer's number ranges inclusive or exclusive? HOT 3
- bogus is missing NuGet package README file HOT 1
- .NET 8 support HOT 9
- Gender-digit is incorrect for Swedish Personnummer generation HOT 3
- Switch to licence expression rather than URL HOT 1
- Invalid Iban generation for CR (Costa Rica) HOT 3
- Add hungarian (hu) locale from faker-js HOT 1
- How to make convert to generic method HOT 6
- Fakers used inside Rules of other Fakers share the same object reference HOT 2
- Determinism with Custom Datasets HOT 1
- Include the increment count for the Rules Expressions HOT 1
- Stack memory issue in locale tests (overflows on Mac) HOT 2
- Update `zh_CN` dataset to latest HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bogus.