public void CachedExpression_Can_Verify_Path_StartsWith_Predicate_In_Same_Result() { // Arrange // use a single cached expression for multiple expressions and ensure the correct output // is done for both of them. var cachedExpression = new CachedExpression(); Expression <Func <IContent, bool> > predicate1 = content => content.Path.StartsWith("-1"); cachedExpression.Wrap(predicate1); var modelToSqlExpressionHelper1 = new ModelToSqlExpressionVisitor <IContent>(SqlContext.SqlSyntax, Mappers); var result1 = modelToSqlExpressionHelper1.Visit(cachedExpression); Assert.AreEqual("upper([umbracoNode].[path]) LIKE upper(@0)", result1); Assert.AreEqual("-1%", modelToSqlExpressionHelper1.GetSqlParameters()[0]); Expression <Func <IContent, bool> > predicate2 = content => content.Path.StartsWith("-1,123,97"); cachedExpression.Wrap(predicate2); var modelToSqlExpressionHelper2 = new ModelToSqlExpressionVisitor <IContent>(SqlContext.SqlSyntax, Mappers); var result2 = modelToSqlExpressionHelper2.Visit(cachedExpression); Assert.AreEqual("upper([umbracoNode].[path]) LIKE upper(@0)", result2); Assert.AreEqual("-1,123,97%", modelToSqlExpressionHelper2.GetSqlParameters()[0]); }
public void WithCachedExpression() { for (int i = 0; i < 100; i++) { var a = i; var b = i * 10; Expression <Func <IContent, bool> > predicate = content => content.Path.StartsWith("-1") && content.Published && (content.ContentTypeId == a || content.ContentTypeId == b); var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor <IContent>(_syntaxProvider, _mapperCollection); //wrap it! _cachedExpression.Wrap(predicate); var result = modelToSqlExpressionHelper.Visit(_cachedExpression); } }