Пример #1
0
        public void CorrectlyDeserializeMissingValues()
        {
            var serializdEntry = "127.12.254.0 - - [09/May/2018:16:00:39 +0100] \"GET /report/latest HTTP/1.0\" 200 -";
            var serializer     = new LogEntrySerializer();

            Assert.IsTrue(serializer.TryParse(serializdEntry, out var log));

            Assert.AreEqual(string.Empty, log.UserId);
            Assert.AreEqual(string.Empty, log.UserName);
            Assert.AreEqual(null as int?, log.ObjectSize);
        }
Пример #2
0
        public void CorrectlyDeserializeValidEntry()
        {
            var serializdEntry = "127.12.254.0 user_id james [09/May/2018:16:00:39 +0100] \"GET /report/latest HTTP/1.0\" 200 123";
            var serializer     = new LogEntrySerializer();

            Assert.IsTrue(serializer.TryParse(serializdEntry, out var log));

            Assert.AreEqual(new IPAddress(new byte[] { 127, 12, 254, 0 }), log.ClientAddress);
            Assert.AreEqual("user_id", log.UserId);
            Assert.AreEqual("james", log.UserName);
            Assert.AreEqual(new DateTime(2018, 5, 9, 15, 0, 39, DateTimeKind.Utc), log.TimeStampUtc);
            Assert.AreEqual("GET", log.Request.Method);
            Assert.AreEqual(new Uri("/report/latest", UriKind.Relative), log.Request.Uri);
            Assert.AreEqual("HTTP/1.0", log.Request.Protocol);
            Assert.AreEqual(200, log.Status);
            Assert.AreEqual(123 as int?, log.ObjectSize);
        }
Пример #3
0
        [TestCase("127.12.254.0 user_id james [09/May/2018:16:00:39 +0100] \"GET /report/latest HTTP/1.0\" 200 abs")]                                                                                          // invalid object size
        public void FailToDeserializeInvalidEntry(string serializdEntry)
        {
            var serializer = new LogEntrySerializer();

            Assert.IsFalse(serializer.TryParse(serializdEntry, out var _));
        }