Example #1
0
        public async Task WriteSimpleLog()
        {
            var options = new DbContextOptionsBuilder <ContextSimple>()
                          .UseInMemoryDatabase("SimpleLogDatabase", StartupSimple.MemoryRoot)
                          .Options;

            // Act
            RequestBuilder      request  = this.Server.CreateRequest("/");
            HttpResponseMessage response = await request.SendAsync("PUT");

            // Assert
            response.EnsureSuccessStatusCode();

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ContextSimple(options))
            {
                var logs = context.Logs.ToList();

                Assert.AreEqual(2, logs.Count);
                Assert.AreEqual("Handling request.", logs.First().Message);
                Assert.AreEqual(1, logs.First().EventId);
                Assert.AreEqual("Finished handling request.", logs.Last().Message);
                Assert.AreEqual(2, logs.Last().EventId);
            }
        }
        public async Task WriteSimpleLogException()
        {
            var options = new DbContextOptionsBuilder <ContextSimple>()
                          .UseInMemoryDatabase("SimpleLogExceptionDatabase")
                          .Options;

            // Act
            RequestBuilder      request  = this.Server.CreateRequest("/");
            HttpResponseMessage response = await request.SendAsync("PUT");

            // Assert
            response.EnsureSuccessStatusCode();

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ContextSimple(options))
            {
                var logs = context.Logs.ToList();

                Assert.AreEqual(1, logs.Count);
                Assert.AreEqual(true, logs.First().Message.StartsWith("Exception message"));
                Assert.AreEqual(1, logs.First().EventId);
            }
        }