public void GetSqlWhenValueIsNull() { var predicate = new FieldPredicate <TestEntity>() { Operator = Operator.Gt, PropertyName = "Id" }; var dictionary = new Dictionary <string, object>(); var sql = predicate.GetSql(SqlHelper.GetSqlGenerator(), dictionary); Assert.Equal("(Id IS NULL)", sql); }
public void GetSqlWhenValueIsEnumerableAndOperatorIsNotEqShouldThrowsException(Operator op) { var predicate = new FieldPredicate <TestEntity>() { Value = new[] { 2, 5 }, Operator = op, PropertyName = "Id" }; Assert.Throws <ArgumentException>(() => { predicate.GetSql(SqlHelper.GetSqlGenerator(), new Dictionary <string, object>()); }); }
public void GetSql() { var predicate = new FieldPredicate <TestEntity>() { Value = 2, Operator = Operator.Gt, PropertyName = "Id" }; var dictionary = new Dictionary <string, object>(); var sql = predicate.GetSql(SqlHelper.GetSqlGenerator(), dictionary); Assert.Equal("(Id > @Id_0)", sql); Assert.Equal(2, dictionary["@Id_0"]); }
public void GeneratingOperatorStrings(bool not, Operator @operator, string excepted) { var predicate = new FieldPredicate <TestEntity>() { Value = 2, Operator = @operator, PropertyName = "Id", Not = not }; var dictionary = new Dictionary <string, object>(); var sql = predicate.GetSql(SqlHelper.GetSqlGenerator(), dictionary); Assert.Equal($"(Id {excepted} @Id_0)", sql); Assert.Equal(2, dictionary["@Id_0"]); }
public void EnumerableThrowsException_If_Operator_Not_Eq() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Id", Value = new[] { 3, 4, 5 }, Not = false, Operator = Operator.Ge }; Dictionary <string, object> parameters = new Dictionary <string, object>(); var ex = Assert.Throws <ArgumentException>(() => pred.GetSql(parameters)); Assert.AreEqual("Operator must be set to Eq for Enumerable types", ex.Message); }
public void GetSqlWhenValueIsEnumerable() { var predicate = new FieldPredicate <TestEntity>() { Value = new[] { 2, 5 }, Operator = Operator.Eq, PropertyName = "Id" }; var dictionary = new Dictionary <string, object>(); var sql = predicate.GetSql(SqlHelper.GetSqlGenerator(), dictionary); Assert.Equal("(Id IN (@Id_0, @Id_1))", sql); Assert.Equal(2, dictionary["@Id_0"]); Assert.Equal(5, dictionary["@Id_1"]); }
public void Eq_ReturnsProperSql() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Id", Value = 3, Not = false, Operator = Operator.Eq }; Dictionary <string, object> parameters = new Dictionary <string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] = @Id_0)", result); Assert.AreEqual(3, parameters["@Id_0"]); }
public void LikeWithNot_ReturnsPropertySql() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Name", Value = "%foo", Not = true, Operator = Operator.Like }; Dictionary <string, object> parameters = new Dictionary <string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Name] NOT LIKE @Name_0)", result); Assert.AreEqual("%foo", parameters["@Name_0"]); }
public void EqWithNullAndNot_ReturnsProperSql() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Name", Value = null, Not = true, Operator = Operator.Eq }; Dictionary <string, object> parameters = new Dictionary <string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Name] IS NOT NULL)", result); Assert.AreEqual(0, parameters.Count); }
public void EqWithNot_EnumerableReturns_Proper_Sql() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Id", Value = new[] { 3, 4, 5 }, Not = true, Operator = Operator.Eq }; Dictionary <string, object> parameters = new Dictionary <string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] NOT IN (@Id_0, @Id_1, @Id_2))", result); Assert.AreEqual(3, parameters["@Id_0"]); Assert.AreEqual(4, parameters["@Id_1"]); Assert.AreEqual(5, parameters["@Id_2"]); }
public void Eq_ReturnsProperSqlWhenEnumerableOf_tring() { var pred = new FieldPredicate <PredicateTestEntity> { PropertyName = "Id", Value = new[] { "Alpha", "Beta", "Gamma", "Delta" }, Not = false, Operator = Operator.Eq }; Dictionary <string, object> parameters = new Dictionary <string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] IN (@Id_0, @Id_1, @Id_2, @Id_3))", result); Assert.AreEqual("Alpha", parameters["@Id_0"]); Assert.AreEqual("Beta", parameters["@Id_1"]); Assert.AreEqual("Gamma", parameters["@Id_2"]); Assert.AreEqual("Delta", parameters["@Id_3"]); }
public void Eq_EnumerableReturnsProperSql() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Id", Value = new[] {3, 4, 5}, Not = false, Operator = Operator.Eq }; Dictionary<string, object> parameters = new Dictionary<string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] IN (@Id_0, @Id_1, @Id_2))", result); Assert.AreEqual(3, parameters["@Id_0"]); Assert.AreEqual(4, parameters["@Id_1"]); Assert.AreEqual(5, parameters["@Id_2"]); }
public void EnumerableThrowsException_If_Operator_Not_Eq() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Id", Value = new[] {3, 4, 5}, Not = false, Operator = Operator.Ge }; Dictionary<string, object> parameters = new Dictionary<string, object>(); var ex = Assert.Throws<ArgumentException>(() => pred.GetSql(parameters)); Assert.AreEqual("Operator must be set to Eq for Enumerable types", ex.Message); }
public void EqWithNull_ReturnsPropertySql() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Name", Value = null, Not = false, Operator = Operator.Eq }; Dictionary<string, object> parameters = new Dictionary<string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Name] IS NULL)", result); Assert.AreEqual(0, parameters.Count); }
public void Eq_ReturnsProperSqlWhenEnumerableOf_tring() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Id", Value = new[] {"Alpha", "Beta", "Gamma", "Delta"}, Not = false, Operator = Operator.Eq }; Dictionary<string, object> parameters = new Dictionary<string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] IN (@Id_0, @Id_1, @Id_2, @Id_3))", result); Assert.AreEqual("Alpha", parameters["@Id_0"]); Assert.AreEqual("Beta", parameters["@Id_1"]); Assert.AreEqual("Gamma", parameters["@Id_2"]); Assert.AreEqual("Delta", parameters["@Id_3"]); }
public void Like_ReturnsPropertySql() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Name", Value = "%foo", Not = false, Operator = Operator.Like }; Dictionary<string, object> parameters = new Dictionary<string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Name] LIKE @Name_0)", result); Assert.AreEqual("%foo", parameters["@Name_0"]); }
public void Lt_ReturnsProperSql() { var pred = new FieldPredicate<PredicateTestEntity> { PropertyName = "Id", Value = 3, Not = false, Operator = Operator.Lt }; Dictionary<string, object> parameters = new Dictionary<string, object>(); string result = pred.GetSql(parameters); Assert.AreEqual("([PredicateTestEntity].[Id] < @Id_0)", result); Assert.AreEqual(3, parameters["@Id_0"]); }