Git Product home page Git Product logo

Comments (4)

Vidarls avatar Vidarls commented on May 13, 2024

Possibly related: The ability to set the value of individual properties on an immutable type where all setters are private.

//This will result in a compile error because of inaccessible setter
//If the "newValue" was injected through the constructor this would work
var x = fixture.Build<MyImmutableClass>()
  .With(v => v.MyReadonlyPropery = "newValue")
  .CreateAnonymous();

from autofixture.

WojcikMike avatar WojcikMike commented on May 13, 2024

I am trying to implement this one. Implementing checking for custom structs without constructors went well. However I have issues with allowing for that unsupported operation.

Initial code can be found here:
WojcikMike@ebda500

Short description goes as follows:
To Fixture I've added something like this:
new FilteringSpecimenBuilder(
new StructureWithoutConstructorSpecimenBuilder(), //throws exception with detailed message
new AndRequestSpecification(
new StructureSpecification(), //checks if it is custom struct
new NoConstructorSpecification())) //checks if it doesn't have constructors

I've created two classes:
SupportStructureDefaultConstructorsCustomization, SupportStructureDefaultConstructorsGenerator. and this is where the tricky parts are.

Generator creates structure itself so it is fine however I would have to pass it to fill all properties. To do this ideally my generator would have to land somewhere before Postprocessor with AutoPropertiesTarget. Any advices how to proceed?

from autofixture.

ploeh avatar ploeh commented on May 13, 2024

The Auto-Properties feature is implemented by composing Postprocessor with an AutoPropertiesCommand, so your customization would need to do something like this:

fixture.Customizations.Add(
    new Postprocessor(
        new SupportStructureDefaultConstructorsGenerator(),
        new AutoPropertiesCommand());

You may need to use the Postprocessor constructor overload, that also takes as a third parameter an IRequestSpecification...

from autofixture.

ploeh avatar ploeh commented on May 13, 2024

Available in AutoFixture 3.2.0.

from autofixture.

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.