-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathEntityFramework.cs
87 lines (79 loc) · 2.71 KB
/
EntityFramework.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.IO;
using System.Linq;
using Mvc.JQuery.DataTables;
using Mvc.JQuery.DataTables.Tests.DummyPocos;
using NUnit.Framework;
namespace Mvc.JQuery.DataTables.Tests.Fixtures
{
public class EntityFramework : Linq, IDisposable
{
public class TestConfiguration : DbConfiguration
{
public TestConfiguration()
{
var connectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", string.Empty,
$"Data Source=\"{DbFile}\";Password={Password}");
SetDefaultConnectionFactory(connectionFactory);
}
}
public class SomeContext : DbContext
{
public DbSet<SomeModel> Models { get; set; }
}
private SomeContext _dataContext;
protected SomeContext DataContext
{
get { return _dataContext; }
set
{
_dataContext = value;
SomeModelQueryable = (_dataContext==null)?null:_dataContext.Models.AsQueryable();
}
}
protected const string DbFile = "Test.sdf";
protected const string Password = "1234567890";
public EntityFramework()
{
var oldQueryable = SomeModelQueryable;
DataContext = new SomeContext();
DataContext.Database.Initialize(true);
foreach (var sm in oldQueryable)
{
DataContext.Models.Add(sm);
}
DataContext.SaveChanges();
}
//[Test, TestCaseSource(typeof(MyFactoryClass), "TestCases")]
public override int[] ExecuteParams(DataTablesParam dataTablesParam)
{
DataContext.Dispose(); //reset datacontext in order to clear local
DataContext = new SomeContext();
int[] returnVar = base.ExecuteParams(dataTablesParam);
Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory");
return returnVar;
}
#region IDisposable implementation
private bool _disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
if (DataContext != null) { DataContext.Dispose(); }
if (File.Exists(DbFile)) { File.Delete(DbFile); }
}
_disposed = true;
}
}
#endregion
}
}