コード例 #1
0
        public void ReadLogsByDateRangeTest()
        {
            MongoDbLogger logger = new MongoDbLogger();
            logger.Clear();

            for (int i = 1; i <= 10; i++)
            {
                Log log = new Log();

                if (i <= 3)
                {
                    log.Date = new DateTime(2012,5,16);
                }
                else if (i >= 3 && i <= 6)
                {
                    log.Date = new DateTime(2013, 7, 4);
                }
                else if (i >= 6 && i <= 10)
                {
                    log.Date = new DateTime(2013, 6, 22);
                }

                log.Ip = "172.20.154.1";
                log.Message = string.Format("Запись №{0}", i);
                log.Status = Status.Normal;
                log.UserName = "******";
                logger.Write(log);
            }

            List<Log> logs = logger.ReadLogs(new DateTime(2012, 5, 16), new DateTime(2013, 7, 4));
            Assert.IsNotNull(logs);
            Assert.AreEqual(10,logs.Count);

            logs = logger.ReadLogs(new DateTime(2012, 5, 16), new DateTime(2013, 6, 22));
            Assert.AreEqual(7,logs.Count);

            logger.Clear();
        }
コード例 #2
0
        public void ReadLogsByDateRangeWithPaginationTest()
        {
            MongoDbLogger logger = new MongoDbLogger();
            logger.Clear();

            for (int i = 1; i <= 10; i++)
            {
                Log log = new Log();

                if (i <= 3)
                {
                    log.Date = new DateTime(2012, 5, 16);
                }
                else if (i >= 3 && i <= 6)
                {
                    log.Date = new DateTime(2013, 7, 4);
                }
                else if (i >= 6 && i <= 10)
                {
                    log.Date = new DateTime(2013, 6, 22);
                }

                log.Ip = "172.20.154.1";
                log.Message = string.Format("Запись №{0}", i);
                log.Status = Status.Normal;
                log.UserName = "******";
                logger.Write(log);
            }

            long count;
            List<Log> logs = logger.ReadLogs(new DateTime(2012, 5, 16), new DateTime(2013, 7, 4),3,2, out count);

            Assert.IsNotNull(logs);
            Assert.AreEqual(3, logs.Count);
            Assert.AreEqual(10,count);
            var d = DateTime.SpecifyKind(new DateTime(2013, 6, 22, 0, 0, 0), DateTimeKind.Local);
            Assert.AreEqual(new DateTime(2013, 7, 4), logs[0].Date);
            Assert.AreEqual(new DateTime(2013, 6, 22), logs[1].Date);
            Assert.AreEqual(new DateTime(2013, 6, 22), logs[2].Date);

            logs = logger.ReadLogs(new DateTime(2012, 5, 16), new DateTime(2013, 6, 22),4,2,out count);
            Assert.AreEqual(4, logs.Count);
            Assert.AreEqual(7,count);
            Assert.AreEqual(new DateTime(2013, 6, 22), logs[0].Date);
            Assert.AreEqual(new DateTime(2013, 6, 22), logs[1].Date);
            Assert.AreEqual(new DateTime(2012, 5, 16), logs[2].Date);
            Assert.AreEqual(new DateTime(2012, 5, 16), logs[3].Date);

            logger.Clear();
        }
コード例 #3
0
        public void WriteManyLogsTest()
        {
            MongoDbLogger logger = new MongoDbLogger();
            logger.Clear();

            Parallel.For(0, 2000, act =>
            {
                Log log = new Log
                {
                    Date = DateTime.Now,
                    Ip = "172.20.154.1",
                    Message = string.Format("Запись №{0}", act),
                    Status = Status.Normal,
                    UserName = "******"
                };
                logger.Write(log);
            });

            logger.Clear();
        }
コード例 #4
0
        public void WriteLogTest()
        {
            MongoDbLogger logger = new MongoDbLogger();
            logger.Clear();

            Log log = new Log
            {
                Date = DateTime.Now,
                Ip = "172.20.154.1",
                Message = "Проверка",
                Status = Status.Normal,
                UserName = "******"
            };
            logger.Write(log);

            Assert.IsNotNull(log.Id);

            logger.DeleteLog(log.Id);
        }
コード例 #5
0
        public void SetCollectionTest()
        {
            MongoDbLogger logger = new MongoDbLogger();
            logger.Clear();

            logger.SetCollection("wapi.mapmakers");

            Log log = new Log
            {
                Date = DateTime.Now,
                Ip = "172.20.154.1",
                Message = "Проверка",
                Status = Status.Normal,
                UserName = "******"
            };
            logger.Write(log);

            Assert.IsNotNull(log.Id);

            logger.Clear();
        }