Ejemplo n.º 1
0
        public void TryApplySequenceOfValueTypeOutParametersArrangementFunc()
        {
            // 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>();
            var wasFirstApplied  = arrangment.TryApplyTo(invocation);
            var first            = feature.OutParameterCollection.First().Value;
            var wasSecondApplied = arrangment.TryApplyTo(invocation);
            var second           = feature.OutParameterCollection.First().Value;
            var wasThirdApplied  = arrangment.TryApplyTo(invocation);
            var third            = feature.OutParameterCollection.First().Value;
            var wasFourthApplied = arrangment.TryApplyTo(invocation);
            var fourth           = feature.OutParameterCollection.First().Value;

            // Then
            Assert.True(wasFirstApplied);
            Assert.Equal(13, first);
            Assert.True(wasSecondApplied);
            Assert.Equal(42, second);
            Assert.True(wasThirdApplied);
            Assert.Equal(65, third);
            Assert.True(wasFourthApplied);
            Assert.Equal(65, fourth);
        }
Ejemplo n.º 2
0
        public void EnsureTryApplySequenceIsFalseForNonMatchingInvocationFunc()
        {
            // 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> {
                13, 42, 65
            });

            // 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);
        }