public void GeneratesPostgresJsonValue() { // Arrange var sql = new JsonSqlExpression <Lead>(new PostgresSqlBuiler()); // Act var str = sql.Where(p => p.Data.LastName == "Foo").ToSql(out var parameters); // Assert Assert.Equal(" where (\"Data\"->>'LastName' = @p1)", str); Assert.Equal("p1", Assert.Single(parameters.ParameterNames)); }
public void GeneratesMySqlJsonValue() { // Arrange var sql = new JsonSqlExpression <Lead>(new MySqlSqlBuilder(), new DommelJsonOptions()); // Act var str = sql.Where(p => p.Data.LastName == "Foo").ToSql(out var parameters); // Assert Assert.Equal(" where (`Data`->'$.LastName' = @p1)", str); Assert.Equal("p1", Assert.Single(parameters.ParameterNames)); }
public void GeneratesSqlServerCeJsonValue() { // Arrange var sql = new JsonSqlExpression <Lead>(new SqlServerCeSqlBuilder()); // Act var str = sql.Where(p => p.Data.LastName == "Foo").ToSql(out var parameters); // Assert Assert.Equal(" where (JSON_VALUE([Data], '$.LastName') = @p1)", str); Assert.Equal("p1", Assert.Single(parameters.ParameterNames)); }
public void LikeOperandContains_WithConstant() { // Arrange var sqlExpression = new JsonSqlExpression <Lead>(new MySqlSqlBuilder(), new DommelJsonOptions()); // Act var expression = sqlExpression.Where(p => p.Data.FirstName !.Contains("test")); var sql = expression.ToSql(out var dynamicParameters); // Assert Assert.Equal("where (`Data`->'$.FirstName' like @p1)", sql.Trim()); Assert.Single(dynamicParameters.ParameterNames); Assert.Equal("%test%", dynamicParameters.Get <string>("p1")); }
public void LikeOperandEndsWith_WithVariable() { // Arrange var sqlExpression = new JsonSqlExpression <Lead>(new MySqlSqlBuilder(), new DommelJsonOptions()); var substring = "test"; // Act var expression = sqlExpression.Where(p => p.Data.FirstName !.EndsWith(substring)); var sql = expression.ToSql(out var dynamicParameters); // Assert Assert.Equal("where (lower(`Data`->'$.FirstName') like lower(@p1))", sql.Trim()); Assert.Single(dynamicParameters.ParameterNames); Assert.Equal("%test", dynamicParameters.Get <string>("p1")); }