public void AbstractExpectationPropertiesReturnTheValuesSetByDerivedClass() { Range r = new Range(0, 30); IExpectation test = GetExpectation(method, r, 5); Assert.Equal(r, test.Expected); Assert.Equal(5, test.ActualCallsCount); }
/// <summary> /// Initializes a new instance of the <see cref="ConstraintsExpectation"/> class. /// Creates a new <see cref="ConstraintsExpectation"/> instance. /// </summary> /// <param name="invocation"> /// Invocation for this expectation /// </param> /// <param name="constraints"> /// Constraints. /// </param> /// <param name="expectedRange"> /// Number of method calls for this expectations /// </param> public ConstraintsExpectation(IInvocation invocation, AbstractConstraint[] constraints, Range expectedRange) : base(invocation, expectedRange) { Validate.IsNotNull(() => constraints); this.constraints = constraints; ConstraintsMatchMethod(); }
public void ExpectationIsClosedForVoidMethod() { Range r = new Range(0, 5); MethodInfo voidMethod = typeof (IDemo).GetMethod("VoidNoArgs"); IExpectation test = GetExpectation(voidMethod, r, 0); Assert.True(test.ActionsSatisfied); }
public void AddActualMethodIncreaseActualCalls() { Range r = new Range(0, 5); IExpectation test = GetExpectation(method, r, 0); Assert.Equal(0, test.ActualCallsCount); test.AddActualCall(); Assert.Equal(1, test.ActualCallsCount); test.AddActualCall(); Assert.Equal(2, test.ActualCallsCount); }
/// <summary> /// Initializes a new instance of the <see cref="AbstractExpectation"/> class. /// Creates a new <see cref="AbstractExpectation"/> instance. /// </summary> /// <param name="invocation"> /// The originalInvocation for this method, required because it contains the generic type infromation /// </param> /// <param name="expectedRange"> /// Number of method calls for this expectations /// </param> protected AbstractExpectation(IInvocation invocation, Range expectedRange) { Validate.IsNotNull(invocation, "originalInvocation"); Validate.IsNotNull(invocation.Method, "method"); this.originalInvocation = invocation; this.method = invocation.Method; this.expected = expectedRange; }
public void RangeToStringWhenMinZeroAndMaxNonZero() { Range range = new Range(0, 30); Assert.Equal("30", range.ToString()); }
protected override IExpectation GetExpectation(MethodInfo m, Range r, int actual) { CallbackExpectation expectation = new CallbackExpectation(new FakeInvocation(m), new DelegateDefinations.NoArgsDelegate(VoidNoArgs), new Range(1, 1)); SetupExpectation(expectation, r, actual); return expectation; }
public void RangeToString() { Range range = new Range(30, 50); Assert.Equal("30..50", range.ToString()); }
public void RangeToStringWhenMinMaxEqual() { Range range = new Range(30, 30); Assert.Equal("30", range.ToString()); }
public void HasCallLeftWhenThereArentCallLeft() { Range r = new Range(0, 1); IExpectation test = GetExpectation(method, r, 1); Assert.False(test.CanAcceptCalls); }
public void RangePropetiesReturnTheSameValuesAsThosePassedInCtor() { Range range = new Range(30, 50); Assert.Equal(30, range.Min); Assert.Equal(50, range.Max); }
/// <summary> /// Initializes a new instance of the <see cref="AbstractExpectation"/> class. /// Creates a new <see cref="AbstractExpectation"/> instance. /// </summary> /// <param name="expectation"> /// Expectation. /// </param> protected AbstractExpectation(IExpectation expectation) : this(expectation.Originalinvocation, new Range(1, 1)) { returnValue = expectation.ReturnValue; returnValueSet = expectation.HasReturnValue; expected = expectation.Expected; actualCallsCount = expectation.ActualCallsCount; repeatableOption = expectation.RepeatableOption; exceptionToThrow = expectation.ExceptionToThrow; Message = expectation.Message; actionToExecute = expectation.ActionToExecute; outRefParams = expectation.OutRefParams; allowTentativeReturn = expectation.AllowTentativeReturn; }
protected override IExpectation GetExpectation(MethodInfo m, Range r, int actual) { AnyArgsExpectation expectation = new AnyArgsExpectation(new FakeInvocation(m), new Range(1, 1)); SetupExpectation(expectation, r, actual); return expectation; }
/// <summary> /// Initializes a new instance of the <see cref="AnyArgsExpectation"/> class. /// Creates a new <see cref="AnyArgsExpectation"/> instance. /// </summary> /// <param name="invocation"> /// Invocation for this expectation /// </param> /// <param name="expectedRange"> /// Number of method calls for this expectations /// </param> public AnyArgsExpectation(IInvocation invocation, Range expectedRange) : base(invocation, expectedRange) { }
protected abstract IExpectation GetExpectation(MethodInfo m, Range r, int actual);
protected static void SetupExpectation(IExpectation expectation, Range r, int actual) { expectation.Expected = r; for (int i = 0; i < actual; i++) { expectation.AddActualCall(); } }
public void HashCodeIsTheSameAcrossInvocations() { Range r = new Range(0, 5); MethodInfo voidMethod = typeof (IDemo).GetMethod("VoidNoArgs"); IExpectation test = GetExpectation(voidMethod, r, 0); Assert.Equal(test.GetHashCode(),test.GetHashCode()); }
protected override IExpectation GetExpectation(MethodInfo m, Range r, int actual) { IExpectation expectation = new ConstraintsExpectation(new FakeInvocation(m),new AbstractConstraint[0], new Range(1, 1)); SetupExpectation(expectation, r, actual); return expectation; }
/// <summary> /// Initializes a new instance of the <see cref="CallbackExpectation"/> class. /// Creates a new <see cref="CallbackExpectation"/> instance. /// </summary> /// <param name="invocation"> /// Invocation for this expectation /// </param> /// <param name="callback"> /// Callback. /// </param> /// <param name="expectedRange"> /// Number of method calls for this expectations /// </param> public CallbackExpectation(IInvocation invocation, Delegate callback, Range expectedRange) : base(invocation, expectedRange) { this.callback = callback; ValidateCallback(); }
/// <summary> /// Initializes a new instance of the <see cref="ArgsEqualExpectation"/> class. /// Creates a new <see cref="ArgsEqualExpectation"/> instance. /// </summary> /// <param name="invocation"> /// The invocation for this expectation /// </param> /// <param name="expectedArgs"> /// Expected args. /// </param> /// <param name="expectedRange"> /// Number of method calls for this expectations /// </param> public ArgsEqualExpectation(IInvocation invocation, object[] expectedArgs, Range expectedRange) : base(invocation, expectedRange) { this.expectedArgs = expectedArgs; }