Giter VIP home page Giter VIP logo

Comments (2)

bchavez avatar bchavez commented on May 18, 2024

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.

mdmoura avatar mdmoura commented on May 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.