Example #1
0
        /// <summary>
        /// 测试 RunCompileFromCached 方法(弱类型模型)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <string> TestRunCompileFromCached(string name)
        {
            var runCompileTemplate = "Hello @Model.Name";
            var model = new { Name = name };

            var str1 = _viewEngine.RunCompileFromCached(runCompileTemplate, model);
            var str2 = runCompileTemplate.RunCompileFromCached(model);
            var str3 = await _viewEngine.RunCompileFromCachedAsync(runCompileTemplate, model);

            var str4 = await runCompileTemplate.RunCompileFromCachedAsync(model);

            var isEqual = (str1 == str2) && (str3 == str4) && (str1 == str4);

            if (!isEqual)
            {
                throw new Exception("多次编译之后模板内容相等");
            }

            if (!File.Exists(Path.Combine(AppContext.BaseDirectory, "templates", $"~{MD5Encryption.Encrypt(runCompileTemplate)}.dll")))
            {
                throw new Exception("没找到模板缓存 .dll");
            }

            return(str1);
        }