EnabledIf Attribute in Mixins

Hi everyone,

I wanted to develop a mixin that has multiple properties with EnabledIf attributes such as:

public class TestMixin : ITestStepPostRunMixin
{
    [Browsable(false)]
    public bool IsEnabled { get; set; }

    [EnabledIf(nameof(IsEnabled), true, HideIfDisabled = true)]
    public string String1 { get; set; }

    [EnabledIf(nameof(IsEnabled), false, HideIfDisabled = true)]
    public string String2 { get; set; }

    public TestMixin(bool isEnabled)
    {
        IsEnabled = isEnabled;
    }

    public void OnPostRun(TestStepPostRunEventArgs eventArgs)
    {
        
    }
}

[MixinBuilder(typeof(ITestStepParent))]
public class TestMixinBuilder : IMixinBuilder
{
    public bool IsEnabled{ get; set; }
    public void Initialize(ITypeData targetType)
    {

    }

    public MixinMemberData ToDynamicMember(ITypeData targetType)
    {
        return new MixinMemberData(this, () => new TestMixin(IsEnabled))
        {
            TypeDescriptor = TypeData.FromType(typeof(TestMixin)),
            Attributes = GetAttributes(),
            Writable = true,
            Readable = true,
            DeclaringType = targetType,
            Name = "TestMixin"
        };
    }

    IEnumerable<Attribute> GetAttributes()
    {
        yield return new EmbedPropertiesAttribute();
        yield return new DisplayAttribute("Repeat Mixin", Order: 20000);
    }
}

Problem with this mixin is that when I modify the mixin from the menu command, EnabledIf attribute does not work, visibility of the properties are not changed.

This mixin works fine when it is directly embedded to a test step using [EmbedAttribute].

Edit:
This issue also exists for Basic Mixins plugin. When you modify a mixin, property on the Test Step Settings panel is not updated.

hi @btyilmaz,

Thanks for highlighting this!

Can you open an issue on github. That way we can track it and make sure it gets fixed in a future version.

1 Like

Hi @rolf_madsen ,

I opened an issue. Issue number is 1372

1 Like

Thanks, @btyilmaz! :star: :star: :star:

1 Like