public void WhenCreatingBendy_HavingTwoParameterlessVoidMethod_CorrectMethodIsInvoked() { // Arrange var builder = new BendyBuilder(); // Act builder.AutoCreateMethod<string, string>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => x); builder.AutoCreateMethod<int, int>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => 5); var bendy = builder.ToBendy(); dynamic bendyDynamic = bendy.AsDynamic(); // Assert Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("alex"), Is.EqualTo("alex")); Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged(0), Is.EqualTo(5)); }
public void WhenCreatingBendy_HavingTwoParameterlessVoidMethod_CorrectMethodIsInvoked() { // Arrange var builder = new BendyBuilder(); // Act builder.AutoCreateMethod <string, string>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => x); builder.AutoCreateMethod <int, int>("MyNonExistantMethodReturnsParamUnchanged", (containerBendy, x) => 5); var bendy = builder.ToBendy(); dynamic bendyDynamic = bendy.AsDynamic(); // Assert Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged("alex"), Is.EqualTo("alex")); Assert.That(bendyDynamic.MyNonExistantMethodReturnsParamUnchanged(0), Is.EqualTo(5)); }
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")); }
public void WhenInferringSignatureFromLambda_WithParameters_AndStringReturnValue_SignatureHasName() { // Arrange var builder = new BendyBuilder(); // Act var method = builder.AutoCreateMethod <string, string>("MyMethod", (containerBendy, myParameter) => "return value"); // Assert Assert.That(method.Signature.Name, Is.EqualTo("MyMethod")); Assert.That(method.Signature.ReturnsValue, Is.EqualTo(true)); Assert.That(method.Signature.ReturnType, Is.EqualTo(typeof(string))); Assert.That(method.Signature.Parameters.ToArray()[1].Name, Is.EqualTo("myParameter")); Assert.That(method.Signature.Parameters.ToArray()[1].Type, Is.EqualTo(typeof(string))); Assert.That(builder.Methods.Count(), Is.EqualTo(1)); Assert.That(builder.Methods, Has.All.SameAs(method)); }
public void WhenInferringSignatureFromLambda_WithParameters_AndStringReturnValue_SignatureHasName() { // Arrange var builder = new BendyBuilder(); // Act var method = builder.AutoCreateMethod<string, string>("MyMethod", (containerBendy, myParameter) => "return value"); // Assert Assert.That(method.Signature.Name, Is.EqualTo("MyMethod")); Assert.That(method.Signature.ReturnsValue, Is.EqualTo(true)); Assert.That(method.Signature.ReturnType, Is.EqualTo(typeof(string))); Assert.That(method.Signature.Parameters.ToArray()[0].Name, Is.EqualTo("myParameter")); Assert.That(method.Signature.Parameters.ToArray()[0].Type, Is.EqualTo(typeof(string))); Assert.That(builder.Methods.Count(), Is.EqualTo(1)); Assert.That(builder.Methods, Has.All.SameAs(method)); }