Esempio n. 1
0
        internal void WhereBuilder_ValidateSymbolILogicalOperator_InvalidProceeding_ThrowsException(
            ILogicalOperatorSymbol symbol,
            ISequenceSymbol nextSymbol)
        {
            // Act && Assert
            var ex = Assert.Throws <ParseException>(() => this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(symbol, nextSymbol, 1));

            Assert.StartsWith(ValidationErrorResources.SequenceOfSymbols_AfterLogicalOperatorThereMustBeOpeningParenthesisOrExpression, ex.Message);
        }
Esempio n. 2
0
 public void ValidateSymbol(ExpressionSymbol <T> sequenceSymbol, ISequenceSymbol nextSymbol)
 {
     if (!this.allowedSymbolsAfterExpression.Contains(nextSymbol?.GetType()))
     {
         throw new ParseException(
                   ValidationErrorResources.SequenceOfSymbols_AfterExpressionThereMustBeLogicalOperatorOrClosingParenthesis,
                   sequenceSymbol.QueryPartIndex);
     }
 }
Esempio n. 3
0
        internal void ExpressionCollectionBuilder_HitsInvalidSymbol_ThrowsException(ISequenceSymbol sequenceSymbol)
        {
            // Arrange
            var sequenceOfSymbols = new List <ISequenceSymbol>();

            sequenceOfSymbols.Add(sequenceSymbol);

            // Act & Assert
            var ex = Assert.Throws <NotImplementedException>(() => this._fixture._expressionCollectionBuilder.Build(sequenceOfSymbols));

            Assert.Equal(string.Format(GeneralResources.Exception_UnexpectedTokenDuringAnalysisOfSequenceOfSymbols, sequenceSymbol.GetType()), ex.Message);
        }
Esempio n. 4
0
        public void ValidateSymbol(ILogicalOperatorSymbol sequenceSymbol, ISequenceSymbol nextSymbol, int i)
        {
            if (i == 0)
            {
                throw new ParseException(
                          ValidationErrorResources.SequenceOfSymbols_QueryCannotBeginWithLogicalOperator,
                          (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
            }

            if (!this.allowedSymbolsAfterLogicalOperator.Contains(nextSymbol?.GetType()))
            {
                throw new ParseException(
                          ValidationErrorResources.SequenceOfSymbols_AfterLogicalOperatorThereMustBeOpeningParenthesisOrExpression,
                          (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
            }
        }
Esempio n. 5
0
        public void ValidateSymbol(IParenthesisSymbol sequenceSymbol, ISequenceSymbol nextSymbol, int i, ref int parenthesisCount)
        {
            switch (sequenceSymbol)
            {
            case ParenthesisOpenSymbol _:
                parenthesisCount++;

                if (!this.allowedSymbolsAfterParenthesisOpen.Contains(nextSymbol?.GetType()))
                {
                    throw new ParseException(
                              ValidationErrorResources.SequenceOfSymbols_AfterOpeningParenthesisThereMustBeExpressionOrOpeningParenthesis,
                              (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
                }
                break;

            case ParenthesisCloseSymbol _:
                if (i == 0)
                {
                    throw new ParseException(
                              ValidationErrorResources.SequenceOfSymbols_QueryCannotBeginWithClosingParenthesis,
                              (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
                }

                parenthesisCount--;

                if (!this.allowedSymbolsAfterParenthesisClose.Contains(nextSymbol?.GetType()))
                {
                    throw new ParseException(
                              ValidationErrorResources.SequenceOfSymbols_AfterClosingParenthesisThereMustBeLogicalOperatorOrClosingParenthesis,
                              (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
                }
                break;

            default:     // should not happen
                throw new ParseException(
                          string.Format(ValidationErrorResources.SequenceOfSymbols_UnknownParenthesisSymbolX, sequenceSymbol.GetType()),
                          (sequenceSymbol as ISequenceSymbol).QueryPartIndex);
            }
        }
Esempio n. 6
0
        internal void SequenceOfSymbolsBuilder_QueryBeginsWithValidSymbols_DoesNotThrowException(
            ISequenceSymbol sequenceSymbol,
            ISequenceSymbol nextSequenceSymbol1,
            ISequenceSymbol nextSequenceSymbol2)
        {
            // Arrange
            var sequenceOfSymbols = new List <ISequenceSymbol>();

            sequenceOfSymbols.Add(sequenceSymbol);

            if (nextSequenceSymbol1 != null)
            {
                sequenceOfSymbols.Add(nextSequenceSymbol1);
            }

            if (nextSequenceSymbol2 != null)
            {
                sequenceOfSymbols.Add(nextSequenceSymbol2);
            }

            // Act
            this._fixture.SequenceOfSymbolsValidator.Validate(sequenceOfSymbols);
        }
Esempio n. 7
0
        internal void SequenceOfSymbolsBuilder_QueryBeginsWithInvalidSymbols_ThrowsException(ISequenceSymbol sequenceSymbol, string expectedExceptionMessage)
        {
            // Arrange
            var sequenceOfSymbols = new List <ISequenceSymbol>();

            sequenceOfSymbols.Add(sequenceSymbol);

            // Act & Assert
            var ex = Assert.Throws <ParseException>(() => this._fixture.SequenceOfSymbolsValidator.Validate(sequenceOfSymbols));

            Assert.StartsWith(expectedExceptionMessage, ex.Message);
        }
Esempio n. 8
0
        internal void WhereBuilder_ValidateSymbolParenthesisClose_ValidProceeding_DoesnNotThrowException(ISequenceSymbol nextSymbol)
        {
            // Arrange
            var parenthesisCount = 0;

            // Act
            this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(new ParenthesisCloseSymbol(0), nextSymbol, 1, ref parenthesisCount);
        }
Esempio n. 9
0
        internal void WhereBuilder_ValidateSymbolExpression_ParenthesisClose_ThrowsException(ISequenceSymbol nextSymbol)
        {
            // Arrange
            var parenthesisCount = 0;

            // Act && Assert
            var ex = Assert.Throws <ParseException>(() => this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(new ParenthesisCloseSymbol(0), nextSymbol, 1, ref parenthesisCount));

            Assert.StartsWith(ValidationErrorResources.SequenceOfSymbols_AfterClosingParenthesisThereMustBeLogicalOperatorOrClosingParenthesis, ex.Message);
        }
Esempio n. 10
0
 internal void WhereBuilder_ValidateSymbolExpression_ValidProceeding_DoesnNotThrowException(ISequenceSymbol nextSymbol)
 {
     // Act
     this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(new ExpressionSymbol <object>(0, null), nextSymbol);
 }
Esempio n. 11
0
        internal void WhereBuilder_ValidateSymbolExpression_InvalidProceeding_ThrowsException(ISequenceSymbol nextSymbol)
        {
            // Act && Assert
            var ex = Assert.Throws <ParseException>(() => this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(new ExpressionSymbol <object>(0, null), nextSymbol));

            Assert.StartsWith(ValidationErrorResources.SequenceOfSymbols_AfterExpressionThereMustBeLogicalOperatorOrClosingParenthesis, ex.Message);
        }
Esempio n. 12
0
 internal void WhereBuilder_ValidateSymbolILogicalOperator_ValidProceeding_DoesnNotThrowException(ILogicalOperatorSymbol symbol, ISequenceSymbol nextSymbol)
 {
     // Act
     this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(symbol, nextSymbol, 1);
 }