Ejemplo n.º 1
0
        public void ApplySequenceOfReferenceTypeReturnValuesArrangement()
        {
            // Given
            var value1    = new object();
            var value2    = new object();
            var value3    = new object();
            var signature = typeof(IFooFuncReferenceTypeParameterless <object>)
                            .GetMethod(nameof(IFooFuncReferenceTypeParameterless <object> .MethodWithoutParameter)) ?? throw new InvalidOperationException();
            var returnValueFeature = new ReturnValueInvocation <object?>();
            var invocation         = new Invocation(signature, returnValueFeature);
            var arrangment         = new ReturnValueSequenceArrangement <object?>(signature, new List <object?>(new[] { value1, value2, value3 }));

            // When
            var feature = invocation.GetFeature <IReturnValue <object?> >();

            arrangment.ApplyTo(invocation);
            var first = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var second = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var third = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var fourth = feature.ReturnValue;

            // Then
            Assert.Equal(value1, first);
            Assert.Equal(value2, second);
            Assert.Equal(value3, third);
            Assert.Equal(value3, fourth);
        }
Ejemplo n.º 2
0
        public void ApplySequenceOfValueTypeReturnValuesGetterArrangement()
        {
            // Given
            var signature = typeof(IFooValueTypeGetter <int>)
                            .GetProperty(nameof(IFooValueTypeGetter <int> .Getter)) ?? throw new InvalidOperationException();
            var getter = signature.GetGetMethod() ?? throw new InvalidOperationException();

            var propertyFeature    = new PropertyInvocation(signature);
            var returnValueFeature = new ReturnValueInvocation <int>();
            var invocation         = new Invocation(getter, propertyFeature, returnValueFeature);
            var arrangment         = new ReturnValueSequenceArrangement <int>(getter, new List <int>(new[] { 13, 42, 65 }));

            // When
            var feature = invocation.GetFeature <IReturnValue <int> >();

            arrangment.ApplyTo(invocation);
            var first = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var second = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var third = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var fourth = feature.ReturnValue;

            // Then
            Assert.Equal(13, first);
            Assert.Equal(42, second);
            Assert.Equal(65, third);
            Assert.Equal(65, fourth);
        }
Ejemplo n.º 3
0
        public void ApplySequenceOfValueTypeReturnValuesArrangement()
        {
            // Given
            var signature = typeof(IFooFuncValueTypeParameterless <int>)
                            .GetMethod(nameof(IFooFuncValueTypeParameterless <int> .MethodWithoutParameter)) ?? throw new InvalidOperationException();
            var returnValueFeature = new ReturnValueInvocation <int>();
            var invocation         = new Invocation(signature, returnValueFeature);
            var arrangment         = new ReturnValueSequenceArrangement <int>(signature, new List <int>(new[] { 13, 42, 65 }));

            // When
            var feature = invocation.GetFeature <IReturnValue <int> >();

            arrangment.ApplyTo(invocation);
            var first = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var second = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var third = feature.ReturnValue;

            arrangment.ApplyTo(invocation);
            var fourth = feature.ReturnValue;

            // Then
            Assert.Equal(13, first);
            Assert.Equal(42, second);
            Assert.Equal(65, third);
            Assert.Equal(65, fourth);
        }
Ejemplo n.º 4
0
        public void ApplyAsyncSequenceOfReferenceTypeTaskReturnValuesArrangement()
        {
            // Given
            var value1    = new object();
            var value2    = new object();
            var value3    = new object();
            var signature = typeof(IFooGenericTaskReferenceTypeParameterless)
                            .GetMethod(nameof(IFooGenericTaskReferenceTypeParameterless.MethodWithoutParameterAsync)) ?? throw new InvalidOperationException();
            var asyncFeature = new AsyncGenericTaskInvocation <object?>();
            var invocation   = new Invocation(signature, asyncFeature);
            var arrangment   = new ReturnValueSequenceArrangement <Task <object?> >(signature, new List <Task <object?> >(new[]
            {
                Task.FromResult <object?>(value1),
                Task.FromResult <object?>(value2),
                Task.FromResult <object?>(value3)
            }));

            // When
            var feature = invocation.GetFeature <IAsyncInvocation <Task <object?> > >();

            arrangment.ApplyTo(invocation);
            var first = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var second = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var third = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var fourth = feature.AsyncReturnValue;

            // Then
            Assert.NotNull(first);
            Assert.IsAssignableFrom <Task <object?> >(first);
            Assert.Equal(value1, first.Result);
            Assert.NotNull(second);
            Assert.IsAssignableFrom <Task <object?> >(second);
            Assert.Equal(value2, second.Result);
            Assert.NotNull(third);
            Assert.IsAssignableFrom <Task <object?> >(third);
            Assert.Equal(value3, third.Result);
            Assert.NotNull(fourth);
            Assert.IsAssignableFrom <Task <object?> >(fourth);
            Assert.Equal(value3, fourth.Result);
        }
Ejemplo n.º 5
0
        public void EnsureNoArrangentIsAppliedToNonMatchingInvocation()
        {
            // Given
            var valueTypeSignature = typeof(IFooFuncValueTypeParameterless <int>)
                                     .GetMethod(nameof(IFooFuncValueTypeParameterless <int> .MethodWithoutParameter)) ?? throw new InvalidOperationException();
            var referenceTypeSignature = typeof(IFooFuncReferenceTypeParameterless <object>)
                                         .GetMethod(nameof(IFooFuncReferenceTypeParameterless <object> .MethodWithoutParameter)) ?? throw new InvalidOperationException();
            var returnValueFeature = new ReturnValueInvocation <int>();
            var invocation         = new Invocation(referenceTypeSignature, returnValueFeature);
            var arrangment         = new ReturnValueSequenceArrangement <int>(valueTypeSignature, new List <int>(new[] { 42 }));

            // When
            arrangment.ApplyTo(invocation);

            // Then
            var feature = invocation.GetFeature <IReturnValue <int> >();

            Assert.Equal(default, feature.ReturnValue);
Ejemplo n.º 6
0
        public void ApplyAsyncSequenceOfValueTypeReturnValuesArrangement()
        {
            // Given
            var signature = typeof(IFooGenericTaskValueTypeParameterless)
                            .GetMethod(nameof(IFooGenericTaskValueTypeParameterless.MethodWithoutParameterAsync)) ?? throw new InvalidOperationException();
            var asyncFeature = new AsyncGenericTaskInvocation <int>();
            var invocation   = new Invocation(signature, asyncFeature);
            var arrangment   = new ReturnValueSequenceArrangement <int>(signature, new List <int>(new[] { 13, 42, 65 }));

            // When
            var feature = invocation.GetFeature <IAsyncInvocation <Task <int> > >();

            arrangment.ApplyTo(invocation);
            var first = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var second = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var third = feature.AsyncReturnValue;

            arrangment.ApplyTo(invocation);
            var fourth = feature.AsyncReturnValue;

            // Then
            Assert.NotNull(first);
            Assert.IsAssignableFrom <Task <int> >(first);
            Assert.Equal(13, first.Result);
            Assert.NotNull(second);
            Assert.IsAssignableFrom <Task <int> >(second);
            Assert.Equal(42, second.Result);
            Assert.NotNull(third);
            Assert.IsAssignableFrom <Task <int> >(third);
            Assert.Equal(65, third.Result);
            Assert.NotNull(fourth);
            Assert.IsAssignableFrom <Task <int> >(fourth);
            Assert.Equal(65, fourth.Result);
        }