Exemple #1
0
        public void InsertBehaviorToObject()
        {
            object avatar = new TestAvatar();

            var actual = avatar.InsertBehavior(0, new TestBehavior()) as IAvatar;

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

            var actual = avatar.InsertBehavior(0, 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);
        }
Exemple #3
0
        public void InsertAnonymousBehaviorToObject()
        {
            object         avatar = new TestAvatar();
            Func <string?> method = ToString;

            var actual = avatar.InsertBehavior(0,
                                               (m, n) => new MethodReturn(m, "foo", null !),
                                               m => true,
                                               nameof(InsertAnonymousBehaviorToObject)) as IAvatar;

            Assert.NotNull(actual);
            Assert.Same(avatar, actual);
            Assert.Single(actual !.Behaviors);
        }
Exemple #4
0
        public void InsertAnonymousBehavior()
        {
            IAvatar        avatar = new TestAvatar();
            Func <string?> method = ToString;

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

            Assert.Same(avatar, actual);
            Assert.Single(avatar.Behaviors);
            Assert.Equal(nameof(InsertAnonymousBehavior), 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);
        }