Skip to content

Commit ef48cf0

Browse files
committed
Merge branch 'master' of github.com:mcintyre321/mvc.jquery.datatables
Conflicts: Mvc.JQuery.Datatables.sln.DotSettings.user Mvc.JQuery.Datatables/DataTablesResult.cs Mvc.JQuery.Datatables/TypeFilters.cs
2 parents d307de0 + 6bc3973 commit ef48cf0

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System.Data.Entity;
2+
using System.Data.Entity.Infrastructure;
3+
using System.IO;
4+
using Mvc.JQuery.Datatables;
5+
using NUnit.Framework;
6+
7+
namespace Mvc.JQuery.DataTables.Tests.EF
8+
{
9+
10+
11+
[TestFixture]
12+
public class EntityFramework
13+
{
14+
public class SomeContext : DbContext
15+
{
16+
public DbSet<SomeModel> Models { get; set; }
17+
}
18+
19+
protected const string DbFile = "test.sdf";
20+
protected const string Password = "1234567890";
21+
22+
[SetUp]
23+
public void InitTest()
24+
{
25+
DataContext = new SomeContext();
26+
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password));
27+
28+
DataContext.Database.Initialize(true);
29+
for (var i = 0; i < 100; i++)
30+
{
31+
DataContext.Models.Add(new SomeModel() {DisplayName = "Name " + i});
32+
33+
}
34+
DataContext.SaveChanges();
35+
}
36+
37+
protected SomeContext DataContext { get; set; }
38+
39+
[Test]
40+
public void ItMakesAppropriateQueries()
41+
{
42+
//arrange
43+
var source = DataContext.Models;
44+
var dataTablesParam = new DataTablesParam();
45+
dataTablesParam.iColumns = 2;
46+
dataTablesParam.bSearchable.Add(false);
47+
dataTablesParam.bSearchable.Add(true);
48+
49+
dataTablesParam.sSearch = "Name 10";
50+
51+
//act
52+
var result = new DataTablesResult<SomeModel, SomeModel>(source, dataTablesParam, model => model);
53+
var data = (DataTablesData) result.Data;
54+
55+
//assert
56+
//TODO: need to check that appropriate SQL queries are made somehow.
57+
58+
}
59+
60+
[TearDown]
61+
public void CleanupTest()
62+
{
63+
DataContext.Dispose();
64+
65+
if (File.Exists(DbFile))
66+
{
67+
File.Delete(DbFile);
68+
}
69+
}
70+
}
71+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Mvc.JQuery.DataTables.Tests.EF
4+
{
5+
public class SomeModel
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
public string DisplayName { get; set; }
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Mvc.JQuery.DataTables.Tests.EF
2+
{
3+
public class SomeView
4+
{
5+
public string Name { get; set; }
6+
}
7+
}

Mvc.Jquery.DataTables.Tests/Mvc.JQuery.DataTables.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<Compile Include="Fixtures\EntityFrameworkCe.cs" />
5959
<Compile Include="Fixtures\Linq.cs" />
6060
<Compile Include="Properties\AssemblyInfo.cs" />
61+
<Compile Include="EF\EntityFramework.cs" />
62+
<Compile Include="Properties\AssemblyInfo.cs" />
63+
<Compile Include="EF\SomeModel.cs" />
64+
<Compile Include="EF\SomeView.cs" />
6165
</ItemGroup>
6266
<ItemGroup>
6367
<None Include="App.config" />

0 commit comments

Comments
 (0)