|
| 1 | +using DevExpress.Xpo; |
| 2 | +using DevExtreme.AspNet.Data.Helpers; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Linq.Expressions; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace DevExtreme.AspNet.Data.Tests.Xpo { |
| 10 | + |
| 11 | + public class XafDomainComponents { |
| 12 | + |
| 13 | + public abstract class DCBaseObject : XPCustomObject { |
| 14 | + public DCBaseObject(Session session) |
| 15 | + : base(session) { |
| 16 | + } |
| 17 | + |
| 18 | + [Key] |
| 19 | + public Guid Oid { get; set; } |
| 20 | + } |
| 21 | + |
| 22 | + interface IMyComponent { |
| 23 | + int Value { get; set; } |
| 24 | + } |
| 25 | + |
| 26 | + [Persistent(nameof(XafDomainComponents) + "_" + nameof(MyComponentImpl))] |
| 27 | + public class MyComponentImpl : DCBaseObject, IMyComponent { |
| 28 | + |
| 29 | + public MyComponentImpl(Session session) |
| 30 | + : base(session) { |
| 31 | + } |
| 32 | + |
| 33 | + public int Value { get; set; } |
| 34 | + } |
| 35 | + |
| 36 | + const string |
| 37 | + OID = "Oid", |
| 38 | + LOCK_FILED = "OptimisticLockFieldInDataLayer"; |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void Scenario() { |
| 42 | + StaticBarrier.Run(delegate { |
| 43 | + CustomAccessorCompilers.Register((target, accessorText) => { |
| 44 | + if(accessorText == OID) { |
| 45 | + return Expression.Property( |
| 46 | + Expression.Convert(target, typeof(DCBaseObject)), |
| 47 | + OID |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + if(accessorText == LOCK_FILED) { |
| 52 | + return Expression.Call( |
| 53 | + Expression.Convert(target, typeof(PersistentBase)), |
| 54 | + "GetPropertyValue", |
| 55 | + null, |
| 56 | + Expression.Constant(LOCK_FILED) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + return null; |
| 61 | + }); |
| 62 | + |
| 63 | + var key = Guid.NewGuid(); |
| 64 | + |
| 65 | + UnitOfWorkHelper.Exec(uow => { |
| 66 | + uow.Save(new MyComponentImpl(uow) { |
| 67 | + Oid = key, |
| 68 | + Value = 123 |
| 69 | + }); |
| 70 | + |
| 71 | + uow.CommitChanges(); |
| 72 | + |
| 73 | + IQueryable<IMyComponent> interfaceQuery = uow.Query<MyComponentImpl>(); |
| 74 | + |
| 75 | + var loadResult = DataSourceLoader.Load(interfaceQuery, new SampleLoadOptions { |
| 76 | + PrimaryKey = new[] { OID }, |
| 77 | + RemoteSelect = false, |
| 78 | + PreSelect = new[] { OID, "Value", LOCK_FILED } |
| 79 | + }); |
| 80 | + |
| 81 | + var item = loadResult.data.Cast<IDictionary<string, object>>().First(); |
| 82 | + |
| 83 | + Assert.Equal(key, item[OID]); |
| 84 | + Assert.Equal(123, item["Value"]); |
| 85 | + Assert.Equal(0, item[LOCK_FILED]); |
| 86 | + }); |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + } |
| 91 | + |
| 92 | +} |
0 commit comments