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);
        }
예제 #2
0
        private static IExpectation BuildParamExpectation(IInvocation invocation, MethodInfo method)
        {
            ArgManager.CheckMethodSignature(method);
            IExpectation expectation = new ConstraintsExpectation(invocation, ArgManager.GetAllConstraints(), new Range(1, null));

            expectation.OutRefParams = ArgManager.GetAllReturnValues();
            return(expectation);
        }
 public ConstraintExpectationTests()
 {
     method      = typeof(IDemo).GetMethod("VoidThreeArgs");
     expectation = new ConstraintsExpectation(new FakeInvocation(this.method), new AbstractConstraint[]
     {
         Is.Anything(),
         Text.Like(@"[\w\d]+"),
         Is.Equal(3.14f),
     }, new Range(1, 1));
 }
 public void PassingNullConstraintsThrows()
 {
     Assert.Throws <InvalidOperationException>(
         "The constraint at index 1 is null! Use Is.Null() to represent null parameters.",
         () =>
         expectation = new ConstraintsExpectation(new FakeInvocation(this.method), new AbstractConstraint[]
     {
         Is.Anything(),
         null,
         Is.Equal(3.14f),
     }, new Range(1, 1)));
 }
        public void CreateErrorMessageForConstraints()
        {
            ConstraintsExpectation expectation = new ConstraintsExpectation(new FakeInvocation(this.method), new AbstractConstraint[]
            {
                Is.Anything(),
                Is.Null(),
                Text.Like(@"[\w\d]+1234")
            }, new Range(1, 1));
            string message = "IDemo.VoidThreeArgs(anything, equal to null, like \"[\\w\\d]+1234\");";

            Assert.Equal(message, expectation.ErrorMessage);
        }
예제 #6
0
        /// <summary>
        /// Add constraints for the method's arguments.
        /// </summary>
        public IMethodOptions <T> Constraints(params AbstractConstraint[] constraints)
        {
            if (expectation is ConstraintsExpectation)
            {
                throw new InvalidOperationException(
                          string.Format("You have already specified constraints for this method. ({0})", this.expectation.ErrorMessage));
            }
            ConstraintsExpectation constraintsExpectation = new ConstraintsExpectation(expectation, constraints);

            ReplaceExpectation(constraintsExpectation);
            return(this);
        }