示例#1
0
        public override void Assert()
        {
            switch (AssertType)
            {
            case OneParamAssertTypes.IsTrue:
                AssertionHelper.ExecuteIfBool(IsTrue, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsFalse:
                AssertionHelper.ExecuteIfBool(IsFalse, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsEmpty:
                AssertionHelper.ExecuteIfAppropriateType <T, ICollection>(IsEmpty, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsNotEmpty:
                AssertionHelper.ExecuteIfAppropriateType <T, ICollection>(IsNotEmpty, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsNull:
                IsNull(FirstParam, Message);
                break;

            case OneParamAssertTypes.IsNotNull:
                IsNotNull(FirstParam, Message);
                break;

            case OneParamAssertTypes.IsZero:
                AssertionHelper.ExecuteIfNumeric(IsZero, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsNotZero:
                AssertionHelper.ExecuteIfNumeric(IsNotZero, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsPositive:
                AssertionHelper.ExecuteIfNumeric(IsPositive, FirstParam, Message);
                break;

            case OneParamAssertTypes.IsNegative:
                AssertionHelper.ExecuteIfNumeric(IsNegative, FirstParam, Message);
                break;

            case OneParamAssertTypes.That:
                var wasAsserted1 = AssertionHelper.ExecuteIfBool(That, FirstParam, Message, false);
                var wasAsserted2 = AssertionHelper.ExecuteIfAppropriateType <T, Func <bool> >(That, FirstParam, Message, false);
                if (!(wasAsserted1 || wasAsserted2))
                {
                    AssertionHelper.ThrowExceptionIfNeeded(true, typeof(bool), FirstParam.GetType());
                }
                break;

            case OneParamAssertTypes.Throws:
                Throws(FirstParam, Message);
                break;

            case OneParamAssertTypes.ThrowsAsync:
                ThrowsAsync(FirstParam, Message);
                break;

            default:
                ThrowExceptionIfInvalidEnumItem();
                break;
            }
        }