コード例 #1
0
ファイル: IntegerMatchTests.cs プロジェクト: wserr/AspNetCore
        public void IntegerMatch_Evaluation_Cases_Tests(int value, int operation, string input, bool expectedResult)
        {
            var context = new RewriteContext {
                HttpContext = new DefaultHttpContext()
            };
            var integerMatch = new IntegerMatch(value, (IntegerOperationType)operation);
            var matchResult  = integerMatch.Evaluate(input, context);

            Assert.Equal(expectedResult, matchResult.Success);
        }
コード例 #2
0
ファイル: RuleBuilder.cs プロジェクト: pa-at/aspnetcore
    public void AddConditionFromParts(
        Pattern pattern,
        ParsedModRewriteInput input,
        Flags flags)
    {
        if (_conditions == null)
        {
            _conditions = new List <Condition>();
        }

        var orNext = flags.HasFlag(FlagType.Or);

        UrlMatch match;

        switch (input.ConditionType)
        {
        case ConditionType.Regex:
            Debug.Assert(input.Operand != null);
            if (flags.HasFlag(FlagType.NoCase))
            {
                match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, _regexTimeout), input.Invert);
            }
            else
            {
                match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled, _regexTimeout), input.Invert);
            }
            break;

        case ConditionType.IntComp:
            Debug.Assert(input.Operand != null);
            switch (input.OperationType)
            {
            case OperationType.Equal:
                match = new IntegerMatch(input.Operand, IntegerOperationType.Equal);
                break;

            case OperationType.Greater:
                match = new IntegerMatch(input.Operand, IntegerOperationType.Greater);
                break;

            case OperationType.GreaterEqual:
                match = new IntegerMatch(input.Operand, IntegerOperationType.GreaterEqual);
                break;

            case OperationType.Less:
                match = new IntegerMatch(input.Operand, IntegerOperationType.Less);
                break;

            case OperationType.LessEqual:
                match = new IntegerMatch(input.Operand, IntegerOperationType.LessEqual);
                break;

            case OperationType.NotEqual:
                match = new IntegerMatch(input.Operand, IntegerOperationType.NotEqual);
                break;

            default:
                throw new ArgumentException("Invalid operation for integer comparison.");
            }
            break;

        case ConditionType.StringComp:
            Debug.Assert(input.Operand != null);
            switch (input.OperationType)
            {
            case OperationType.Equal:
                match = new StringMatch(input.Operand, StringOperationType.Equal, input.Invert);
                break;

            case OperationType.Greater:
                match = new StringMatch(input.Operand, StringOperationType.Greater, input.Invert);
                break;

            case OperationType.GreaterEqual:
                match = new StringMatch(input.Operand, StringOperationType.GreaterEqual, input.Invert);
                break;

            case OperationType.Less:
                match = new StringMatch(input.Operand, StringOperationType.Less, input.Invert);
                break;

            case OperationType.LessEqual:
                match = new StringMatch(input.Operand, StringOperationType.LessEqual, input.Invert);
                break;

            default:
                throw new ArgumentException("Invalid operation for string comparison.");
            }
            break;

        default:
            switch (input.OperationType)
            {
            case OperationType.Directory:
                match = new IsDirectoryMatch(input.Invert);
                break;

            case OperationType.RegularFile:
                match = new IsFileMatch(input.Invert);
                break;

            case OperationType.ExistingFile:
                match = new IsFileMatch(input.Invert);
                break;

            case OperationType.SymbolicLink:
                // TODO see if FileAttributes.ReparsePoint works for this?
                throw new NotImplementedException("Symbolic links are not supported because " +
                                                  "of cross platform implementation");

            case OperationType.Size:
                match = new FileSizeMatch(input.Invert);
                break;

            case OperationType.ExistingUrl:
                throw new NotSupportedException("Existing Url lookups not supported because it requires a subrequest");

            case OperationType.Executable:
                throw new NotSupportedException("Executable Property is not supported because Windows " +
                                                "requires a pinvoke to get this property");

            default:
                throw new ArgumentException("Invalid operation for property comparison");
            }
            break;
        }

        var condition = new Condition(pattern, match, orNext);

        _conditions.Add(condition);
    }