public void ApplySequenceOfValueTypeRefParametersArrangementFunc() { // Given var type = typeof(IFooFuncValueTypeParameterRef <int>); var methodName = nameof(IFooFuncValueTypeParameterRef <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var refParameterFeature = new ParameterRef(signature, new object[] { 9 }); var invocation = new Invocation(signature, refParameterFeature); var arrangment = new RefParameterSequenceArrangement <int>(signature, "first", new List <int> { 13, 42, 65 }); // When var feature = invocation.GetFeature <IParameterRef>(); arrangment.ApplyTo(invocation); var first = feature.RefParameterCollection.First().Value; arrangment.ApplyTo(invocation); var second = feature.RefParameterCollection.First().Value; arrangment.ApplyTo(invocation); var third = feature.RefParameterCollection.First().Value; arrangment.ApplyTo(invocation); var fourth = feature.RefParameterCollection.First().Value; // Then Assert.Equal(13, first); Assert.Equal(42, second); Assert.Equal(65, third); Assert.Equal(65, fourth); }
public void EnsureNoArrangentIsAppliedToNonMatchingInvocationFunc() { // Given var type = typeof(IFooFuncValueTypeParameterRef <int>); var methodName = nameof(IFooFuncValueTypeParameterRef <int> .MethodWithOneParameter); var valueTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); type = typeof(IFooFuncReferenceTypeParameterRef <object>); methodName = nameof(IFooFuncReferenceTypeParameterRef <object> .MethodWithOneParameter); var referenceTypeSignature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var refParameterFeature = new ParameterRef(valueTypeSignature, new object[] { 9 }); var invocation = new Invocation(valueTypeSignature, refParameterFeature); var arrangment = new RefParameterSequenceArrangement <object>( referenceTypeSignature, "first", new List <object> { new object() }); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IParameterRef>()); var feature = invocation.GetFeature <IParameterRef>(); Assert.Single(feature.RefParameterCollection); var parameter = feature.RefParameterCollection.Single(); Assert.Equal(9, parameter.Value); }
public void EnsureNoArrangentIsAppliedToNonMatchingParameterInvocation() { // Given var type = typeof(IFooActionValueTypeParameterRef <int>); var methodName = nameof(IFooActionValueTypeParameterRef <int> .MethodWithOneParameter); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var refParameterFeature = new ParameterRef(signature, new object[] { 9 }); var invocation = new Invocation(signature, refParameterFeature); var arrangment = new RefParameterSequenceArrangement <int>(signature, "WrongParameterName", new List <int> { 13, 42, 65 }); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IParameterRef>()); var feature = invocation.GetFeature <IParameterRef>(); Assert.Single(feature.RefParameterCollection); var parameter = feature.RefParameterCollection.Single(); Assert.Equal(9, parameter.Value); }