コード例 #1
0
        private async Task <string> ExecuteServerSide(string testName, string templateFile, string dataFile)
        {
            var cacheProvider  = new NullCacheProvider();
            var namingRule     = new NamingRule();
            var handlerFactory = new NullRenderingHelperHandlerFactory();

            var templateInfo = new FileTemplateInfo(testName, PathInfo.Create(templateFile), new FileSystem());

            var   viewEngine = new VeilViewEngine(cacheProvider, handlerFactory, namingRule);
            IView view       = await viewEngine.CreateViewAsync(templateInfo).ConfigureAwait(false);

            if (view == null)
            {
                Assert.Fail("Could not create view from file'{0}'.", templateFile);
            }

            object model;

            using (var reader = new StreamReader(dataFile))
            {
                model = new JsonSerializer().Deserialize(reader, typeof(Dictionary <string, object>));
            }

            this.TestContext.BeginTimer("Server");
            var builder = new StringBuilder();

            using (var writer = new StringWriterDelayed(builder))
            {
                view.Render(model, new RenderingContext(writer));
            }
            var resultString = builder.ToString();

            this.TestContext.EndTimer("Server");
            return(resultString);
        }
コード例 #2
0
        private string ExecuteClientSide(string testName, string templateFile, string dataFile)
        {
            var namingRule     = new NamingRule();
            var handlerFactory = new NullRenderingHelperHandlerFactory();

            var clientGenerator = new ClientTemplateGenerator(handlerFactory, new MemberLocatorFromNamingRule(namingRule));
            var generator       = new JavascriptClientTemplateGenerator("repo", clientGenerator);

            var templateInfo = new FileTemplateInfo(testName, PathInfo.Create(templateFile), new FileSystem());
            var view         = generator.Generate(templateInfo);

            Dictionary <string, object> model;

            using (var reader = new StreamReader(dataFile))
            {
                model = (Dictionary <string, object>) new JavaScriptSerializer().Deserialize(reader.ReadToEnd(), typeof(Dictionary <string, object>));
            }

            CleanupModel(model);

            this.TestContext.BeginTimer("JS Rendering");
            var result = JavascriptClientTest.ExecuteJavascript(view, model, testName);

            this.TestContext.EndTimer("JS Rendering");

            return(result);
        }
コード例 #3
0
        private async Task <string> ExecuteServerSideStrongModel(string testName, string templateFile, string dataFile)
        {
            var cacheProvider  = new NullCacheProvider();
            var namingRule     = new NamingRule();
            var handlerFactory = new NullRenderingHelperHandlerFactory();

            var templateInfo = new FileTemplateInfo(testName, PathInfo.Create(templateFile), new FileSystem());

            var schemaProvider = new HandlebarsViewSchemaProvider(handlerFactory, new MemberLocatorFromNamingRule(namingRule));

            var generator = new JsonSchemaCodeGenerator(namingRule);
            var schema    = await schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false);

            schema.Title = "Model";
            var modelType = generator.Compile(schema);

            var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory, namingRule);
            var view       = await viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false);

            if (view == null)
            {
                Assert.Fail("Could not create view from file '{0}'.", templateFile);
            }

            object model;

            using (var reader = new JsonTextReader(new StreamReader(dataFile)))
            {
                model = JsonSerializer.Create().Deserialize(reader, modelType);
            }

            this.TestContext.BeginTimer("ServerStrong");
            var builder = new StringBuilder();

            using (var writer = new StringWriterDelayed(builder))
            {
                view.Render(model, new RenderingContext(writer));
            }
            var resultString = builder.ToString();

            this.TestContext.EndTimer("ServerStrong");
            return(resultString);
        }