Customizations are ignored
See original GitHub issueI’ve recently updated from AutoFixture 3.50.2 to 4.11.0
After update, Customize<>()
is not used when creating object with Build()
One more thing, probably related. When there are multiple customizations on the same object, only the last is valid, and previous are ignored. (The quick fix is to chain them inside one block, but this should not be the final solution.)
See the reproductions for both issues:
using AutoFixture;
using Xunit;
namespace CustomizationDoesntWork
{
public class ProofTest
{
public class Example
{
public string Name { get; set; }
public string City { get; set; }
}
[Fact]
public void ShouldUseCustomizationWhenBuilding()
{
var fixture = new Fixture();
fixture.Customize<Example>(e => e.Without(p => p.Name));
var exampleByCreate = fixture.Create<Example>();
Assert.Null(exampleByCreate.Name); // ok
var exampleByBuild = fixture.Build<Example>().With(e => e.City, "something").Create();
Assert.Null(exampleByBuild.Name); // fails!
}
[Fact]
public void ShouldRememberAllCustomizations()
{
var fixture = new Fixture();
fixture.Customize<Example>(e => e.With(p => p.Name, "John"));
fixture.Customize<Example>(e => e.With(p => p.City, "New York"));
var exampleByCreate = fixture.Create<Example>();
Assert.Equal("John", exampleByCreate.Name); // fails!
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Autofixtures "With"-Customizations for are ignored when ...
My goal is to be able to define only the parameters that are relevant for the specific tests, with immutable types in c#...
Read more >Layout builder customizations are ignored [#3053803]
Layout builder customizations are ignored ... We should fix this by using a custom EntityViewDisplay class for rendering - as layout builder ...
Read more >Is Customization A Revenue Stream That Is Being Ignored?
Being able to buy some that that will not help you progress in the game, but will allow you to customize your account...
Read more >Diffing Customization - Declarative GitOps CD for Kubernetes
Argo CD allows ignoring differences at a specific JSON path, using RFC6902 JSON patches and JQ path expressions. It is also possible to...
Read more >Customization: Ignoring marked Test Case steps
The Ignore Test Case steps customization can be used to can be used to ignore (leave unchanged) test case steps with a specific...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aivascu I don’t work for @emgdev anymore but I suppose the new CTO (@simgu) will assign the edit to someone else.
Anyway I have cloned and republished the guide on my own company’s account:
Repo: https://github.com/insight-architectures/unit-testing-csharp/ Published version: https://docs.insightarchitectures.com/unit-testing-csharp/
EDIT:
@ecampidoglio created an issue here and I cloned it in my repo
Thanks @ecampidoglio =)
Somehow I found these two misleading things pointing in the same direction before the docs xP
Anywho, my use case wouldn’t be solved even if this worked, I’d also need a callback on
Create
, similar to https://github.com/AutoFixture/AutoFixture/issues/988.Then building test data for EF Core InMemory testing would be quite nice: