Пример #1
0
        public void Benchmark_Razor_vs_Markdown()
        {
            var iterations = 10000;
            var razorFormat = RazorFormat.Instance;
            var markdownFmt = MarkdownFormat.Instance;
            var dto = new RockstarsResponse { Results = Rockstar.SeedData.ToList() };

            "Warm up MVC Razor...".Print();
            var mockReq = new MockHttpRequest { OperationName = "RockstarsRazor" };
            var mockRes = new MockHttpResponse();
            razorFormat.ProcessRequest(mockReq, mockRes, dto);
            mockRes.ReadAsString().Print();

            "Warm up Markdown Razor...".Print();
            mockReq = new MockHttpRequest { OperationName = "RockstarsMark" };
            mockRes = new MockHttpResponse();
            markdownFmt.ProcessRequest(mockReq, mockRes, dto);
            mockRes.ReadAsString().Print();

            "\n\nRunning for {0} times...".Fmt(iterations).Print();
            CompareRuns(iterations,
                "MVC Razor", () => {
                    mockReq = new MockHttpRequest { OperationName = "RockstarsRazor" };
                    mockRes = new MockHttpResponse();
                    razorFormat.ProcessRequest(mockReq, mockRes, dto);
                },
                "Markdown Razor", () => {
                    mockReq = new MockHttpRequest { OperationName = "RockstarsMark" };
                    mockRes = new MockHttpResponse();
                    markdownFmt.ProcessRequest(mockReq, mockRes, dto);
                });
        }
Пример #2
0
        public object Get(Rockstars request)
        {
            if (request.Delete == "reset")
            {
                Db.DeleteAll <Rockstar>();
                Db.Insert(Rockstar.SeedData);
            }
            else if (request.Delete.IsInt())
            {
                Db.DeleteById <Rockstar>(request.Delete.ToInt());
            }

            var response = new RockstarsResponse
            {
                Aged    = request.Age,
                Total   = Db.Scalar <int>("select count(*) from Rockstar"),
                Results = request.Id != default(int) ?
                          Db.Select <Rockstar>(q => q.Id == request.Id)
                      : request.Age.HasValue ?
                          Db.Select <Rockstar>(q => q.Age == request.Age.Value)
                      : Db.Select <Rockstar>()
            };

            if (request.View != null || request.Template != null)
            {
                return new HttpResult(response)
                       {
                           View     = request.View,
                           Template = request.Template,
                       }
            }
            ;

            return(response);
        }
 private static string GetRazorInstanceHtml()
 {
     var razorFormat = RazorFormat.Instance;
     var mockReq = new MockHttpRequest { OperationName = "RazorInstance" };
     var mockRes = new MockHttpResponse();
     var dto = new RockstarsResponse { Results = Rockstar.SeedData.ToList() };
     razorFormat.ProcessRequest(mockReq, mockRes, dto);
     var html = mockRes.ReadAsString();
     return html;
 }
        private static string GetRazorInstanceHtml()
        {
            var razorFormat = RazorFormat.Instance;
            var mockReq     = new MockHttpRequest {
                OperationName = "RazorInstance"
            };
            var mockRes = new MockHttpResponse();
            var dto     = new RockstarsResponse {
                Results = Rockstar.SeedData.ToList()
            };

            razorFormat.ProcessRequest(mockReq, mockRes, dto);
            var html = mockRes.ReadAsString();

            return(html);
        }
Пример #5
0
        public void Benchmark_Razor_vs_Markdown()
        {
            var iterations  = 10000;
            var razorFormat = RazorFormat.Instance;
            var markdownFmt = MarkdownFormat.Instance;
            var dto         = new RockstarsResponse {
                Results = Rockstar.SeedData.ToList()
            };

            "Warm up MVC Razor...".Print();
            var mockReq = new MockHttpRequest {
                OperationName = "RockstarsRazor"
            };
            var mockRes = new MockHttpResponse();

            razorFormat.ProcessRequest(mockReq, mockRes, dto);
            mockRes.ReadAsString().Print();

            "Warm up Markdown Razor...".Print();
            mockReq = new MockHttpRequest {
                OperationName = "RockstarsMark"
            };
            mockRes = new MockHttpResponse();
            markdownFmt.ProcessRequest(mockReq, mockRes, dto);
            mockRes.ReadAsString().Print();

            "\n\nRunning for {0} times...".Fmt(iterations).Print();
            CompareRuns(iterations,
                        "MVC Razor", () => {
                mockReq = new MockHttpRequest {
                    OperationName = "RockstarsRazor"
                };
                mockRes = new MockHttpResponse();
                razorFormat.ProcessRequest(mockReq, mockRes, dto);
            },
                        "Markdown Razor", () => {
                mockReq = new MockHttpRequest {
                    OperationName = "RockstarsMark"
                };
                mockRes = new MockHttpResponse();
                markdownFmt.ProcessRequest(mockReq, mockRes, dto);
            });
        }
Пример #6
0
        public override object OnGet(Rockstars request)
        {
            using (var db = DbFactory.OpenDbConnection())
            {
                if (request.Delete == "reset")
                {
                    db.DeleteAll <Rockstar>();
                    db.Insert(Rockstar.SeedData);
                }
                else if (request.Delete.IsInt())
                {
                    db.DeleteById <Rockstar>(request.Delete.ToInt());
                }

                var response = new RockstarsResponse {
                    Aged    = request.Age,
                    Total   = db.GetScalar <int>("select count(*) from Rockstar"),
                    Results = request.Id != default(int) ?
                              db.Select <Rockstar>(q => q.Id == request.Id)
                          : request.Age.HasValue ?
                              db.Select <Rockstar>(q => q.Age == request.Age.Value)
                          : db.Select <Rockstar>()
                };

                if (request.View != null || request.Template != null)
                {
                    return new HttpResult(response)
                           {
                               View     = request.View,
                               Template = request.Template,
                           }
                }
                ;

                return(response);
            }
        }
Пример #7
0
        public object Get(Rockstars request)
        {
            if (request.Delete == "reset")
            {
                Db.DeleteAll<Rockstar>();
                Db.Insert(Rockstar.SeedData);
            }
            else if (request.Delete.IsInt())
            {
                Db.DeleteById<Rockstar>(request.Delete.ToInt());
            }

            var response = new RockstarsResponse {
                Aged = request.Age,
                Total = Db.GetScalar<int>("select count(*) from Rockstar"),
                Results = request.Id != default(int) ?
                    Db.Select<Rockstar>(q => q.Id == request.Id)
                      : request.Age.HasValue ?
                    Db.Select<Rockstar>(q => q.Age == request.Age.Value)
                      : Db.Select<Rockstar>()
            };

            if (request.View != null || request.Template != null)
                return new HttpResult(response) {
                    View = request.View,
                    Template = request.Template,
                };

            return response;
        }