public void PersistAndFind() { var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(eb1.RowKey.Equals(Guid.Empty)); em.Persist(eb2); Assert.IsFalse(eb2.RowKey.Equals(Guid.Empty)); Assert.IsFalse(eb2.A.RowKey.Equals(Guid.Empty)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.RowKey); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityA>(eb2.A.RowKey); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityB>(eb2.RowKey); Assert.AreEqual(eb2, _eb2); } }
public void FetchByScanSpec() { var ec1 = new EntityC { A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY() }; TestBase.TestSerialization(ec1); var ex21 = new EntityX2(); TestBase.TestSerialization(ex21); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); em.Persist(ex21); } using (var em = Emf.CreateEntityManager()) { var _ec = em.Fetch <EntityC>(new ScanSpec(ec1.Id)); Assert.IsNotNull(_ec); Assert.AreEqual(1, _ec.Count()); Assert.AreEqual(ec1, _ec.First()); var ss = new ScanSpec(); ss.AddColumn("a"); var _ex = em.Fetch <EntityXBase>(ss); Assert.IsNotNull(_ex); Assert.AreEqual(2, _ex.Count()); Assert.AreEqual(ec1.X, _ex.OfType <EntityX>().First()); Assert.AreEqual(ex21, _ex.OfType <EntityX2>().First()); } }
public void Find() { var ec1 = new EntityC(); TestBase.TestSerialization(ec1); var ec2 = new EntityC(); TestBase.TestSerialization(ec2); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); em.Persist(ec2); Assert.IsFalse(string.IsNullOrEmpty(ec2.Id)); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>(ec1.Id); Assert.AreEqual(ec1, _ec1); var _ec2 = em.Find <EntityC>(ec2.Id); Assert.AreEqual(ec2, _ec2); } }
public void Fetch() { var eb1 = new EntityBX(); TestBase.TestSerialization(eb1); var eb2 = new EntityBX { A = new EntityAX() }; TestBase.TestSerialization(eb2); var eb21 = new EntityB2X(); TestBase.TestSerialization(eb21); var eb22 = new EntityB2X { A = new EntityA2X() }; TestBase.TestSerialization(eb22); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); em.Persist(eb2); em.Persist(eb21); em.Persist(eb22); } using (var em = Emf.CreateEntityManager()) { var _ea = em.Fetch <EntityAX>(); Assert.IsNotNull(_ea); ISet <EntityAX> sax = new HashSet <EntityAX>(_ea.ToList()); Assert.AreEqual(2, sax.Count); Assert.IsTrue(sax.Contains(eb2.A)); Assert.IsTrue(sax.Contains(eb22.A)); { var _eb = em.Fetch <EntityBX>(); Assert.IsNotNull(_eb); ISet <EntityBX> sbx = new HashSet <EntityBX>(_eb.ToList()); Assert.AreEqual(4, sbx.Count); Assert.IsTrue(sbx.Contains(eb1)); Assert.IsTrue(sbx.Contains(eb2)); Assert.IsTrue(sbx.Contains(eb21)); Assert.IsTrue(sbx.Contains(eb22)); } { var _eb = em.Fetch <EntityB2X>(); Assert.IsNotNull(_eb); ISet <EntityB2X> sbx = new HashSet <EntityB2X>(_eb.ToList()); Assert.AreEqual(2, sbx.Count); Assert.IsTrue(sbx.Contains(eb21)); Assert.IsTrue(sbx.Contains(eb22)); } } }
public void PersistChildren() { var ec1 = new EntityC(); TestBase.TestSerialization(ec1); var ec2 = new EntityC { A = new EntityA(), B = new EntityB() }; TestBase.TestSerialization(ec2); var ec3 = new EntityC { X = new EntityX(), Y = new EntityY() }; TestBase.TestSerialization(ec3); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); em.Persist(ec2); Assert.IsFalse(string.IsNullOrEmpty(ec2.Id)); Assert.IsFalse(ec2.A.Id.Equals(Guid.Empty)); Assert.IsFalse(ec2.B.Id.Equals(Guid.Empty)); em.Persist(ec3); Assert.IsFalse(string.IsNullOrEmpty(ec3.Id)); Assert.IsFalse(string.IsNullOrEmpty(ec3.X.Id)); Assert.IsFalse(string.IsNullOrEmpty(ec3.Y.Id)); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>(ec1.Id); Assert.AreEqual(ec1, _ec1); var _ea2 = em.Find <EntityA>(ec2.A.Id); Assert.AreEqual(ec2.A, _ea2); var _eb2 = em.Find <EntityB>(ec2.B.Id); Assert.AreEqual(ec2.B, _eb2); var _ec2 = em.Find <EntityC>(ec2.Id); Assert.AreEqual(ec2, _ec2); var _ex3 = em.Find <EntityX>(ec3.X.Id); Assert.AreEqual(ec3.X, _ex3); var _ey3 = em.Find <EntityY>(ec3.Y.Id); Assert.AreEqual(ec3.Y, _ey3); var _ec3 = em.Find <EntityC>(ec3.Id); Assert.AreEqual(ec3, _ec3); } }
public void PersistLoggingMaxPerformance() { if (IsOdbc) { return; //TODO temporary skipped } var ea = new EntityA(); TestBase.TestSerialization(ea); var eb = new EntityB(); TestBase.TestSerialization(eb); var rng = new Random(); for (var j = 0; j < 5; ++j) { using (var em = Emf.CreateEntityManager()) { var mutatorSpec = new MutatorSpec(MutatorKind.Chunked) { Queued = true, //// MaxCellCount = 8 * 1024, MaxChunkSize = 64 * 1024, FlushEachChunk = true, Capacity = 32768 }; using (var ma = em.GetTable <EntityA>().CreateMutator(mutatorSpec)) using (var mb = em.GetTable <EntityB>().CreateMutator(mutatorSpec)) { for (var i = 0; i < 100000; ++i) { ea = new EntityA(); rng.NextBytes(ea.Value); ma.Set(new Key { ColumnFamily = "a" }, Serializer.ToByteArray(ea), true); eb = new EntityB(); rng.NextBytes(eb.Value); mb.Set(new Key { ColumnFamily = "b" }, Serializer.ToByteArray(ea), true); } } } } }
public void FindMany() { var ec1 = new EntityC(); TestBase.TestSerialization(ec1); var ec2 = new EntityC(); TestBase.TestSerialization(ec2); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); em.Persist(ec2); Assert.IsFalse(string.IsNullOrEmpty(ec2.Id)); } using (var em = Emf.CreateEntityManager()) { { var _ec = em.FindMany <EntityC>(new[] { ec1.Id, ec2.Id }); Assert.IsNotNull(_ec); var l = _ec.ToList(); Assert.AreEqual(ec1, l[0]); Assert.AreEqual(ec2, l[1]); } { var _ec = em.FindMany <EntityC>(new[] { ec1.Id, ec2.Id, ec2.Id, ec1.Id }); Assert.IsNotNull(_ec); var l = _ec.ToList(); Assert.AreEqual(ec1, l[0]); Assert.AreEqual(ec2, l[1]); Assert.AreEqual(ec2, l[2]); Assert.AreEqual(ec1, l[3]); } { var _ec = em.FindMany <EntityBase>(new[] { ec1.Id, ec2.Id, ec2.Id, ec1.Id }); Assert.IsNotNull(_ec); var l = _ec.ToList(); Assert.AreEqual(ec1, l[0]); Assert.AreEqual(ec2, l[1]); Assert.AreEqual(ec2, l[2]); Assert.AreEqual(ec1, l[3]); } } }
public void PersistAndFind() { var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier)); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier)); Assert.IsNotNull(eb2.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb2.A.Key.ColumnQualifier)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityA>(eb2.A.Key); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); } }
public void PersistLogging() { if (IsOdbc) { return; //TODO temporary skipped } var ea = new EntityA(); TestBase.TestSerialization(ea); var eb = new EntityB(); TestBase.TestSerialization(eb); for (var j = 0; j < 5; ++j) { using (var em = Emf.CreateEntityManager()) { em.Configuration.MutatorSpec = new MutatorSpec(MutatorKind.Chunked) { Queued = true, //// MaxCellCount = 8 * 1024, MaxChunkSize = 64 * 1024, FlushEachChunk = true, Capacity = 32768 }; for (var i = 0; i < 100000; ++i) { ea = new EntityA(); Rng.Instance.NextBytes(ea.Value); em.Persist(ea, Behaviors.CreateNew | Behaviors.DoNotCache); eb = new EntityB(); Rng.Instance.NextBytes(eb.Value); em.Persist(eb, Behaviors.CreateNew | Behaviors.DoNotCache); } } } }
public void PersistAndFind() { var p = new Parent("0"); p.Children.Add(new Child("X")); p.Children.Add(new Child("Y")); p.Children.Add(new Child("Z")); TestBase.TestSerialization(p); using (var em = Emf.CreateEntityManager()) { em.Persist(p, Behaviors.CreateNew); Assert.AreEqual("0", p.Id); Assert.AreEqual("X", p.Children[0].Id); Assert.AreEqual("Y", p.Children[1].Id); Assert.AreEqual("Z", p.Children[2].Id); } using (var em = Emf.CreateEntityManager()) { var _p = em.Find <Parent>(p.Id); Assert.AreEqual(p, _p); } using (var em = Emf.CreateEntityManager()) { var _b = em.Fetch <Base>(new[] { typeof(Parent), typeof(Child) }); var _p = _b.OfType <Parent>().First(); Assert.AreEqual(p, _p); var i = 0; foreach (var c in _b.OfType <Child>().OrderBy(c => c.Id)) { Assert.AreEqual(p.Children[i], c); Assert.AreSame(_p.Children[i++], c); } } }
public void PersistAndFind() { var ea1 = new EntityA { X = 1, Y = 2, Z = 3 }; TestBase.TestSerialization(ea1); var ea2 = new EntityA { X = 4, Y = 5, Z = 6 }; TestBase.TestSerialization(ea2); var eb1 = new EntityB { A = ea1, B = ea2 }; TestBase.TestSerialization(eb1); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.A.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.B.Id)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); } eb1 = new EntityB { A = ea1, B = ea2, C = ea1 }; TestBase.TestSerialization(eb1); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.A.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.B.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.C.Id)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); } eb1 = new EntityB { A = ea1, B = ea1, C = ea2 }; TestBase.TestSerialization(eb1); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.A.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.B.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.C.Id)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); } eb1 = new EntityB { A = ea1, B = ea1, C = ea1 }; TestBase.TestSerialization(eb1); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.A.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.B.Id)); Assert.IsFalse(string.IsNullOrEmpty(eb1.C.Id)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); } }
public void PersistBehaviors() { { var ea1 = new EntityA(); TestBase.TestSerialization(ea1); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = ea1 }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(ea1); em.Persist(eb1); em.Persist(eb2); } using (var em = Emf.CreateEntityManager()) { Assert.AreEqual(1, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); var _ea1 = em.Find <EntityA>(ea1.RowKey); Assert.AreEqual(ea1, _ea1); var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); var _ea2 = em.Find <EntityA>(eb2.A.RowKey); Assert.AreEqual(ea1, _ea2); } TestBase.ClearNamespace(); using (var em = Emf.CreateEntityManager()) { em.Persist(ea1); } using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); em.Persist(eb2); } using (var em = Emf.CreateEntityManager()) { Assert.AreEqual(2, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); var _ea1 = em.Find <EntityA>(ea1.RowKey); Assert.AreEqual(ea1, _ea1); var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); var _ea2 = em.Find <EntityA>(eb2.A.RowKey); Assert.AreEqual(eb2.A, _ea2); } TestBase.ClearNamespace(); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateLazy); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateLazy); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateLazy); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateLazy); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateLazy); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateLazy); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(1, ida.Count); Assert.AreEqual(2, idb.Count); em.Flush(); Assert.AreEqual(1, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); } TestBase.ClearNamespace(); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateAlways); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateAlways); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateAlways); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateAlways); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateAlways); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateAlways); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(4, ida.Count); Assert.AreEqual(4, idb.Count); em.Flush(); Assert.AreEqual(4, em.Fetch <EntityA>().Count()); Assert.AreEqual(4, em.Fetch <EntityB>().Count()); } TestBase.ClearNamespace(); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateNew); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateNew); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateNew); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateNew); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateNew); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateNew); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(1, ida.Count); Assert.AreEqual(2, idb.Count); em.Flush(); Assert.AreEqual(1, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); } } TestBase.ClearNamespace(); { var ea1 = new EntityA(); TestBase.TestSerialization(ea1); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = ea1 }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateLazy); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateLazy); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateLazy); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateLazy); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateLazy); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateLazy); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(1, ida.Count); Assert.AreEqual(2, idb.Count); em.Flush(); Assert.AreEqual(1, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); } } TestBase.ClearNamespace(); { var ea1 = new EntityA(); TestBase.TestSerialization(ea1); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = ea1 }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateAlways); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateAlways); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateAlways); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateAlways); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateAlways); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateAlways); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(4, ida.Count); Assert.AreEqual(4, idb.Count); em.Flush(); Assert.AreEqual(4, em.Fetch <EntityA>().Count()); Assert.AreEqual(4, em.Fetch <EntityB>().Count()); } } TestBase.ClearNamespace(); { var ea1 = new EntityA(); TestBase.TestSerialization(ea1); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = ea1 }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { var ida = new HashSet <string>(); var idb = new HashSet <string>(); em.Persist(ea1, Behaviors.CreateNew); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateNew); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateNew); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); em.Persist(ea1, Behaviors.CreateNew); ida.Add(ea1.RowKey); em.Persist(eb1, Behaviors.CreateNew); idb.Add(eb1.Key.Row); em.Persist(eb2, Behaviors.CreateNew); idb.Add(eb2.Key.Row); ida.Add(eb2.A.RowKey); Assert.AreEqual(1, ida.Count); Assert.AreEqual(2, idb.Count); em.Flush(); Assert.AreEqual(1, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); } } }
public void Fetch() { var ec1 = new EntityC { A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY() }; TestBase.TestSerialization(ec1); var ec2 = new EntityC { A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY() }; TestBase.TestSerialization(ec2); var ex1 = new EntityX(); TestBase.TestSerialization(ex1); var ex2 = new EntityX(); TestBase.TestSerialization(ex2); var ex21 = new EntityX2(); TestBase.TestSerialization(ex21); var ex22 = new EntityX2(); TestBase.TestSerialization(ex22); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); em.Persist(ec2); em.Persist(ex1); em.Persist(ex2); em.Persist(ex21); em.Persist(ex22); } using (var em = Emf.CreateEntityManager()) { { var _ec = em.Fetch <EntityC>(); Assert.IsNotNull(_ec); ISet <EntityC> s = new HashSet <EntityC>(_ec.ToList()); Assert.AreEqual(2, s.Count); Assert.IsTrue(s.Contains(ec1)); Assert.IsTrue(s.Contains(ec2)); } { var _ec = em.Fetch <EntityBase>(new[] { typeof(EntityC) }); Assert.IsNotNull(_ec); ISet <EntityBase> s = new HashSet <EntityBase>(_ec.ToList()); Assert.AreEqual(2, s.Count); Assert.IsTrue(s.Contains(ec1)); Assert.IsTrue(s.Contains(ec2)); } Assert.AreEqual(2, em.Fetch <EntityA>().Count()); Assert.AreEqual(2, em.Fetch <EntityB>().Count()); Assert.AreEqual(2, em.Fetch <EntityC>().Count()); Assert.AreEqual(4, em.Fetch <EntityX>().Count()); Assert.AreEqual(2, em.Fetch <EntityX2>().Count()); Assert.AreEqual(6, em.Fetch <EntityXBase>().Count()); Assert.AreEqual(2, em.Fetch <EntityY>().Count()); Assert.AreEqual(10, em.Fetch <EntityBase>().Count()); Assert.AreEqual(6, em.Fetch <EntityBase>(new[] { typeof(EntityX), typeof(EntityX2) }).Count()); Assert.AreEqual(2, em.Fetch <EntityBase>(new[] { typeof(EntityY) }).Count()); // pre-fetch // TODOAssert.AreEqual(2, em.Fetch<EntityC>(new[] { typeof(EntityC), typeof(EntityX), typeof(EntityY) }).Count()); } }
public void PersistAndFind() { { var ec1 = new EntityC(); TestBase.TestSerialization(ec1); var ey = new EntityY(); var ec2 = new EntityC { X = new[] { new EntityX(), new EntityX() }, Y = new[] { ey, ey }, Y2 = ey }; TestBase.TestSerialization(ec2); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); em.Persist(ec2); Assert.IsFalse(string.IsNullOrEmpty(ec2.Id)); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>(ec1.Id); Assert.AreEqual(ec1, _ec1); var _ec2 = em.Find <EntityC>(ec2.Id); Assert.AreEqual(ec2, _ec2); Assert.AreSame(_ec2.Y[0], _ec2.Y[1]); Assert.AreSame(_ec2.Y2, _ec2.Y[0]); } } { var ed1 = new EntityD(); TestBase.TestSerialization(ed1); var ey = new EntityY(); var ed2 = new EntityD { X = new HashSet <EntityX>(new[] { new EntityX(), new EntityX() }), Y = new HashSet <EntityY>(new[] { ey, new EntityY() }), Y2 = ey }; TestBase.TestSerialization(ed2); using (var em = Emf.CreateEntityManager()) { em.Persist(ed1); Assert.IsFalse(string.IsNullOrEmpty(ed1.Id)); em.Persist(ed2); Assert.IsFalse(string.IsNullOrEmpty(ed2.Id)); } using (var em = Emf.CreateEntityManager()) { var _ed1 = em.Find <EntityD>(ed1.Id); Assert.AreEqual(ed1, _ed1); var _ed2 = em.Find <EntityD>(ed2.Id); Assert.AreEqual(ed2, _ed2); Assert.IsNotNull(_ed2.Y.FirstOrDefault(item => object.ReferenceEquals(item, _ed2.Y2))); } } { var ee1 = new EntityE(); TestBase.TestSerialization(ee1); var ey = new EntityY(); var ee2 = new EntityE { X = new List <EntityX>(new[] { new EntityX(), new EntityX() }), Y = new List <EntityY>(new[] { ey, ey }), Y2 = ey }; TestBase.TestSerialization(ee2); using (var em = Emf.CreateEntityManager()) { em.Persist(ee1); Assert.IsFalse(string.IsNullOrEmpty(ee1.Id)); em.Persist(ee2); Assert.IsFalse(string.IsNullOrEmpty(ee2.Id)); } using (var em = Emf.CreateEntityManager()) { var _ee1 = em.Find <EntityE>(ee1.Id); Assert.AreEqual(ee1, _ee1); var _ee2 = em.Find <EntityE>(ee2.Id); Assert.AreEqual(ee2, _ee2); Assert.AreSame(_ee2.Y[0], _ee2.Y[1]); Assert.AreSame(_ee2.Y2, _ee2.Y[0]); } } { var ef1 = new EntityF(); TestBase.TestSerialization(ef1); var ey = new EntityY(); var ef2 = new EntityF { X = new ArrayList(new[] { new EntityX(), new EntityX() }), Y = new ArrayList(new[] { ey, ey }), Y2 = ey }; TestBase.TestSerialization(ef2); using (var em = Emf.CreateEntityManager()) { em.Persist(ef1); Assert.IsFalse(string.IsNullOrEmpty(ef1.Id)); em.Persist(ef2); Assert.IsFalse(string.IsNullOrEmpty(ef2.Id)); } using (var em = Emf.CreateEntityManager()) { var _ef1 = em.Find <EntityF>(ef1.Id); Assert.AreEqual(ef1, _ef1); var _ef2 = em.Find <EntityF>(ef2.Id); Assert.AreEqual(ef2, _ef2); Assert.AreSame(_ef2.Y[0], _ef2.Y[1]); Assert.AreSame(_ef2.Y2, _ef2.Y[0]); } } }
public void PersistAndFind() { var eb1 = new EntityBX(); TestBase.TestSerialization(eb1); var eb2 = new EntityBX { A = new EntityAX() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.AreEqual("b", eb1.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier)); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.AreEqual("b", eb2.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier)); Assert.IsNotNull(eb2.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row)); Assert.AreEqual("a", eb2.A.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb2.A.Key.ColumnQualifier)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityBX>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityAX>(eb2.A.Key); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityBX>(eb2.Key); Assert.AreEqual(eb2, _eb2); Assert.AreEqual(2, em.Fetch <EntityBX>().Count()); Assert.AreEqual(1, em.Fetch <EntityAX>().Count()); Assert.AreEqual(3, em.Fetch <EntityBaseX>().Count()); Assert.AreEqual(2, em.Fetch <IEntityBx>().Count()); Assert.AreEqual(3, em.Fetch <EntityBaseX>(new[] { typeof(EntityBX), typeof(EntityAX) }).Count()); } var eb21 = new EntityB2X(); TestBase.TestSerialization(eb21); var eb22 = new EntityB2X { A = new EntityA2X() }; TestBase.TestSerialization(eb22); using (var em = Emf.CreateEntityManager()) { em.Persist(eb21); Assert.IsNotNull(eb21.Key); Assert.IsFalse(string.IsNullOrEmpty(eb21.Key.Row)); Assert.AreEqual("b", eb21.Key.ColumnFamily); Assert.AreEqual("bx", eb21.Key.ColumnQualifier); em.Persist(eb22); Assert.IsNotNull(eb22.Key); Assert.IsFalse(string.IsNullOrEmpty(eb22.Key.Row)); Assert.AreEqual("b", eb22.Key.ColumnFamily); Assert.AreEqual("bx", eb22.Key.ColumnQualifier); Assert.IsNotNull(eb22.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb22.A.Key.Row)); Assert.AreEqual("a", eb22.A.Key.ColumnFamily); Assert.AreEqual("a2x", eb22.A.Key.ColumnQualifier); } using (var em = Emf.CreateEntityManager()) { var _eb21 = em.Find <EntityBX>(eb21.Key); Assert.IsInstanceOfType(_eb21, typeof(EntityB2X)); Assert.AreEqual(eb21, _eb21); var _ea22 = em.Find <EntityAX>(eb22.A.Key); Assert.IsInstanceOfType(_ea22, typeof(EntityA2X)); Assert.AreEqual(eb22.A, _ea22); var _eb22 = em.Find <EntityBX>(eb22.Key); Assert.IsInstanceOfType(_eb22, typeof(EntityB2X)); Assert.AreEqual(eb22, _eb22); Assert.AreEqual(1, em.Fetch <EntityA2X>().Count()); Assert.AreEqual(2, em.Fetch <EntityAX>().Count()); Assert.AreEqual(2, em.Fetch <EntityB2X>().Count()); Assert.AreEqual(4, em.Fetch <EntityBX>().Count()); Assert.AreEqual(4, em.Fetch <IEntityBx>().Count()); Assert.AreEqual(6, em.Fetch <EntityBaseX>().Count()); Assert.AreEqual(6, em.Fetch <EntityBaseX>(new[] { typeof(EntityBX), typeof(EntityAX) }).Count()); } }
public void PersistAndFind() { var bindings = Emf.Configuration.Binding; Assert.IsTrue(bindings.RegisterKeyBinding(typeof(EntityA), new KeyBindingEntityA())); Assert.IsFalse(bindings.RegisterKeyBinding(typeof(EntityA), new KeyBindingEntityA())); Assert.IsTrue(bindings.RegisterKeyBinding(typeof(EntityB), new KeyBindingEntityB())); { var cb = new ColumnBinding("e"); Assert.IsTrue(bindings.RegisterColumnBinding(typeof(EntityC), cb)); Assert.IsTrue(bindings.RegisterKeyBinding(typeof(EntityC), new KeyBinding <EntityC>(e => e.Name))); } var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier)); Assert.IsTrue(eb1.Key.Row.StartsWith(typeof(EntityB).Name)); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier)); Assert.IsTrue(eb2.Key.Row.StartsWith(typeof(EntityB).Name)); Assert.IsTrue(eb2.A.Name.StartsWith(typeof(EntityA).Name)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); Assert.IsTrue(_eb1.Key.Row.StartsWith(_eb1.GetType().Name)); var _ea2 = em.Find <EntityA>(eb2.A.Name); // EntityA key binding uses the Name property as row key Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); Assert.IsTrue(_eb2.Key.Row.StartsWith(typeof(EntityB).Name)); Assert.AreEqual(eb2.A.Name, _eb2.A.Name); Assert.IsTrue(eb2.A.Name.StartsWith(typeof(EntityA).Name)); } var ec1 = new EntityC { Name = "11", A = new EntityA() }; TestBase.TestSerialization(ec1); var ec2 = new EntityC { Name = "222", A = new EntityA(), B = new EntityB() }; TestBase.TestSerialization(ec2); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.AreEqual(ec1.Id, ec1.Name); em.Persist(ec2); Assert.AreEqual(ec2.Id, ec2.Name); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>("11"); Assert.AreEqual(ec1, _ec1); var _ec2 = em.Find <EntityC>(ec2); Assert.AreEqual(ec2, _ec2); } bindings.UnregisterBinding(typeof(EntityA)); bindings.UnregisterBinding(typeof(EntityB)); bindings.UnregisterBinding(typeof(EntityC)); }
public void PersistAndFind() { var bindingContext = new BindingContext(); Assert.IsFalse(bindingContext.StrictExplicitColumnBinding); Assert.IsFalse(bindingContext.StrictExplicitKeyBinding); Assert.IsFalse(bindingContext.StrictExplicitTableBinding); bindingContext.StrictExplicitColumnBinding = true; Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA())); Assert.IsFalse(bindingContext.RegisterColumnBinding(typeof(EntityA), new ColumnBindingEntityA())); Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityB), new ColumnBinding("b", "qb"))); Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC1), new ColumnBinding("c", "1"))); Assert.IsTrue(bindingContext.RegisterColumnBinding(typeof(EntityC2), new ColumnBinding("c", "2"))); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); var ec1 = new EntityC1 { A = new EntityA() }; TestBase.TestSerialization(ec1); var ec2 = new EntityC2 { A = new EntityA() }; TestBase.TestSerialization(ec2); using (var em = Emf.CreateEntityManager(bindingContext)) { Assert.IsTrue(em.IsTypeDeclared <EntityA>()); Assert.IsTrue(em.IsTypeDeclared <EntityB>()); Assert.IsTrue(em.IsTypeDeclared <EntityC1>()); Assert.IsTrue(em.IsTypeDeclared <EntityC2>()); em.Configuration.Binding.StrictExplicitColumnBinding = true; em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.AreEqual("b", eb1.Key.ColumnFamily); Assert.AreEqual("qb", eb1.Key.ColumnQualifier); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.AreEqual("b", eb2.Key.ColumnFamily); Assert.AreEqual("qb", eb2.Key.ColumnQualifier); Assert.IsNotNull(eb2.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row)); Assert.AreEqual("a", eb2.A.Key.ColumnFamily); Assert.AreEqual("qa", eb2.A.Key.ColumnQualifier); em.Persist(ec1); Assert.IsNotNull(ec1.Key); Assert.IsFalse(string.IsNullOrEmpty(ec1.Key.Row)); Assert.AreEqual("c", ec1.Key.ColumnFamily); Assert.AreEqual("1", ec1.Key.ColumnQualifier); em.Persist(ec2); Assert.IsNotNull(ec2.Key); Assert.IsFalse(string.IsNullOrEmpty(ec2.Key.Row)); Assert.AreEqual("c", ec2.Key.ColumnFamily); Assert.AreEqual("2", ec2.Key.ColumnQualifier); } using (var em = Emf.CreateEntityManager(bindingContext)) { var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityA>(eb2.A.Key); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); var _ec1 = em.Find <EntityC1>(ec1.Key); Assert.AreEqual(ec1, _ec1); var _ec2 = em.Find <EntityC2>(ec2.Key); Assert.AreEqual(ec2, _ec2); var ecl = em.Fetch <EntityC>().ToList(); Assert.AreEqual(2, ecl.Count); Assert.IsTrue(ecl.Contains(_ec1)); Assert.IsTrue(ecl.Contains(_ec2)); } Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityA))); Assert.IsFalse(bindingContext.UnregisterColumnBinding(typeof(EntityA))); Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityB))); Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC1))); Assert.IsTrue(bindingContext.UnregisterColumnBinding(typeof(EntityC2))); }
public void PersistAndFind() { var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); var ec1 = new EntityC { A = new EntityA() }; TestBase.TestSerialization(ec1); var dateTime = DateTime.UtcNow - TimeSpan.FromMilliseconds(250); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); Assert.AreEqual(0, eb1.LastModified.Ticks); em.Persist(eb2); Assert.IsFalse(string.IsNullOrEmpty(eb2.Id)); Assert.IsFalse(eb2.A.Id.Equals(Guid.Empty)); Assert.AreEqual(0, eb2.LastModified.Ticks); Assert.AreEqual(0, eb2.A.LastModified.Ticks); em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); Assert.IsFalse(ec1.A.Id.Equals(Guid.Empty)); Assert.AreEqual(0, ec1.LastModified.Ticks); Assert.AreEqual(0, ec1.A.LastModified.Ticks); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); Assert.IsTrue(_eb1.LastModified > dateTime); var _ea2 = em.Find <EntityA>(eb2.A.Id); Assert.AreEqual(eb2.A, _ea2); Assert.IsTrue(_ea2.LastModified > dateTime); var _eb2 = em.Find <EntityB>(eb2.Id); Assert.AreEqual(eb2, _eb2); Assert.IsTrue(_eb2.LastModified > dateTime); Assert.IsTrue(_eb2.A.LastModified > dateTime); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>(ec1.Id); Assert.AreEqual(ec1, _ec1); Assert.IsTrue(_ec1.LastModified > dateTime); Assert.IsTrue(_ec1.A.LastModified > dateTime); var _ea2 = em.Find <EntityA>(ec1.A.Id); Assert.AreEqual(ec1.A, _ea2); Assert.IsTrue(_ec1.A.LastModified > dateTime); } }
public void Any() { var ec1 = new EntityC { A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY() }; TestBase.TestSerialization(ec1); using (var em = Emf.CreateEntityManager()) { Assert.IsFalse(em.Any <EntityC>()); Assert.IsFalse(em.Any <EntityA>()); Assert.IsFalse(em.Any <EntityB>()); Assert.IsFalse(em.Any <EntityXBase>()); Assert.IsFalse(em.Any <EntityX>()); Assert.IsFalse(em.Any <EntityX2>()); Assert.IsFalse(em.Any <EntityY>()); Assert.IsFalse(em.Any(new[] { typeof(EntityX), typeof(EntityX2) })); } using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); } using (var em = Emf.CreateEntityManager()) { Assert.IsTrue(em.Any <EntityC>()); Assert.IsTrue(em.Any <EntityA>()); Assert.IsTrue(em.Any <EntityB>()); Assert.IsTrue(em.Any <EntityXBase>()); Assert.IsTrue(em.Any <EntityX>()); Assert.IsFalse(em.Any <EntityX2>()); Assert.IsTrue(em.Any <EntityY>()); Assert.IsTrue(em.Any(new[] { typeof(EntityX), typeof(EntityX2) })); } var ex21 = new EntityX2(); TestBase.TestSerialization(ex21); using (var em = Emf.CreateEntityManager()) { em.Persist(ex21); em.Flush(); Assert.IsTrue(em.Any <EntityXBase>()); Assert.IsTrue(em.Any <EntityX>()); Assert.IsTrue(em.Any <EntityX2>()); Assert.IsTrue(em.Any(new[] { typeof(EntityX), typeof(EntityX2) })); em.Remove(ec1.X); em.Flush(); Assert.IsTrue(em.Any <EntityXBase>()); Assert.IsFalse(em.Any <EntityX>()); Assert.IsTrue(em.Any <EntityX2>()); Assert.IsTrue(em.Any(new[] { typeof(EntityX), typeof(EntityX2) })); em.Remove(ex21); em.Flush(); Assert.IsFalse(em.Any <EntityXBase>()); Assert.IsFalse(em.Any <EntityX>()); Assert.IsFalse(em.Any <EntityX2>()); Assert.IsFalse(em.Any(new[] { typeof(EntityX), typeof(EntityX2) })); } }
public void PersistAndFind() { var bindings = Emf.Configuration.Binding; Assert.IsFalse(bindings.StrictExplicitColumnBinding); Assert.IsFalse(bindings.StrictExplicitKeyBinding); Assert.IsFalse(bindings.StrictExplicitTableBinding); Assert.IsTrue(bindings.RegisterTableBinding(typeof(EntityBaseX), new TableBindingEntityBaseX())); Assert.IsTrue(bindings.RegisterColumnBinding(typeof(EntityAX), new ColumnBindingEntityAX())); Assert.IsTrue(bindings.RegisterColumnBinding(typeof(EntityA2X), new ColumnBindingEntityA2X())); Assert.IsTrue(bindings.RegisterColumnBinding(typeof(EntityBX), new ColumnBindingEntityBX())); Assert.IsTrue(bindings.RegisterColumnBinding(typeof(EntityB2X), new ColumnBindingEntityB2X())); var eb1 = new EntityBX(); TestBase.TestSerialization(eb1); var eb2 = new EntityBX { A = new EntityAX() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Configuration.Binding.StrictExplicitTableBinding = true; em.Configuration.Binding.StrictExplicitColumnBinding = true; em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.AreEqual("b", eb1.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier)); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.AreEqual("b", eb2.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier)); Assert.IsNotNull(eb2.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row)); Assert.AreEqual("a", eb2.A.Key.ColumnFamily); Assert.IsTrue(string.IsNullOrEmpty(eb2.A.Key.ColumnQualifier)); } using (var em = Emf.CreateEntityManager()) { em.Configuration.Binding.StrictExplicitTableBinding = true; em.Configuration.Binding.StrictExplicitColumnBinding = true; var _eb1 = em.Find <EntityBX>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityAX>(eb2.A.Key); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityBX>(eb2.Key); Assert.AreEqual(eb2, _eb2); Assert.AreEqual(2, em.Fetch <EntityBX>().Count()); Assert.AreEqual(1, em.Fetch <EntityAX>().Count()); Assert.AreEqual(3, em.Fetch <EntityBaseX>().Count()); Assert.AreEqual(2, em.Fetch <IEntityBx>().Count()); Assert.AreEqual(3, em.Fetch <EntityBaseX>(new[] { typeof(EntityBX), typeof(EntityAX) }).Count()); } var eb21 = new EntityB2X(); TestBase.TestSerialization(eb21); var eb22 = new EntityB2X { A = new EntityA2X() }; TestBase.TestSerialization(eb22); using (var em = Emf.CreateEntityManager()) { em.Persist(eb21); Assert.IsNotNull(eb21.Key); Assert.IsFalse(string.IsNullOrEmpty(eb21.Key.Row)); Assert.AreEqual("b", eb21.Key.ColumnFamily); Assert.AreEqual("bx", eb21.Key.ColumnQualifier); em.Persist(eb22); Assert.IsNotNull(eb22.Key); Assert.IsFalse(string.IsNullOrEmpty(eb22.Key.Row)); Assert.AreEqual("b", eb22.Key.ColumnFamily); Assert.AreEqual("bx", eb22.Key.ColumnQualifier); Assert.IsNotNull(eb22.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb22.A.Key.Row)); Assert.AreEqual("a", eb22.A.Key.ColumnFamily); Assert.AreEqual("a2x", eb22.A.Key.ColumnQualifier); } using (var em = Emf.CreateEntityManager()) { var _eb21 = em.Find <EntityBX>(eb21.Key); Assert.IsInstanceOfType(_eb21, typeof(EntityB2X)); Assert.AreEqual(eb21, _eb21); var _ea22 = em.Find <EntityAX>(eb22.A.Key); Assert.IsInstanceOfType(_ea22, typeof(EntityA2X)); Assert.AreEqual(eb22.A, _ea22); var _eb22 = em.Find <EntityBX>(eb22.Key); Assert.IsInstanceOfType(_eb22, typeof(EntityB2X)); Assert.AreEqual(eb22, _eb22); Assert.AreEqual(1, em.Fetch <EntityA2X>().Count()); Assert.AreEqual(2, em.Fetch <EntityAX>().Count()); Assert.AreEqual(2, em.Fetch <EntityB2X>().Count()); Assert.AreEqual(4, em.Fetch <EntityBX>().Count()); Assert.AreEqual(4, em.Fetch <IEntityBx>().Count()); Assert.AreEqual(6, em.Fetch <EntityBaseX>().Count()); Assert.AreEqual(6, em.Fetch <EntityBaseX>(new[] { typeof(EntityBX), typeof(EntityAX) }).Count()); } Assert.IsTrue(bindings.UnregisterColumnBinding(typeof(EntityAX))); Assert.IsTrue(bindings.UnregisterColumnBinding(typeof(EntityA2X))); Assert.IsTrue(bindings.UnregisterColumnBinding(typeof(EntityBX))); Assert.IsTrue(bindings.UnregisterColumnBinding(typeof(EntityB2X))); Assert.IsTrue(bindings.UnregisterTableBinding(typeof(EntityBaseX))); }
public void PersistAndFind() { { var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB(); eb2.A = new EntityA(eb2); TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { em.Persist(eb1); Assert.IsFalse(string.IsNullOrEmpty(eb1.Id)); em.Persist(eb2); Assert.IsFalse(string.IsNullOrEmpty(eb2.Id)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Id); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityA>(eb2.A.Id); Assert.AreEqual(eb2.A, _ea2); Assert.AreEqual(eb2, _ea2.OwnerB); Assert.AreSame(_ea2, _ea2.OwnerB.A); var _eb2 = em.Find <EntityB>(eb2.Id); Assert.AreEqual(eb2, _eb2); Assert.AreSame(_eb2, _eb2.A.OwnerB); } } { var ec1 = new EntityC(); TestBase.TestSerialization(ec1); var ec2 = new EntityC(); ec2.I.A = new EntityA(ec2); TestBase.TestSerialization(ec2); var ec3 = new EntityC { I = { A = new EntityA(ec1) } }; TestBase.TestSerialization(ec3); using (var em = Emf.CreateEntityManager()) { em.Persist(ec1); Assert.IsFalse(string.IsNullOrEmpty(ec1.Id)); em.Persist(ec2); Assert.IsFalse(string.IsNullOrEmpty(ec2.Id)); em.Persist(ec3); Assert.IsFalse(string.IsNullOrEmpty(ec3.Id)); } using (var em = Emf.CreateEntityManager()) { var _ec1 = em.Find <EntityC>(ec1.Id); Assert.AreEqual(ec1, _ec1); var _ea2 = em.Find <EntityA>(ec2.I.A.Id); Assert.AreEqual(ec2.I.A, _ea2); Assert.AreEqual(ec2, _ea2.OwnerC); Assert.AreSame(_ea2, _ea2.OwnerC.I.A); var _ec2 = em.Find <EntityC>(ec2.Id); Assert.AreEqual(ec2, _ec2); Assert.AreSame(_ec2, _ec2.I.A.OwnerC); var _ea3 = em.Find <EntityA>(ec3.I.A.Id); Assert.AreEqual(ec3.I.A, _ea3); Assert.AreEqual(ec1, _ea3.OwnerC); Assert.IsNull(_ea3.OwnerC.I.A); var _ec3 = em.Find <EntityC>(ec3.Id); Assert.AreEqual(ec3, _ec3); Assert.AreEqual(_ec1, _ec3.I.A.OwnerC); } } { var ed1 = new EntityD(); TestBase.TestSerialization(ed1); var ed2 = new EntityD(); ed2.I1.A = new EntityA(ed2); TestBase.TestSerialization(ed2); var ed3 = new EntityD { I2 = { A = new EntityA(ed1) } }; TestBase.TestSerialization(ed3); using (var em = Emf.CreateEntityManager()) { em.Persist(ed1); Assert.IsFalse(string.IsNullOrEmpty(ed1.Id)); em.Persist(ed2); Assert.IsFalse(string.IsNullOrEmpty(ed2.Id)); em.Persist(ed3); Assert.IsFalse(string.IsNullOrEmpty(ed3.Id)); } using (var em = Emf.CreateEntityManager()) { var _ed1 = em.Find <EntityD>(ed1.Id); Assert.AreEqual(ed1, _ed1); Assert.AreSame(_ed1.I1, _ed1.I2); var _ea2 = em.Find <EntityA>(ed2.I1.A.Id); Assert.AreEqual(ed2.I1.A, _ea2); Assert.AreEqual(ed2, _ea2.OwnerD); Assert.AreSame(_ea2.OwnerD.I2, _ea2.OwnerD.I2); Assert.AreSame(_ea2, _ea2.OwnerD.I1.A); var _ed2 = em.Find <EntityD>(ed2.Id); Assert.AreEqual(ed2, _ed2); Assert.AreSame(_ed2, _ed2.I1.A.OwnerD); Assert.AreSame(_ed2.I1, _ed2.I2); var _ea3 = em.Find <EntityA>(ed3.I1.A.Id); Assert.AreEqual(ed3.I1.A, _ea3); Assert.AreEqual(ed1, _ea3.OwnerD); Assert.IsNull(_ea3.OwnerD.I1.A); Assert.AreSame(_ea3.OwnerD.I1, _ea3.OwnerD.I2); var _ed3 = em.Find <EntityD>(ed3.Id); Assert.AreEqual(ed3, _ed3); Assert.AreEqual(_ed1, _ed3.I1.A.OwnerD); Assert.AreSame(_ed1.I1, _ed1.I2); } } }
public void PersistAndFind() { var bindings = Emf.Configuration.Binding; Assert.IsFalse(bindings.StrictExplicitColumnBinding); Assert.IsFalse(bindings.StrictExplicitKeyBinding); Assert.IsFalse(bindings.StrictExplicitTableBinding); Assert.IsTrue(bindings.RegisterTableBinding(typeof(EntityA), new TableBindingEntityA())); Assert.IsFalse(bindings.RegisterTableBinding(typeof(EntityA), new TableBindingEntityA())); Assert.IsTrue(bindings.RegisterTableBinding(typeof(EntityB), new TableBindingEntityB())); var eb1 = new EntityB(); TestBase.TestSerialization(eb1); var eb2 = new EntityB { A = new EntityA() }; TestBase.TestSerialization(eb2); using (var em = Emf.CreateEntityManager()) { Assert.IsTrue(em.IsTypeDeclared <EntityA>()); Assert.IsTrue(em.IsTypeDeclared <EntityB>()); em.Configuration.Binding.StrictExplicitTableBinding = true; em.Persist(eb1); Assert.IsNotNull(eb1.Key); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb1.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb1.Key.ColumnQualifier)); em.Persist(eb2); Assert.IsNotNull(eb2.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb2.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb2.Key.ColumnQualifier)); Assert.IsNotNull(eb2.A.Key); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.Row)); Assert.IsFalse(string.IsNullOrEmpty(eb2.A.Key.ColumnFamily)); Assert.IsTrue(string.IsNullOrEmpty(eb2.A.Key.ColumnQualifier)); } using (var em = Emf.CreateEntityManager()) { var _eb1 = em.Find <EntityB>(eb1.Key); Assert.AreEqual(eb1, _eb1); var _ea2 = em.Find <EntityA>(eb2.A.Key); Assert.AreEqual(eb2.A, _ea2); var _eb2 = em.Find <EntityB>(eb2.Key); Assert.AreEqual(eb2, _eb2); } Assert.IsTrue(bindings.UnregisterTableBinding(typeof(EntityA))); Assert.IsFalse(bindings.UnregisterTableBinding(typeof(EntityA))); Assert.IsTrue(bindings.UnregisterTableBinding(typeof(EntityB))); }