-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathConfigurationVisitorBehaviours.cs
81 lines (68 loc) · 2.54 KB
/
ConfigurationVisitorBehaviours.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq.Expressions;
using RefactorThis.GraphDiff.Tests.Models;
using System.Data.Entity;
using System.Linq;
namespace RefactorThis.GraphDiff.Tests.Tests
{
[TestClass]
public class ConfigurationVisitorBehaviours : TestBase
{
public Expression<Func<TestNode, OneToOneOwnedModel>> Lambda { get; set; }
[TestMethod]
public void ShouldBeAbleToVisitExpressionsStoredAsFields()
{
var node1 = new TestNode
{
Title = "One",
OneToOneOwned = new OneToOneOwnedModel { Title = "Hello" }
};
using (var context = new TestDbContext())
{
context.Nodes.Add(node1);
context.SaveChanges();
} // Simulate detach
node1.OneToOneOwned.Title = "Hey2";
Expression<Func<TestNode, OneToOneOwnedModel>> lambda = (p => p.OneToOneOwned);
Expression<Func<IUpdateConfiguration<TestNode>, dynamic>> exp = map => map.OwnedEntity(lambda);
using (var context = new TestDbContext())
{
// Setup mapping
context.UpdateGraph(node1, exp);
context.SaveChanges();
Assert.IsTrue(context.Nodes
.Include(p => p.OneToOneOwned)
.Single(p => p.Id == node1.Id)
.OneToOneOwned.Title == "Hey2");
}
}
[TestMethod]
public void ShouldBeAbleToVisitExpressionsStoredAsProperties()
{
var node1 = new TestNode
{
Title = "One",
OneToOneOwned = new OneToOneOwnedModel { Title = "Hello" }
};
using (var context = new TestDbContext())
{
context.Nodes.Add(node1);
context.SaveChanges();
} // Simulate detach
node1.OneToOneOwned.Title = "Hey2";
Lambda = (p => p.OneToOneOwned);
Expression<Func<IUpdateConfiguration<TestNode>, dynamic>> exp = map => map.OwnedEntity(Lambda);
using (var context = new TestDbContext())
{
// Setup mapping
context.UpdateGraph(node1, exp);
context.SaveChanges();
Assert.IsTrue(context.Nodes
.Include(p => p.OneToOneOwned)
.Single(p => p.Id == node1.Id)
.OneToOneOwned.Title == "Hey2");
}
}
}
}