Ejemplo n.º 1
0
        public void Setup()
        {
            file =
                @"#Version: 1.0
            #Date: 12-Jan-1996 00:00:00
            #Fields: time cs-method cs-uri
            00:34:23 GET /foo/bar.html
            12:21:16 GET /foo/bar.html
            12:45:52 GET /foo/bar.html
            12:57:34 GET /foo/bar.html";

            file2 =
                @"#Version: 1.0
            #Date: 12-Jan-1996 00:00:00
            #Fields: date time cs-method cs-uri
            2012-07-23 00:34:23 GET /foo/bar.html
            2012-07-23 12:21:16 GET /foo/bar.html
            2012-07-23 12:45:52 GET /foo/bar.html
            2012-07-23 12:57:34 GET /foo/bar.html";

            fields = new[] {"time", "cs-method", "cs-uri"};
            values = new List<string[]>();
            values.Add(new[] {"00:34:23", "GET", "/foo/bar.html"});
            values.Add(new[] {"12:21:16", "GET", "/foo/bar.html"});
            values.Add(new[] {"12:45:52", "GET", "/foo/bar.html"});
            values.Add(new[] {"12:57:34", "GET", "/foo/bar.html"});
            values.Add(new[] {"2012-07-23", "00:34:23", "GET", "/foo/bar.html"});
            values.Add(new[] {"2012-07-23", "12:21:16", "GET", "/foo/bar.html"});
            values.Add(new[] {"2012-07-23", "12:45:52", "GET", "/foo/bar.html"});
            values.Add(new[] {"2012-07-23", "12:57:34", "GET", "/foo/bar.html"});

            logger = Substitute.For<Logger>();

            logger.When(x => x.Log(Arg.Any<string>(), Arg.Any<Exception>()))
                .Do(x =>
                        {
                            x.Args()[0].WriteLine();
                            throw new Exception("Shouldn't be throwing exceptions:{0}".Frmat(x.Args()[0]),
                                                (Exception) x.Args()[1]);
                        });
            w3cReader = new W3CLogReader(logger);
        }
Ejemplo n.º 2
0
        public void Should_Handle_Conversion_Fail_Gracefully()
        {
            //This one throws an Exception, just not any unhandled ones.
            w3cReader = new W3CLogReader(Substitute.For<Logger>());
            var fields = new[] {"date", "time", "method", "status"};
            IEnumerable<string> lines = new[] {"2012-07-23 09:57:31 - booger"};
            w3cReader.Convert("status").ToType(typeof (int));
            w3cReader.WithFields(fields);

            List<IDictionary<string, object>> entries = w3cReader.Process(lines).ToList();
        }