public void ExcpetionIsThrownForUnarrangePropertySetterInvocation() { // Given var type = typeof(Stream); var propertyName = nameof(Stream.Position); var signature = type.GetProperty(propertyName)?.GetSetMethod() ?? throw new PropertyInfoException(type, propertyName); var setterInvocation = new Invocation(signature); var emptyArrangements = new ArrangementCollection(); var interceptor = new StrictMockInterceptor(emptyArrangements); // When var exception = Assert.Throws <MissingArrangementException>(() => interceptor.Intercept(setterInvocation)); // Then Assert.Contains(type.Name, exception.Message); Assert.Contains(propertyName, exception.Message); Assert.Contains("setter", exception.Message); }
public void ExcpetionIsThrownForUnarrangeMethodInvocation() { // Given var type = typeof(object); var methodName = nameof(object.GetHashCode); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var methodInvocation = new Invocation(signature); var emptyArrangements = new ArrangementCollection(); var interceptor = new StrictMockInterceptor(emptyArrangements); // When var exception = Assert.Throws <MissingArrangementException>(() => interceptor.Intercept(methodInvocation)); // Then Assert.Contains(type.Name, exception.Message); Assert.Contains(methodName, exception.Message); Assert.Contains("method", exception.Message); }
public void SuccessfullInvocationWithArrangement() { // Given var type = typeof(object); var methodName = nameof(object.GetHashCode); var signature = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName); var methodInvocation = new Invocation(signature, new ReturnValueInvocation <int>()); var arrangement = new ReturnValueArrangement <int>(signature, 42); var arrangements = new ArrangementCollection(new IArrangement[] { arrangement }); var interceptor = new StrictMockInterceptor(arrangements); // When var wasIntercepted = interceptor.Intercept(methodInvocation); // Then Assert.True(wasIntercepted); var hasFeature = methodInvocation.TryGetFeature <IReturnValue <int> >(out var feature); Assert.True(hasFeature); Assert.Equal(42, feature?.ReturnValue); }