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); }
public void ApplyValueTypeGetterReturnValueArrangement() { // 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 ReturnValueArrangement <int>(getter, 42); // When arrangment.ApplyTo(invocation); // Then Assert.True(invocation.HasFeature <IReturnValue <int> >()); var feature = invocation.GetFeature <IReturnValue <int> >(); Assert.Equal(42, feature.ReturnValue); }
public void ApplySequenceOfReferenceTypeReturnValuesGetterArrangement() { // Given var value1 = new object(); var value2 = new object(); var value3 = new object(); var signature = typeof(IFooReferenceTypeGetter <object>) .GetProperty(nameof(IFooReferenceTypeGetter <object> .Getter)) ?? throw new InvalidOperationException(); var getter = signature.GetGetMethod() ?? throw new InvalidOperationException(); var propertyFeature = new PropertyInvocation(signature); var returnValueFeature = new ReturnValueInvocation <object?>(); var invocation = new Invocation(getter, propertyFeature, returnValueFeature); var arrangment = new ReturnValueSequenceArrangement <object?>(getter, 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); }