예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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]);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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]);
        }
예제 #6
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());
        }
예제 #7
0
        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());
        }
예제 #8
0
        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]);
        }
예제 #9
0
        public void SetSubDocumentPrimary()
        {
            Role role = CreateRole();

            role.Nums.Add(2, 2);

            role.Update(context);
            Assert.AreEqual(BsonDocument.Parse("{$set:{'Nums.2':2}}"), context.Build());
        }
예제 #10
0
        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();
        }
예제 #11
0
        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());
        }
예제 #12
0
        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());
        }
예제 #13
0
        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());
        }
예제 #14
0
        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);
        }
예제 #15
0
        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());
        }
예제 #16
0
        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);
        }
예제 #17
0
        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]);
        }