Skip to content

Commit 5b5788d

Browse files
committed
Merge branch 'master' of github.com:mcintyre321/mvc.jquery.datatables
2 parents 1ae4ee2 + 368ed09 commit 5b5788d

File tree

10 files changed

+130
-212
lines changed

10 files changed

+130
-212
lines changed

Mvc.JQuery.Datatables/DataTablesResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class DataTablesResult<T, TRes> : DataTablesResult<TRes>
5858
Guard<IEnumerable<bool>>(s => s.ToArray()),
5959
Guard<IEnumerable<double>>(s => s.ToArray()),
6060
Guard<IEnumerable<object>>(s => s.Select(o => GetTransformedValue(o.GetType(), o)).ToArray()),
61+
Guard<bool>(s => s),
6162
Guard<object>(o => (o ?? "").ToString())
6263
};
6364

Mvc.JQuery.Datatables/TypeExtensions.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@
44
using System.Linq;
55
using System.Reflection;
66

7-
public static class TypeExtensions
7+
namespace Mvc.JQuery.Datatables
88
{
9-
public static IEnumerable<PropertyInfo> GetSortedProperties(this Type t)
9+
public static class TypeExtensions
1010
{
11-
return from pi in t.GetProperties()
12-
let da = (DisplayAttribute)pi.GetCustomAttributes(typeof(DisplayAttribute), false).SingleOrDefault()
13-
let order = ((da != null && da.Order != 0) ? da.Order : int.MaxValue)
14-
orderby order
15-
select pi;
16-
}
11+
public static IEnumerable<PropertyInfo> GetSortedProperties(this Type t)
12+
{
13+
return from pi in t.GetProperties()
14+
let da = (DisplayAttribute)pi.GetCustomAttributes(typeof(DisplayAttribute), false).SingleOrDefault()
15+
let order = ((da != null && da.GetOrder() != null && da.GetOrder() >= 0) ? da.Order : int.MaxValue)
16+
orderby order
17+
select pi;
18+
}
1719

18-
public static IEnumerable<PropertyInfo> GetSortedProperties<T>()
19-
{
20-
return typeof(T).GetSortedProperties();
21-
}
22-
public static IEnumerable<PropertyInfo> GetProperties(this Type t)
23-
{
24-
return from pi in t.GetProperties()
25-
select pi;
26-
}
20+
public static IEnumerable<PropertyInfo> GetSortedProperties<T>()
21+
{
22+
return typeof(T).GetSortedProperties();
23+
}
24+
public static IEnumerable<PropertyInfo> GetProperties(this Type t)
25+
{
26+
return from pi in t.GetProperties()
27+
select pi;
28+
}
2729

28-
public static IEnumerable<PropertyInfo> GetProperties<T>()
29-
{
30-
return typeof(T).GetSortedProperties();
30+
public static IEnumerable<PropertyInfo> GetProperties<T>()
31+
{
32+
return typeof(T).GetSortedProperties();
33+
}
3134
}
3235
}

Mvc.JQuery.Datatables/TypeFilters.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ public static string StringFilter(string q, string columnname, Type columntype,
9999
{
100100
if (q.StartsWith("^"))
101101
{
102-
return columnname + ".ToLower().StartsWith(\"" + q.ToLower().Replace("\"", "\"\"") + "\")";
102+
return "(!string.IsNullOrEmpty(" + columnname + ") && " + columnname + ".ToLower().StartsWith(\"" + q.ToLower().Replace("\"", "\"\"") + "\"))";
103103
}
104104
else
105105
{
106-
return columnname + ".ToLower().Contains(\"" + q.ToLower().Replace("\"", "\"\"") + "\")";
106+
return "(!string.IsNullOrEmpty(" + columnname + ") && " + columnname + ".ToLower().Contains(\"" + q.ToLower().Replace("\"", "\"\"") + "\"))";
107107
}
108108
}
109-
110109
}
111110
}

Mvc.Jquery.DataTables.Tests/EF/EntityFramework.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

Mvc.Jquery.DataTables.Tests/EF/SomeModel.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

Mvc.Jquery.DataTables.Tests/EF/SomeView.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,84 @@
11
using System.Data.Entity;
22
using System.Data.Entity.Infrastructure;
33
using System.IO;
4-
using Mvc.JQuery.Datatables;
54
using NUnit.Framework;
65
using System;
76
using System.Linq;
8-
using System.Collections.Generic;
7+
using Mvc.JQuery.Datatables;
98

109
namespace Mvc.JQuery.DataTables.Tests
1110
{
12-
public abstract class EntityFramework : Linq
11+
public class EntityFramework : Linq, IDisposable
1312
{
1413
public class SomeContext : DbContext
1514
{
1615
public DbSet<SomeModel> Models { get; set; }
1716
}
1817

19-
protected readonly SomeContext DataContext;
20-
21-
public EntityFramework(SomeContext dataContext)
18+
private readonly IDbConnectionFactory _defaultConnectionFactory;
19+
private SomeContext _dataContext;
20+
protected SomeContext DataContext
2221
{
23-
DataContext = dataContext;
24-
if (DataContext.Models.Any())
22+
get { return _dataContext; }
23+
set
2524
{
26-
DataContext.Database.ExecuteSqlCommand("DELETE FROM SomeModels");
25+
_dataContext = value;
26+
SomeModelQueryable = (_dataContext==null)?null:_dataContext.Models.AsQueryable();
2727
}
28-
foreach (var sm in SomeModelQueryable)
28+
}
29+
30+
protected const string DbFile = "Test.sdf";
31+
protected const string Password = "1234567890";
32+
33+
public EntityFramework()
34+
: this(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "",
35+
string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password))) { }
36+
37+
public EntityFramework(IDbConnectionFactory connectionFactory)
38+
{
39+
_defaultConnectionFactory = Database.DefaultConnectionFactory;
40+
Database.DefaultConnectionFactory = connectionFactory;
41+
var oldQueryable = SomeModelQueryable;
42+
DataContext = new SomeContext();
43+
DataContext.Database.Initialize(true);
44+
foreach (var sm in oldQueryable)
2945
{
3046
DataContext.Models.Add(sm);
3147
}
3248
DataContext.SaveChanges();
49+
}
3350

34-
SomeModelQueryable = DataContext.Models;
51+
[Test, TestCaseSource(typeof(MyFactoryClass), "TestCases")]
52+
public override int[] ExecuteParams(DataTablesParam dataTablesParam)
53+
{
54+
DataContext.Dispose(); //reset datacontext in order to clear local
55+
DataContext = new SomeContext();
56+
int[] returnVar = base.ExecuteParams(dataTablesParam);
57+
Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory");
58+
return returnVar;
59+
}
60+
61+
#region IDisposable implementation
62+
private bool _disposed = false;
63+
public void Dispose()
64+
{
65+
Dispose(true);
66+
GC.SuppressFinalize(this);
3567
}
3668

69+
protected virtual void Dispose(bool disposing)
70+
{
71+
if (!_disposed)
72+
{
73+
if (disposing)
74+
{
75+
if (DataContext != null) { DataContext.Dispose(); }
76+
if (File.Exists(DbFile)) { File.Delete(DbFile); }
77+
Database.DefaultConnectionFactory = _defaultConnectionFactory;
78+
}
79+
_disposed = true;
80+
}
81+
}
82+
#endregion
3783
}
3884
}

Mvc.Jquery.DataTables.Tests/Fixtures/EntityFrameworkCe.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)