public void ApplyFiltering_GreaterThanBetweenTwoStringsInEF()
    {
        GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();

        var actual   = _ctx.Users.ApplyFiltering("name > h").ToList();
        var expected = _ctx.Users.Where(q => string.Compare(q.Name, "h") > 0).ToList();

        Assert.Equal(expected.Count, actual.Count);
        Assert.Equal(expected, actual);
        Assert.True(actual.Any());
    }
    public void ApplyFiltering_GeneratedSqlShouldCreateParameterizedQuery_SqlServerProvider()
    {
        GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();

        var name     = "vahid";
        var expected = _dbContext.Users.Where(q => q.Name == name).ToQueryString();

        var actual = _dbContext.Users.ApplyFiltering("name = vahid").ToQueryString();

        Assert.StartsWith("DECLARE @__Value", actual);
        Assert.StartsWith("DECLARE @__name", expected);
    }
    public void ApplyFiltering_GreaterThanBetweenTwoStringsInEF_SqlServerProvider_EnableCompatibilityLayer()
    {
        GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
        var sb = new StringBuilder();

        sb.AppendLine("DECLARE @__Value_0 nvarchar(4000) = N'h';");
        sb.AppendLine("SELECT [u].[Id], [u].[CreateDate], [u].[FkGuid], [u].[Name], [u].[shadow1]");
        sb.AppendLine("FROM [Users] AS [u]");
        sb.AppendLine("WHERE [u].[Name] > @__Value_0");

        var actual = _dbContext.Users.ApplyFiltering("name > h").ToQueryString();

        Assert.True(string.Compare(
                        sb.ToString(),
                        actual,
                        CultureInfo.CurrentCulture,
                        CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0);
    }
Beispiel #4
0
        [Fact] // Issue #58
        public void NestedCollectionFiltering_EntityFramework6_Or_NetFramework_ShouldNotThrowAnyExceptions()
        {
            var connection = GetConnection();

            var builder = new QueryBuilder <Customer>()
                          .AddMap("name2", q => q.SubCollection.Select(c => c.Name))
                          .AddCondition("name2=*X");

            // normal list (.NetFramework)
            var list = FakeCustomers().ToList();

            var actual2 = list.Where(q => q.SubCollection != null &&
                                     q.SubCollection.Any(w => w.Name.Contains("X"))).ToList();

            // this should have null checks like actual2
            // since EntityFrameworkCompatibilityLayer is disabled by default.
            var expected2 = builder.Build(list).ToList();

            Assert.True(actual2.Any());
            Assert.Equal(expected2.First(), actual2.First());
            Assert.Equal(expected2, actual2);

            // DbContext (EF6)
            GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
            using (var context = new EntityContext(connection))
            {
                var expected = builder.Build(context.Customers).ToList();

                var actual = context.Customers
                             .Where(q => q.SubCollection.Any(w => w.Name.Contains("X")))
                             .ToList();

                Assert.True(actual.Any());
                Assert.Equal(expected.First(), actual.First());
                Assert.Equal(expected, actual);
            }
        }
 public void ApplyFiltering_GreaterThanBetweenTwoStringsInEF_SqlServerProvider_ShouldThrowErrorWhenCompatibilityLayerIsDisabled()
 {
     GridifyGlobalConfiguration.DisableEntityFrameworkCompatibilityLayer();
     Assert.Throws <InvalidOperationException>(() => _dbContext.Users.ApplyFiltering("name > h").ToQueryString());
 }