public void RegisterAll()
        {
            #region 测试一次注册全部
            string assemblyName = GetType().Assembly.GetName().ToString();
            RepositoryContainer.RegisterAll(assemblyName);

            var uRep       = RepositoryContainer.Resolve <UserRepAsync>();
            var uRepAsync  = RepositoryContainer.Resolve <UserRepAsync>();
            var uRep2      = RepositoryContainer.Resolve <User2RepositoryAsync>();
            var uRepAsync2 = RepositoryContainer.Resolve <User2RepositoryAsync>();
            Assert.IsNotNull(uRep);
            Assert.IsNotNull(uRepAsync);
            Assert.IsNotNull(uRep2);
            Assert.IsNotNull(uRepAsync2);
            #endregion

            #region 测试replace
            //新注册,应该要跟原对象不同
            RepositoryContainer.RegisterAll(assemblyName);

            Assert.AreNotEqual(uRep, RepositoryContainer.Resolve <UserRepAsync>());
            Assert.AreNotEqual(uRepAsync, RepositoryContainer.Resolve <UserRepAsync>());
            Assert.AreNotEqual(uRep2, RepositoryContainer.Resolve <User2RepositoryAsync>());
            Assert.AreNotEqual(uRepAsync2, RepositoryContainer.Resolve <User2RepositoryAsync>());
            #endregion
        }
示例#2
0
        static void CheckUserData()
        {
            var userEsRepo = RepositoryContainer.Resolve <UserRepo>();
            var users      = userEsRepo.GetList(x => x.MallID == 10008, sortExp: x => x.ID, sortType: SortOrder.Ascending, limit: 10000);

            var userMongoRepo = MongoDB.Repository.RepositoryContainer.Resolve <UserMongoRepo>();
            var usersInMongo  = userMongoRepo.GetList(x => x.MallID == 10008, sortExp: x => x.ID, sortType: MongoDB.Repository.SortType.Ascending, limit: 10000);

            Console.WriteLine(users.Item1);
            Console.WriteLine(usersInMongo.Count);

            var userIds        = users.Item2.Select(x => x.ID);
            var userInMongoIds = usersInMongo.Select(x => x.ID);

            var userEsExceptMongoIds = userIds.Except(userInMongoIds);

            Console.WriteLine("在Es中不在MongoDb中的ID个数有{0}", userEsExceptMongoIds.Count());
            foreach (var id in userEsExceptMongoIds)
            {
                Console.WriteLine(id);
            }

            var userMongoExceptEsIds = userInMongoIds.Except(userIds);

            Console.WriteLine("在MongoDb中不在Es中的ID个数有{0}", userMongoExceptEsIds.Count());
            foreach (var id in userMongoExceptEsIds)
            {
                Console.WriteLine(id);
            }
        }
示例#3
0
        public async Task <APILog> SingleInsert()
        {
            var logRep = RepositoryContainer.Resolve <APILogRepository>();
            var entity = CreateEntity();
            await logRep.InsertAsync(entity);

            return(entity);
        }
示例#4
0
        static void CheckMallCardData()
        {
            var mallEsRepo    = RepositoryContainer.Resolve <MallCardRepo>();
            var mallMongoRepo = MongoDB.Repository.RepositoryContainer.Resolve <MallCardMongoRepo>();

            long startIdInEs    = 0;
            long startIdInMongo = 0;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var mallsInEs = mallEsRepo.GetList(x => x.ID > startIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending, limit: 10000);

            sw.Stop();

            Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);

            while (mallsInEs.Item2.Count > 0)
            {
                Console.WriteLine("获取数据数目:{0}", mallsInEs.Item2.Count);

                sw.Restart();
                var mallsInMongo = mallMongoRepo.GetList(x => x.ID > startIdInMongo, sortExp: x => x.ID, sortType: MongoDB.Repository.SortType.Ascending, limit: 10000);
                sw.Stop();
                Console.WriteLine("查询MongoDB耗时:{0}", sw.ElapsedMilliseconds);

                startIdInEs    = mallsInEs.Item2.Last().ID;
                startIdInMongo = mallsInMongo.Last().ID;


                var mallIds        = mallsInEs.Item2.Select(x => x.ID);
                var mallInMongoIds = mallsInMongo.Select(x => x.ID);

                var mallEsExceptMongoIds = mallIds.Except(mallInMongoIds);

                Console.WriteLine("在Es中不在MongoDb中的ID个数有{0}", mallEsExceptMongoIds.Count());
                foreach (var id in mallEsExceptMongoIds)
                {
                    Console.WriteLine(id);
                }

                var mallMongoExceptEsIds = mallInMongoIds.Except(mallIds);

                Console.WriteLine("在MongoDb中不在Es中的ID个数有{0}", mallMongoExceptEsIds.Count());
                foreach (var id in mallMongoExceptEsIds)
                {
                    Console.WriteLine(id);
                }

                sw.Restart();
                mallsInEs = mallEsRepo.GetList(x => x.ID > startIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending, limit: 10000);
                sw.Stop();
                Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);
            }
        }
示例#5
0
        public async Task <List <APILog> > BatchInsert()
        {
            var logRep = RepositoryContainer.Resolve <APILogRepository>();
            var logs   = new List <APILog>();

            logs.Add(CreateEntity());
            logs.Add(CreateEntity());
            logs.Add(CreateEntity());
            await logRep.InsertBatchAsync(logs);

            return(logs);
        }
示例#6
0
        static void CheckCardVoucherInfoData()
        {
            var esRepo    = RepositoryContainer.Resolve <CardVoucherInfoRepo>();
            var mongoRepo = MongoDB.Repository.RepositoryContainer.Resolve <CardVoucherInfoMongoRepo>();

            long startIdInEs    = 0;
            long startIdInMongo = 0;

            long endIdInEs    = 300000;
            long endIdInMongo = 300000;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var inEs = esRepo.GetList(x => x.ID >= startIdInEs && x.ID < endIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending);

            sw.Stop();

            Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);

            while (inEs.Item1 > 0)
            {
                Console.WriteLine("获取数据数目:{0}", inEs.Item1);

                sw.Restart();
                var inMongo = mongoRepo.Count(x => x.ID >= startIdInMongo && x.ID < endIdInMongo);
                sw.Stop();
                Console.WriteLine("查询MongoDB耗时:{0}", sw.ElapsedMilliseconds);


                Console.WriteLine("正在对比区间:{0}~{1}", startIdInEs, endIdInEs);
                if (inEs.Item1 != inMongo)
                {
                    Console.WriteLine("区间:{0}~{1}数据不一致", startIdInEs, endIdInEs);
                    Console.WriteLine("差异:{0}", inEs.Item1 - inMongo);

                    Thread.Sleep(5000);
                }

                startIdInEs    = endIdInEs;
                startIdInMongo = endIdInMongo;

                endIdInEs    += 300000;
                endIdInMongo += 300000;

                Console.WriteLine();

                sw.Restart();
                inEs = esRepo.GetList(x => x.ID >= startIdInEs && x.ID < endIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending);
                sw.Stop();
                Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);
            }
        }
示例#7
0
        static void CheckMallCardData_New()
        {
            var mallEsRepo    = RepositoryContainer.Resolve <MallCardRepo>();
            var mallMongoRepo = MongoDB.Repository.RepositoryContainer.Resolve <MallCardMongoRepo>();

            //17700000~18000000数
            long startIdInEs    = 17800000;
            long startIdInMongo = 17800000;

            long endIdInEs    = 17850965;
            long endIdInMongo = 17850965;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var mallsInEs = mallEsRepo.GetList(x => x.ID >= startIdInEs && x.ID < endIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending);

            sw.Stop();

            Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);

            while (mallsInEs.Item1 > 0)
            {
                Console.WriteLine("获取数据数目:{0}", mallsInEs.Item1);

                sw.Restart();
                var mallsInMongo = mallMongoRepo.Count(x => x.ID >= startIdInMongo && x.ID < endIdInMongo);
                sw.Stop();
                Console.WriteLine("查询MongoDB耗时:{0}", sw.ElapsedMilliseconds);


                Console.WriteLine("正在对比区间:{0}~{1}", startIdInEs, endIdInEs);
                if (mallsInEs.Item1 != mallsInMongo)
                {
                    Console.WriteLine("区间:{0}~{1}数据不一致", startIdInEs, endIdInEs);
                    Console.WriteLine("差异:{0}", mallsInEs.Item1 - mallsInMongo);
                }

                startIdInEs    = endIdInEs;
                startIdInMongo = endIdInMongo;

                endIdInEs    += 60000;
                endIdInMongo += 60000;

                Console.WriteLine();

                sw.Restart();
                mallsInEs = mallEsRepo.GetList(x => x.ID >= startIdInEs && x.ID < endIdInEs, sortExp: x => x.ID, sortType: SortOrder.Ascending);
                sw.Stop();
                Console.WriteLine("查询es耗时:{0}", sw.ElapsedMilliseconds);
            }
        }
        public void Register()
        {
            UserRepAsync uRep = new UserRepAsync();

            RepositoryContainer.Register(uRep);
            UserRepAsync uRep2 = RepositoryContainer.Resolve <UserRepAsync>();

            Assert.AreEqual(uRep, uRep2);

            RepositoryContainer.Register <UserRepAsync>(() => { return(new UserRepAsync()); });
            var uRepAsync = RepositoryContainer.Resolve <UserRepAsync>();

            Assert.IsNotNull(uRepAsync);
        }
        public async Task CallMongoDB()
        {
            #region 无参公共构造方法
            RepositoryContainer.Register <UserRepAsync>();
            RepositoryContainer.Register <UserRepAsync>();

            var uRep      = RepositoryContainer.Resolve <UserRepAsync>();
            var uRepAsync = RepositoryContainer.Resolve <UserRepAsync>();

            #region  步仓储 新增和读取数据测试
            User entity1 = new User()
            {
                Age   = 18,
                Name  = "uRep测试",
                Stamp = "哈哈"
            };
            await uRep.InsertAsync(entity1);

            Assert.IsTrue(entity1.ID > 0);
            var e1 = await uRep.GetAsync(x => x.ID == entity1.ID);

            Assert.IsNotNull(e1);
            Assert.IsTrue(e1.Name == "uRep测试");
            #endregion

            #region 异步仓储 新增和读取数据测试
            User entity2 = new User()
            {
                Age   = 19,
                Name  = "uRepAsync测试",
                Stamp = "哈哈2"
            };
            await uRepAsync.InsertAsync(entity2);

            Assert.IsTrue(entity2.ID > 0);
            var e2 = await uRepAsync.GetAsync(x => x.ID == entity2.ID);

            Assert.IsNotNull(e2);
            Assert.IsTrue(e2.Name == "uRepAsync测试");
            #endregion
            #endregion

            #region 无参私有构造方法
            RepositoryContainer.Register(typeof(User2RepositoryAsync));
            RepositoryContainer.Register(typeof(User2RepositoryAsync));

            var uRep2      = RepositoryContainer.Resolve <User2RepositoryAsync>();
            var uRepAsync2 = RepositoryContainer.Resolve <User2RepositoryAsync>();

            #region  步仓储 新增和读取数据测试
            User2 entity3 = new User2()
            {
                Age    = 20,
                Name   = "User2Repository测试",
                Remark = "哈哈"
            };
            await uRep2.InsertAsync(entity3);

            Assert.IsNotNull(entity3.ID);
            var e3 = await uRep2.GetAsync(x => x.ID == entity3.ID);

            Assert.IsNotNull(e3);
            Assert.IsTrue(e3.Name == "User2Repository测试");
            #endregion

            #region 异步仓储 新增和读取数据测试
            User2 entity4 = new User2()
            {
                Age    = 21,
                Name   = "User2RepositoryAsync测试",
                Remark = "哈哈"
            };
            await uRepAsync2.InsertAsync(entity4);

            Assert.IsNotNull(entity4.ID);
            var e4 = await uRepAsync2.GetAsync(x => x.ID == entity4.ID);

            Assert.IsNotNull(e4);
            Assert.IsTrue(e4.Name == "User2RepositoryAsync测试");
            #endregion
            #endregion
        }