Beispiel #1
0
        public void TestGetErroCodeAndCount()
        {
            using (var connection = new SqliteConnection("DataSource=:memory:"))
            {
                connection.Open();

                var options = new DbContextOptionsBuilder <AlsoEnergyContext>().UseSqlite(connection).Options;

                using (var context = new AlsoEnergyContext(options))
                {
                    context.Database.EnsureCreated();

                    IServerResponseLogRepository serverResponseLogRepository = new ServerResponseLogRepository(new AlsoEnergyContext(options));
                    var date = DateTime.Now.Date;
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date.AddHours(3), HttpStatusCode = 200
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date.AddHours(3), HttpStatusCode = 200
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date.AddHours(3), HttpStatusCode = 500
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date.AddHours(2), HttpStatusCode = 200
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date.AddHours(2), HttpStatusCode = 200
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date, HttpStatusCode = 200
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date, HttpStatusCode = 500
                    });
                    serverResponseLogRepository.Save(new Server_Response_Log {
                        StartTime = date, HttpStatusCode = 408
                    });


                    var dictionary = serverResponseLogRepository.GetErrorCodeAndCount(date);
                    Assert.AreEqual(dictionary.Count, 3);
                    Assert.AreEqual(dictionary[0].Count(), 3);
                    Assert.AreEqual(dictionary[2].Count(), 1);
                    Assert.AreEqual(dictionary[2].First().Key, 200);
                    Assert.AreEqual(dictionary[2].First().Value, 2);
                    Assert.AreEqual(dictionary[3].Count(), 2);
                    Assert.AreEqual(dictionary[3].First(kv => kv.Key == 200).Value, 2);
                    Assert.AreEqual(dictionary[3].First(kv => kv.Key == 500).Value, 1);
                }
            }
        }
Beispiel #2
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            Dictionary <int, IEnumerable <KeyValuePair <int, int> > > model;

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                var options = new DbContextOptionsBuilder <AlsoEnergyContext>().UseSqlServer(connection).Options;

                using (var context = new AlsoEnergyContext(options))
                {
                    IServerResponseLogRepository serverResponseLogRepository = new ServerResponseLogRepository(new AlsoEnergyContext(options));
                    model = serverResponseLogRepository.GetErrorCodeAndCount(DateTime.Now.AddHours(-3));
                }
            }
            return(View(model));
        }