Exemplo n.º 1
0
        public void EnsureDefaultDateFormatAllowsJsonDeserialization()
        {
            // Arrange

            string configXml = @"
                <jsnlog serverSideMessageFormat=""{ 
                    'utcDate': '%utcDate', 'utcDateServer': '%utcDateServer', 'date': '%date', 'dateServer': '%dateServer' 
                    }""></jsnlog>";

            XmlElement xe = Utils.ConfigToXe(configXml);

            // Act

            List <LoggerProcessor.LogData> actual =
                LoggerProcessor.ProcessLogRequestExec(_json1, "my browser", "12.345.98.7",
                                                      _dtServerUtc, "http://mydomain.com/main", "", xe);

            string messageToBeLogged = actual.FirstOrDefault().Message;

            var javaScriptSerializer = new JavaScriptSerializer();
            var datesBag1            = javaScriptSerializer.Deserialize <DatesBag>(messageToBeLogged);

            TestDatesEqual(datesBag1.utcDate, _dtFirstLogUtc);
            TestDatesEqual(datesBag1.utcDateServer, _dtServerUtc);
            TestDatesEqual(datesBag1.date, _dtFirstLog);
            TestDatesEqual(datesBag1.dateServer, _dtServer);

            var datesBag2 = Newtonsoft.Json.JsonConvert.DeserializeObject <DatesBag>(messageToBeLogged);

            TestDatesEqual(datesBag2.utcDate, _dtFirstLogUtc);
            TestDatesEqual(datesBag2.utcDateServer, _dtServerUtc);
            TestDatesEqual(datesBag2.date, _dtFirstLog);
            TestDatesEqual(datesBag2.dateServer, _dtServer);
        }
Exemplo n.º 2
0
        private void RunTest(string configXml, string json, string requestId, string userAgent, string userHostAddress,
                             DateTime serverSideTimeUtc, string url, IEnumerable <LoggerProcessor.LogData> expected)
        {
            XmlElement xe = Utils.ConfigToXe(configXml);

            // Act

            List <LoggerProcessor.LogData> actual =
                LoggerProcessor.ProcessLogRequestExec(json, userAgent, userHostAddress,
                                                      serverSideTimeUtc, url, requestId, xe);

            TestLogDatasEqual(expected, actual);
        }
Exemplo n.º 3
0
        private void RunTest(string configXml, string json, string requestId, string userAgent, string userHostAddress,
                             DateTime serverSideTimeUtc, string url, IEnumerable <LogData> expected)
        {
            XmlElement xe = CommonTestHelpers.ConfigToXe(configXml);

            // Act

            var jsnlogConfiguration    = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe);
            List <FinalLogData> actual =
                LoggerProcessor.ProcessLogRequestExec(
                    json,
                    new LogRequestBase(userAgent, userHostAddress, requestId, url, null, null, null),
                    serverSideTimeUtc, jsnlogConfiguration);

            TestLogDatasEqual(expected, actual, serverSideTimeUtc);
        }
Exemplo n.º 4
0
        public void InternalError()
        {
            string configXml = @"
                <jsnlog></jsnlog>
";

            XmlElement xe = Utils.ConfigToXe(configXml);

            // Act

            List <LoggerProcessor.LogData> actual =
                LoggerProcessor.ProcessLogRequestExec(_json4, "my browser", "12.345.98.7",
                                                      _dtServerUtc, "http://mydomain.com/main", "", xe);

            // Assert

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(Constants.JSNLogInternalErrorLoggerName, actual.ElementAt(0).LoggerName);
        }
Exemplo n.º 5
0
        public void InternalError()
        {
            string configXml = @"
                <jsnlog></jsnlog>
";

            XmlElement xe = CommonTestHelpers.ConfigToXe(configXml);

            // Act

            var jsnlogConfiguration    = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe);
            List <FinalLogData> actual =
                LoggerProcessor.ProcessLogRequestExec(
                    _json4,
                    new LogRequestBase("my browser", "12.345.98.7", "", "http://mydomain.com/main", null, null, null),
                    _dtServerUtc, jsnlogConfiguration);

            // Assert

            Assert.Equal(1, actual.Count);
            Assert.Equal(Constants.JSNLogInternalErrorLoggerName, actual.ElementAt(0).FinalLogger);
        }
Exemplo n.º 6
0
        public void EnsureDefaultDateFormatAllowsJsonDeserialization()
        {
            // Arrange

            string configXml = @"
                <jsnlog serverSideMessageFormat=""{ 
                    'utcDate': '%utcDate', 'utcDateServer': '%utcDateServer', 'date': '%date', 'dateServer': '%dateServer' 
                    }""></jsnlog>";

            XmlElement xe = CommonTestHelpers.ConfigToXe(configXml);

            // Act

            var jsnlogConfiguration    = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe);
            List <FinalLogData> actual =
                LoggerProcessor.ProcessLogRequestExec(
                    _json1,
                    new LogRequestBase("my browser", "12.345.98.7", "http://mydomain.com/main", "", null, null, null),
                    _dtServerUtc, jsnlogConfiguration);

            string messageToBeLogged = actual.FirstOrDefault().FinalMessage;

            var datesBag1 = LogMessageHelpers.DeserializeJson <DatesBag>(messageToBeLogged);

            TestDatesEqual(datesBag1.utcDate, _dtFirstLogUtc);
            TestDatesEqual(datesBag1.utcDateServer, _dtServerUtc);
            TestDatesEqual(datesBag1.date, _dtFirstLog);
            TestDatesEqual(datesBag1.dateServer, _dtServer);

            var datesBag2 = Newtonsoft.Json.JsonConvert.DeserializeObject <DatesBag>(messageToBeLogged);

            TestDatesEqual(datesBag2.utcDate, _dtFirstLogUtc);
            TestDatesEqual(datesBag2.utcDateServer, _dtServerUtc);
            TestDatesEqual(datesBag2.date, _dtFirstLog);
            TestDatesEqual(datesBag2.dateServer, _dtServer);
        }