Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for customization order #1093

Open
zvirja opened this issue Dec 21, 2018 · 1 comment
Open

Add unit tests for customization order #1093

zvirja opened this issue Dec 21, 2018 · 1 comment
Assignees
Milestone

Comments

@zvirja
Copy link
Member

zvirja commented Dec 21, 2018

Add unit tests to ensure the order in which With(), Do() and auto-properties are assigned, so we ensure to not accidentally change that behavior.

@zvirja zvirja self-assigned this Dec 21, 2018
@Jaecen
Copy link

Jaecen commented Oct 7, 2019

@zvirja I'm looking in to creating these unit tests, but I'm seeing different behavior than you specified in #1092

The order of the callback invocations is following:

Constructor
Do() callbacks
With callbacks
AutoProperties callbacks

I'm seeing the AutoProperty callbacks being called before the .With() callbacks. Can you elaborate on what the expected order is?

Here's my repro:

[Fact]
public void BuilderStepsRunInCorrectOrder()
{
    // Arrange
    var fixture = new Fixture();
    var expectedSequence = new[]
    {
        BuildStepTest.Step.Constructor,
        BuildStepTest.Step.DoCallback,
        BuildStepTest.Step.PropertyOneWithCallback,
        BuildStepTest.Step.PropertyTwoAutoProperty,
    };

    // Act
    var buildSetTest = fixture.Build<BuildStepTest>()
        .Do(o => o.InvokableMethod())
        .With(o => o.PropertyOne, BuildStepTest.SpecialValue.SpecificInstance)
        .Create();

    // Assert
    Assert.Equal(expectedSequence, BuildStepTest.Sequence);
}

class BuildStepTest
{
    public static readonly List<Step> Sequence = new List<Step>();

    public class SpecialValue
    {
        public static readonly SpecialValue SpecificInstance = new SpecialValue();
    }

    public enum Step
    {
        Constructor,
        DoCallback,
        PropertyOneWithCallback,
        PropertyOneAutoProperty,
        PropertyTwoWithCallback,
        PropertyTwoAutoProperty,
    }

    public SpecialValue PropertyOne
    {
        get => null;

        set
        {
            if (ReferenceEquals(value, SpecialValue.SpecificInstance))
                Sequence.Add(Step.PropertyOneWithCallback);
            else
                Sequence.Add(Step.PropertyOneAutoProperty);
        }
    }

    public SpecialValue PropertyTwo
    {
        get => null;

        set
        {
            if (ReferenceEquals(value, SpecialValue.SpecificInstance))
                Sequence.Add(Step.PropertyTwoWithCallback);
            else
                Sequence.Add(Step.PropertyTwoAutoProperty);
        }
    }

    public BuildStepTest()
    {
        Sequence.Add(Step.Constructor);
    }

    public void InvokableMethod()
    {
        Sequence.Add(Step.DoCallback);
    }
}

@aivascu aivascu added this to the v4.0 milestone Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants