public void WhenRunningMethod_ContainerBendy_IsPassedToDelegate() { // Arrange var builder = new BendyBuilder(); BendyObject _outer = null; // Act builder.CreateMethod("MyMethod", (containerBendy) => SetRef(ref _outer, ref containerBendy)); dynamic bendyDynamic = builder.ToBendy().AsDynamic(); bendyDynamic.MyMethod(); // Assert Assert.That(_outer, Is.Not.Null); }
public void WhenCreatingBendy_HavingParameterlessVoidMethod_MethodIsInvokable() { // Arrange var builder = new BendyBuilder(); // Act builder.AutoCreateMethod<string, string>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => x); var bendy = builder.ToBendy(); dynamic bendyDynamic = bendy.AsDynamic(); // Assert Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("alex"), Is.EqualTo("alex")); Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("different"), Is.EqualTo("different")); }
public void WhenCreatingBendy_HavingParameterlessVoidMethod_MethodIsInvokable() { // Arrange var builder = new BendyBuilder(); // Act builder.AutoCreateMethod <string, string>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => x); var bendy = builder.ToBendy(); dynamic bendyDynamic = bendy.AsDynamic(); // Assert Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("alex"), Is.EqualTo("alex")); Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("different"), Is.EqualTo("different")); }
public void NestingBendies_WithMethodDeclarations_Behaves() { // Arrange var parentBuilder = new BendyBuilder(); var childBuilder = new BendyBuilder(); // Act childBuilder.AutoCreateMethod<string, string>("Hiya", (containerBendy, x) => "alex" + x); parentBuilder.AutoCreateMethod("GetChild", (containerBendy) => childBuilder.ToBendy()); dynamic asDynamic = parentBuilder.ToBendy().AsDynamic(); // Assert Assert.That(asDynamic.GetChild(), Is.InstanceOf<BendyObject>()); Assert.That(asDynamic.GetChild().Hiya("bob"), Is.EqualTo("alexbob")); }
public void NestingBendies_WithMethodDeclarations_Behaves() { // Arrange var parentBuilder = new BendyBuilder(); var childBuilder = new BendyBuilder(); // Act childBuilder.AutoCreateMethod <string, string>("Hiya", (containerBendy, x) => "alex" + x); parentBuilder.AutoCreateMethod("GetChild", (containerBendy) => childBuilder.ToBendy()); dynamic asDynamic = parentBuilder.ToBendy().AsDynamic(); // Assert Assert.That(asDynamic.GetChild(), Is.InstanceOf <BendyObject>()); Assert.That(asDynamic.GetChild().Hiya("bob"), Is.EqualTo("alexbob")); }