question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Is there a way to generate value for only primitive properties?

See original GitHub issue

We are using EF Core we so designed our entity classes like the following structure:

public class Box
{
    public int Id { get; set; }
    public ICollection<Content> Contents { get; set; }
}

public class Content
{
    public int Id { get; set; }
    int BoxId { get; set; }
    Box Box { get; set; }
}

When we are using AutoFixture to generate test data, for example: fixture.Build<Content>.Create(), it generates the value of BoxId and a Box instance with different Id than the BoxId (which is correct behavior BTW), however we just want AutoFixture generate all properties of primitive types and leave all properties of complex types null, currently we are using .Without() to exclude members that we don’t want Autofixture to generate values for (fixture.Build<Content>.Without(c => c.Box)), however as there are so many properties of complex types in many class, using .Without() increases our code lines.

  • Question 1: is there a way (maybe behavior) to configure this globally?
  • Question 2: Any suggestions on using AutoFixture with EF Core 2.1 and SQLite in-memory unit testing practices?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LiangZugengcommented, Sep 1, 2022

@ekondur it’s been a long time since my last reply! When I posted the question we designed class graphs without context boundaries and aggregated roots in the mind, so all classes were references by all other classes with different levels of navigation properties, that was not a good design, the problem we encountered with AutoFixture was caused by AutoFixture but by our design.

We changed the design and introduced context boundaries and aggregated roots, and it avoided almost all cyclical references. We had no problems since then.

1reaction
LiangZugengcommented, Aug 3, 2018

Great, will test it ASAP

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to document an object with only primitive values?
You can define a custom type using union with @typedef @typedef {(number|string|boolean|...)} YourType. Then refering to this type in your ...
Read more >
How do primitive values get their properties?
We'll look at: Getting property values; Invoking property values (a.k.a. method calls); Setting property values.
Read more >
How to check if the value is primitive or not in JavaScript
To check a value whether it is primitive or not we use the following approaches: Approach 1: In this approach, we check the...
Read more >
JavaScript data types and data structures - MDN Web Docs
Objects are converted to primitives by calling its [@@toPrimitive]() (with "default" as hint), valueOf() , and toString() methods, in that order ...
Read more >
Discovering Primitive Objects In JavaScript (Part 1)
We might assume that the only way primitive values are changed in JavaScript is through the assignment, which means what we're actually changing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found