-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathXafDomainComponents.cs
95 lines (74 loc) · 2.84 KB
/
XafDomainComponents.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
88
89
90
91
92
93
94
95
using DevExpress.Xpo;
using DevExtreme.AspNet.Data.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Xunit;
namespace DevExtreme.AspNet.Data.Tests.Xpo {
public class XafDomainComponents {
public abstract class DCBaseObject : XPCustomObject {
public DCBaseObject(Session session)
: base(session) {
}
[Key]
public Guid Oid { get; set; }
}
interface IMyComponent {
int Value { get; set; }
}
[Persistent(nameof(XafDomainComponents) + "_" + nameof(MyComponentImpl))]
public class MyComponentImpl : DCBaseObject, IMyComponent {
public MyComponentImpl(Session session)
: base(session) {
}
public int Value { get; set; }
}
const string
OID = "Oid",
LOCK_FILED = "OptimisticLockFieldInDataLayer";
[Fact]
public async Task Scenario() {
try {
CustomAccessorCompilers.Register((target, accessorText) => {
if(accessorText == OID) {
return Expression.Property(
Expression.Convert(target, typeof(DCBaseObject)),
OID
);
}
if(accessorText == LOCK_FILED) {
return Expression.Call(
Expression.Convert(target, typeof(PersistentBase)),
"GetPropertyValue",
null,
Expression.Constant(LOCK_FILED)
);
}
return null;
});
var key = Guid.NewGuid();
await UnitOfWorkHelper.ExecAsync(uow => {
uow.Save(new MyComponentImpl(uow) {
Oid = key,
Value = 123
});
uow.CommitChanges();
IQueryable<IMyComponent> interfaceQuery = uow.Query<MyComponentImpl>();
var loadResult = DataSourceLoader.Load(interfaceQuery, new SampleLoadOptions {
PrimaryKey = new[] { OID },
RemoteSelect = false,
PreSelect = new[] { OID, "Value", LOCK_FILED }
});
var item = loadResult.data.Cast<IDictionary<string, object>>().First();
Assert.Equal(key, item[OID]);
Assert.Equal(123, item["Value"]);
Assert.Equal(0, item[LOCK_FILED]);
});
} finally {
CustomAccessorCompilers.Clear();
}
}
}
}