internal void ExpressionCollectionBuilder_ExpressionSymbolsConcatenatedWithLogicalOperators_AllButLastExpressionItemsHaveLogicalOperator( int numberOfExpressionSymbols, ILogicalOperatorSymbol logicalOperator) { // Arrange var sequenceOfSymbols = new List <ISequenceSymbol>(); for (var i = 0; i < numberOfExpressionSymbols; i++) { sequenceOfSymbols.Add(new ExpressionSymbol <object>(i, x => true)); if (i < numberOfExpressionSymbols - 1) { sequenceOfSymbols.Add(logicalOperator as ISequenceSymbol); } } // Act var expressionCollection = this._fixture._expressionCollectionBuilder.Build(sequenceOfSymbols); // Assert var elementInspectors = new List <Action <ExpressionBase <object> > >(); // Element inspectors for all but last ExpressionItem for (var i = 0; i < numberOfExpressionSymbols - 1; i++) { elementInspectors.Add(elem => Assert.NotNull(elem.LogicalOperator)); } // Element inspector for last ExpressionItem elementInspectors.Add(elem => Assert.Null(elem.LogicalOperator)); Assert.Collection(expressionCollection, elementInspectors.ToArray()); }
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); }
internal static LogicalOperator ToLogicalOperator(this ILogicalOperatorSymbol symbol) { switch (symbol) { case LogicalOperatorAndSymbol _: return(LogicalOperator.And); case LogicalOperatorOrSymbol _: return(LogicalOperator.Or); default: throw new NotImplementedException(string.Format(GeneralResources.Exception_UnknownLogicalOperatorSymbol, symbol.GetType())); } }
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); } }
internal void WhereBuilder_ValidateSymbolILogicalOperator_ValidProceeding_DoesnNotThrowException(ILogicalOperatorSymbol symbol, ISequenceSymbol nextSymbol) { // Act this._fixture.SequenceOfSymbolsValidator.ValidateSymbol(symbol, nextSymbol, 1); }