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.

Customizations are ignored

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kralizekcommented, Apr 8, 2021

@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

0reactions
elonmallincommented, Apr 8, 2021

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:

// Setup
var fixture = new Fixture();

fixture.Customize<Person>(b => b
    .With(p => p.Id, () => UniqueId())
    .OnCreate((person) => {
        _efCoreInMemoryTestContext.Persons.Add(person);
        _efCoreInMemoryTestContext.SaveChanges();
    })
);
// Test
// Arrange
var person = fixture.Build<Person>()
    .With(p => p.UpdatedDate, DateTime.Now.AddDays(-8))
    .Create(); // Person has a generated id, is saved to the InMemory DB and is ready to use in EF Core InMemory testing.

// Act
// Get persons updated more than a week ago

// Assert
// Result matches person
Read more comments on GitHub >

github_iconTop 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 >

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