private static void Test9() { var r0 = Role.FindByName("Stone"); r0?.Delete(); var r = new Role { Name = "Stone" }; r.Insert(); var r2 = Role.FindByName("Stone"); XTrace.WriteLine("FindByName: {0}", r2.ToJson()); r.Enable = true; r.Update(); var r3 = Role.Find(Role._.Name == "STONE"); XTrace.WriteLine("Find: {0}", r3.ToJson()); r.Delete(); var n = Role.FindCount(); XTrace.WriteLine("count={0}", n); }
public void TestBsonDictRemove() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; role.Texts[11] = "abc"; role.ClearDirty(); collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.Texts.Remove(11); role.Update(context); var bsonUpdate = context.Build(); Assert.AreEqual(BsonDocument.Parse("{$unset:{'Texts': 1}}"), bsonUpdate); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, bsonUpdate); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(0, roleActual.Texts.Count); }
public void TestBsonDictSetNull() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.Friends.Add(11, null); role.Update(context); var bsonUpdate = context.Build(); Assert.AreEqual(BsonDocument.Parse("{$set:{'Friends.11': null}}"), bsonUpdate); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, bsonUpdate); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(null, roleActual.Friends[11]); }
public void TestBsonListClear() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; role.ListInt.Add(10); role.ListInt.Add(11); role.ListInt.Add(12); role.ClearDirty(); collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.ListInt.Clear(); role.Update(context); var bsonUpdate = context.Build(); Assert.AreEqual(BsonDocument.Parse("{'$unset': {'ListInt': 1}}"), bsonUpdate); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, context.Build()); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(0, roleActual.ListInt.Count); }
public void TestBsonListAddNull() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.ListFriend.Add(null); role.Update(context); var bsonUpdate = context.Build(); Assert.AreEqual(BsonDocument.Parse("{$set:{'ListFriend.1': {'PrevKey':0, 'Value':null}}}"), bsonUpdate); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, bsonUpdate); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(null, roleActual.ListFriend[0]); }
public void SetProperty() { Role role = CreateRole(); role.RoleName = "test"; role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$set:{'RoleName':'test'}}"), context.Build()); role.ClearDirty(); context.Clear(); role.RoleName = null; role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$unset:{'RoleName':1}}"), context.Build()); }
static async void Test2() { //LogProvider.Provider.WriteLog("test", "xxx", "yyy"); var r = new Role { ID = 2, Name = "xxx", Enable = false }; r.Update(); //var count = Role.Meta.Count; //var dal = Role.Meta.Session.Dal; //var db = dal.Query("select * from role"); //var json = db.ToJson(true, false, true); //XTrace.WriteLine(json); //json = db.ToJson(); //XTrace.WriteLine(json); //db = dal.Query("select id,name,enable 启用 from role"); //json = db.ToJson(true, false, true); //XTrace.WriteLine(json); //var names = Log.FindAllCategoryName(); //Console.WriteLine(names.ToJson()); }
public void TestBsonList_IndexSet() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; role.ListInt.Add(10); role.ListInt.Add(11); role.ListInt.Add(12); role.ClearDirty(); collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.ListInt[1] = 21; role.Update(context); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, context.Build()); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(10, roleActual.ListInt[0]); Assert.AreEqual(21, roleActual.ListInt[1]); Assert.AreEqual(12, roleActual.ListInt[2]); }
public void SetSubDocumentPrimary() { Role role = CreateRole(); role.Nums.Add(2, 2); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$set:{'Nums.2':2}}"), context.Build()); }
public void SetSubDocumentString() { Role role = CreateRole(); role.Texts.Add(2, "test2"); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$set:{'Texts.2':'test2'}}"), context.Build()); role.ClearDirty(); }
public void SetSubDocumentClass() { Role role = CreateRole(); role.Friends.Add(2, new Friend { RoleID = 2, RoleName = "test2" }); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$set:{'Friends.2':{'_id':2,'RoleName':'test2'}}}"), context.Build()); }
public void UnsetDocumentString() { Role role = CreateRole(); role.Texts.Add(1, "test1"); role.Texts.Add(2, "test2"); role.ClearDirty(); role.Texts.Remove(2); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$unset:{'Texts.2':1}}"), context.Build()); }
public void UnsetDocumentPrimary() { Role role = CreateRole(); role.Nums.Add(1, 1); role.Nums.Add(2, 2); role.ClearDirty(); role.Nums.Remove(2); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$unset:{'Nums.2':1}}"), context.Build()); }
public void Document() { Role role = CreateRole(); role.RoleID = 1; role.RoleName = "testName"; role.Update(context); var actual = (BsonValue)role; var expected = BsonDocument.Parse("{'_id':NumberLong(1),'RoleName':'testName'}"); Assert.AreEqual(expected, (BsonDocument)(BsonValue)role); }
public void UnsetDocumentClass() { Role role = CreateRole(); role.Friends.Add(1, null); role.Friends.Add(2, new Friend { RoleID = 2, RoleName = "test2" }); role.ClearDirty(); role.Friends.Remove(2); role.Update(context); Assert.AreEqual(BsonDocument.Parse("{$unset:{'Friends.2':1}}"), context.Build()); }
private static void Test9() { var cache = new SingleEntityCache <Int32, User> { Expire = 1 }; // 首次访问 var user = cache[1]; XTrace.WriteLine("cache.Success={0}", cache.Success); user = cache[1]; XTrace.WriteLine("cache.Success={0}", cache.Success); user = cache[1]; XTrace.WriteLine("cache.Success={0}", cache.Success); EntityFactory.InitAll(); XTrace.WriteLine("TestRole"); var r0 = Role.FindByName("Stone"); r0?.Delete(); var r = new Role { Name = "Stone" }; r.Insert(); var r2 = Role.FindByName("Stone"); XTrace.WriteLine("FindByName: {0}", r2.ToJson()); r.Enable = true; r.Update(); var r3 = Role.Find(Role._.Name == "STONE"); XTrace.WriteLine("Find: {0}", r3.ToJson()); r.Delete(); var n = Role.FindCount(); XTrace.WriteLine("count={0}", n); }
public void TestBsonList_RemoveAt_Middle() { var collection = GetTestCollection <BsonDocument>(); Role role = new Role { RoleID = 1 }; role.ListInt.Add(10); role.ListInt.Add(11); role.ListInt.Add(12); role.ClearDirty(); collection.InsertOne((BsonDocument)role); UpdateContext context = new UpdateContext(); role.ListInt.RemoveAt(1); role.Update(context); var bsonUpdate = context.Build(); Assert.AreEqual(new BsonDocument { { "$set", new BsonDocument { { "ListInt.3.PrevKey", 1 } } }, { "$unset", new BsonDocument { { "ListInt.2", 1 } } } }, bsonUpdate); collection.UpdateOne(new BsonDocument { { "_id", 1 } }, context.Build()); var actual = collection.Find(new BsonDocument()).First(); var roleActual = (Role)actual; Assert.AreEqual(10, roleActual.ListInt[0]); Assert.AreEqual(12, roleActual.ListInt[1]); }