Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }