public void ApplyReferenceTypeOutParameterArrangementFunc() { // Given var expectedValue = new object(); var type = typeof(IFooFuncReferenceTypeParameterOut <object>); var methodName = nameof(IFooFuncReferenceTypeParameterOut <object> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterArrangement <object?>(signature, "first", expectedValue); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal("first", parameter.Name); Assert.Equal(typeof(object), parameter.Type); Assert.Equal(expectedValue, parameter.Value); }
public void CanApplyWithNonMatchingSignatureReturnsFalseFunc() { // Given var type = typeof(IFooFuncValueTypeParameterOut <int>); var methodName = nameof(IFooFuncValueTypeParameterOut <int> .MethodWithOneParameter); var valueTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); type = typeof(IFooFuncReferenceTypeParameterOut <object>); methodName = nameof(IFooFuncReferenceTypeParameterOut <object> .MethodWithOneParameter); var referenceTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(valueTypeSignature); var invocation = new Invocation(valueTypeSignature, outParameterFeature); var arrangment = new OutParameterArrangement <object?>(referenceTypeSignature, "first", new object()); // When var canApply = arrangment.CanApplyTo(invocation); // Then Assert.False(canApply); Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal(default(int), parameter.Value); }
public void EnsureTryApplyIsFalseForNonMatchingInvocationFunc() { // Given var type = typeof(IFooFuncValueTypeParameterOut <int>); var methodName = nameof(IFooFuncValueTypeParameterOut <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterArrangement <int>(signature, "WrongParameterName", 42); // When var wasApplied = arrangment.TryApplyTo(invocation); // Then Assert.False(wasApplied); Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal("first", parameter.Name); Assert.Equal(typeof(int), parameter.Type); Assert.Equal(default(int), parameter.Value); }
public void ApplySequenceOfValueTypeOutParametersArrangementFunc() { // Given var type = typeof(IFooFuncValueTypeParameterOut <int>); var methodName = nameof(IFooFuncValueTypeParameterOut <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterSequenceArrangement <int>(signature, "first", new List <int> { 13, 42, 65 }); // When var feature = invocation.GetFeature <IParameterOut>(); arrangment.ApplyTo(invocation); var first = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var second = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var third = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var fourth = feature.OutParameterCollection.First().Value; // Then Assert.Equal(13, first); Assert.Equal(42, second); Assert.Equal(65, third); Assert.Equal(65, fourth); }
public void CanApplySequenceWithNonMatchingParameterReturnsFalseFunc() { // Given var type = typeof(IFooFuncValueTypeParameterOut <int>); var methodName = nameof(IFooFuncValueTypeParameterOut <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterSequenceArrangement <int>(signature, "WrongParameterName", new List <int> { 42 }); // When var canApply = arrangment.CanApplyTo(invocation); // Then Assert.False(canApply); Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal(default(int), parameter.Value); }
public void EnsureNoArrangentIsAppliedToNonMatchingInvocationFunc() { // Given var type = typeof(IFooFuncValueTypeParameterOut <int>); var methodName = nameof(IFooFuncValueTypeParameterOut <int> .MethodWithOneParameter); var valueTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); type = typeof(IFooFuncReferenceTypeParameterOut <object>); methodName = nameof(IFooFuncReferenceTypeParameterOut <object> .MethodWithOneParameter); var referenceTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(valueTypeSignature); var invocation = new Invocation(valueTypeSignature, outParameterFeature); var arrangment = new OutParameterSequenceArrangement <object>( referenceTypeSignature, "first", new List <object> { new object() }); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal(default(int), parameter.Value); }
public void ApplySequenceOfReferenceTypeOutParametersArrangement() { // Given var value1 = new object(); var value2 = new object(); var value3 = new object(); var type = typeof(IFooActionReferenceTypeParameterOut <object>); var methodName = nameof(IFooActionReferenceTypeParameterOut <object> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterSequenceArrangement <object?>( signature, "first", new List <object?> { value1, value2, value3 }); // When var feature = invocation.GetFeature <IParameterOut>(); arrangment.ApplyTo(invocation); var first = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var second = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var third = feature.OutParameterCollection.First().Value; arrangment.ApplyTo(invocation); var fourth = feature.OutParameterCollection.First().Value; // Then Assert.Equal(value1, first); Assert.Equal(value2, second); Assert.Equal(value3, third); Assert.Equal(value3, fourth); }
public void EnsureNoArrangentIsAppliedToNonMatchingParameterInvocation() { // Given var type = typeof(IFooActionValueTypeParameterOut <int>); var methodName = nameof(IFooActionValueTypeParameterOut <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var outParameterFeature = new ParameterOut(signature); var invocation = new Invocation(signature, outParameterFeature); var arrangment = new OutParameterSequenceArrangement <int>(signature, "WrongParameterName", new List <int> { 13, 42, 65 }); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IParameterOut>()); var feature = invocation.GetFeature <IParameterOut>(); Assert.Single(feature.OutParameterCollection); var parameter = feature.OutParameterCollection.Single(); Assert.Equal(default(int), parameter.Value); }