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); }
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); }
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); }
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); }