public static void FKTest() { var x = new FKClass { Id = int.MaxValue / 2, Simple = new FK <Simple>(new Simple { Bar = 33, Baz = "hello world!", }), }; var e = Entity <FKClass> .To(new Entity(), x); var rt = Entity <FKClass> .From(new FKClass(), e); Assert.Equal(x.Id, rt.Id); Assert.Equal(x.Simple.Key, rt.Simple.Key); }
public void FKTest() { var s = new Simple { Baz = "hello world!", }; var x = new FKClass { Simple = new FK <Simple>(s), }; var db = TestDatastoreClient.Create(); var skey = db.Upsert(s); Assert.Equal(s.Bar, skey.Id()); var xkey = db.Insert(x); var rt = db.Lookup(xkey, new FKClass()); Assert.Equal(x.Id, rt.Id); Assert.Equal(x.Simple.Key.Id(), rt.Simple.Key.Id()); var rts = rt.Simple.Get(db); Assert.Equal(s.Baz, rts.Baz); // mutate the property and ensure it saves var s2 = new Simple { Baz = "foo!", }; rt.Simple.Value = s2; db.Upsert(s2); db.Upsert(rt); Assert.NotEqual(0, s2.Bar); Assert.Equal(s2.Bar, rt.Simple.Value.Bar); var rt2 = db.Lookup(xkey, new FKClass()); Assert.Equal(rt.Simple.Value.Bar, rt2.Simple.Get(db).Bar); }