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

WhenMemberHas broken #189

Closed
sglienke opened this issue Sep 15, 2015 · 0 comments
Closed

WhenMemberHas broken #189

sglienke opened this issue Sep 15, 2015 · 0 comments
Assignees
Labels

Comments

@sglienke
Copy link
Contributor

While looking through the code it occured to me that WhenMemberHas and WhenTargetHas have the exact same implementation. But imo WhenMemberHas should not check if Target.IsDefined but if Target.Member.IsDefined. While for properties this would be the same for methods and ctors that is not the case.

The first test fails because it mistakenly considers the Weak attribute.

    public class Knight 
    {
        public IWeapon Weapon { get; private set; }

        public Knight([Weak] IWeapon weapon)
        {
            this.Weapon = weapon;
        }
    }

    public class ConditionalBindingTests : StandardKernelContext
    {
        [Fact]
        public void WhenMemberHasShouldNotConsiderAttributeOnTarget()
        {
            kernel.Bind<Knight>().ToSelf();
            kernel.Bind<IWeapon>().To<Sword>();
            kernel.Bind<IWeapon>().To<ShortSword>().WhenMemberHas<WeakAttribute>();

            var knight = kernel.Get<Knight>();
            knight.Weapon.Should().BeOfType<Sword>();
        }

        [Fact]
        public void WhenTargetHasShouldConsiderAttributeOnTarget()
        {
            kernel.Bind<Knight>().ToSelf();
            kernel.Bind<IWeapon>().To<Sword>();
            kernel.Bind<IWeapon>().To<ShortSword>().WhenTargetHas<WeakAttribute>();

            var knight = kernel.Get<Knight>();
            knight.Weapon.Should().BeOfType<ShortSword>();
        }
    }
@scott-xu scott-xu added the Core label Sep 15, 2015
@scott-xu scott-xu self-assigned this Sep 15, 2015
scott-xu added a commit that referenced this issue Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants