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 CanApplyWithNonMatchingParameterReturnsFalse() { // 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 OutParameterArrangement <int>(signature, "WrongParameterName", 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); }