Ejemplo n.º 1
0
        public void AddBehaviorToObject()
        {
            object avatar = new TestAvatar();

            var actual = avatar.AddBehavior(new TestBehavior()) as IAvatar;

            Assert.NotNull(actual);
            Assert.Same(avatar, actual);
            Assert.Single(actual !.Behaviors);
        }
Ejemplo n.º 2
0
        public void AddBehavior()
        {
            IAvatar        avatar = new TestAvatar();
            Func <string?> method = ToString;

            var actual = avatar.AddBehavior(new TestBehavior());

            Assert.Same(avatar, actual);
            Assert.Single(avatar.Behaviors);
            Assert.Equal(nameof(TestBehavior), actual.Behaviors[0].ToString());
            Assert.True(actual.Behaviors[0].AppliesTo(null !));
            Assert.Equal("test", (string?)actual.Behaviors[0].Execute(new MethodInvocation(this, method.Method), null !).ReturnValue);
        }
Ejemplo n.º 3
0
        public void AddAnonymousBehavior()
        {
            IAvatar        avatar = new TestAvatar();
            Func <string?> method = ToString;

            var actual = avatar.AddBehavior(
                (m, n) => new MethodReturn(m, "foo", m.Arguments),
                m => true,
                nameof(AddBehavior));

            Assert.Same(avatar, actual);
            Assert.Single(avatar.Behaviors);
            Assert.Equal(nameof(AddBehavior), actual.Behaviors[0].ToString());
            Assert.True(actual.Behaviors[0].AppliesTo(null !));
            Assert.Equal("foo", (string?)actual.Behaviors[0].Execute(new MethodInvocation(this, method.Method), null !).ReturnValue);
        }