public static void Check(Expression criteria, string fieldName, object fieldValue, ValuePredicateType valuePredicateType, string subFieldName = null) { var assertingVisitor = new AssertingCriteriaVisitor(fieldName, fieldValue, valuePredicateType, subFieldName); assertingVisitor.Visit(criteria); Assert.IsTrue(assertingVisitor.FoundMatch, "Found no expression for {0} {1} {2}. Found: {3}".InvariantFormat(fieldName, valuePredicateType.ToString(), fieldValue, assertingVisitor.MatchesFound)); }
public void ContentViewModel_ContentType_Alias_NotEqualOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => x.ContentType.Alias != "NewsItem"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "Alias", "NewsItem", ValuePredicateType.NotEqual); }
public void ContentViewModel_FieldCastAsString_Equals() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => (string)x.Field("bodyText") == "frank"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "bodyText", "frank", ValuePredicateType.Equal); }
public void ContentViewModel_StringField_NotEqualsMethod_ViaUnaryExpression() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => !x.StringField("bodyText").Equals("frank")); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "bodyText", "frank", ValuePredicateType.NotEqual); }
public void ContentViewModel_FieldOfString_StartsWith() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => x.Field <string>("bodyText").StartsWith("frank")); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "bodyText", "frank", ValuePredicateType.StartsWith); }
public void ContentViewModel_NumberField_LessThanOrEqualToOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => x.NumberField("items") <= 2); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "items", 2, ValuePredicateType.LessThanOrEqual); }
public void TypedEntityModel_EntitySchema_EqualsOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContext <TypedEntity>(nullQueryableDataSource); var query = context.Where(x => x.EntitySchema.Alias == "NewsItem"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "Alias", "NewsItem", ValuePredicateType.Equal); }
public void TypedEntityModel_Id_EqualsOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContext <TypedEntity>(nullQueryableDataSource); var query = context.Where(x => x.Id == new HiveId(5)); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "Id", new HiveId(5), ValuePredicateType.Equal); }
public void TypedEntityModel_Attribute_WithSubFieldKey_EqualsOperator_ViaExtension() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContext <TypedEntity>(nullQueryableDataSource); var query = context.Where(x => x.Attribute <string>("items", "subItems") == "blah"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "items", "blah", ValuePredicateType.Equal, "subItems"); }
public void TypedEntityModel_Attribute_EqualsOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContext <TypedEntity>(nullQueryableDataSource); var query = context.Where(x => x.Attributes["items"].Values["default"] == (object)"blah"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "items", "blah", ValuePredicateType.Equal); }
public void ContentViewModel_StringField_EqualsOperator_AndAlso_StringField_NotEqualsOperator() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var query = context.Where(x => x.StringField("bodyText") == "frank" && x.StringField("title") != "bob"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "bodyText", "frank", ValuePredicateType.Equal); AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "title", "bob", ValuePredicateType.NotEqual); }
public void ContentViewModel_UtcCreated_SinglePredicateRange() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContentContext(nullQueryableDataSource); var dateTime = DateTimeOffset.Now; var query = context.Where(x => x.UtcCreated <= dateTime && x.UtcCreated >= dateTime); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "UtcCreated", dateTime, ValuePredicateType.GreaterThanOrEqual); }
public void UserGroup_WithDefaultSchemaForQueryingAttribute_Equals() { // Arrange var nullQueryableDataSource = new NullQueryableDataSource(); var context = GenerateContext <UserGroup>(nullQueryableDataSource); var query = context.Where(x => x.Attributes["items"].Values["default"] == (object)"blah"); // Act query.ToList(); var generatedQuery = nullQueryableDataSource.GeneratedQueryDescription; // Assert AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "Alias", UserGroupSchema.SchemaAlias, ValuePredicateType.Equal); AssertingCriteriaVisitor.Check(generatedQuery.Criteria, "items", "blah", ValuePredicateType.Equal); }