Coder Social home page Coder Social logo

Comments (3)

bchavez avatar bchavez commented on May 14, 2024

Hi @carleberg ,

Thanks very much for reporting this. I think I might have forgotten a binding flag that caused multiple properties (with the same name/key) being added into a dictionary.

I think I've made the correct fix and here's the passing unit test:

public class Issue70 : SeededTest
{
    [Test]
    public void should_be_able_to_create_derrived_faker_with_class_hierarchy()
    {
        var baseBFaker = new Faker<BaseB>()
            .RuleFor(b => b.Value, f => f.Random.Int(1,5));

        var derivedBFaker = new Faker<DerivedB>()
            .RuleFor(b => b.Value, f => f.Random.Int(6,10)); ;

        //Works
        var baseAFaker = new Faker<BaseA>()
            .RuleFor(a => a.SomeProp, () => baseBFaker.Generate()); ;

        //Threw System.ArgumentException: 'An item with the same key has already been added.'
        var derivedAFaker = new Faker<DerivedA>()
            .RuleFor(da => da.SomeProp, () => derivedBFaker.Generate());


        DerivedA derivedA = derivedAFaker.Generate();

        derivedA.SomeProp.Value.Should().BeInRange(6,10);
        BaseA baseA = derivedA;
        baseA.SomeProp.Should().BeNull();
    }
}

Let me know if the unit test above looks correct and I'll run a new release with the fix.

Thanks,
💨 🚶 "Bubbles of gas in my brain... Send me off balance, it's not enough"

from bogus.

bchavez avatar bchavez commented on May 14, 2024

Hi @carleberg ,

Bogus v15.0.1 is now available and should hopefully fix your issue. Let me know. Feel free to re-open the issue if you continue to have problems.

Thanks,
Brian

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

from bogus.

carleberg avatar carleberg commented on May 14, 2024

It works great, thanks a lot for your quick response!

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.