Example #1
0
        public void AC_HtmlToken()
        {
            TextTokenTestModel      model           = new TextTokenTestModel();
            AssemblyCompilerOptions compilerOptions = new AssemblyCompilerOptions()
            {
                ModelType = model.GetType()
            };

#if !NETCOREAPP
            compilerOptions.AssemblyDirectory = TestContext.CurrentContext.TestDirectory;
            compilerOptions.AllowSaveAssembly = true;
#endif
            AssemblyCompiler            compiler    = new AssemblyCompiler(compilerOptions);
            AssemblyCompilerTypeContext typeContext = compiler.AddType("TextTokenTest", typeof(ITextTokenTestResultModel));
            typeContext.AddProperty("TextProperty", "{html:TextProperty}", OutputFormat.Text);
            typeContext.AddProperty("HtmlProperty", "{html:HtmlProperty}", OutputFormat.Text);
            typeContext.AddProperty("EncodedHtmlProperty", "{html:HtmlProperty}", OutputFormat.Html);
            typeContext.AddProperty("IntProperty", "{html:IntProperty}", OutputFormat.Text);
            typeContext.AddProperty("FormattedIntProperty", "{html:IntProperty:0000.00}", OutputFormat.Text);
            typeContext.AddProperty("FloatProperty", "{html:FloatProperty}", OutputFormat.Text);
            typeContext.AddProperty("FormattedFloatProperty", "{html:FloatProperty:0.##}", OutputFormat.Text);
            typeContext.AddProperty("DateTimeProperty", "{html:DateTimeProperty:dd.MM.yyyy}", OutputFormat.Text);
            typeContext.AddProperty("FormattedDateTimeProperty", "{html:DateTimeProperty:dd.MM.yyyy HH:mm:ss}", OutputFormat.Text);
#if NETCOREAPP
            Type[] compiledTypes = compiler.GetCompiledTypes();
#else
            Type[] compiledTypes = compiler.GetCompiledTypes(true);
#endif
            Assert.IsNotNull(compiledTypes);
            Assert.AreEqual(1, compiledTypes.Length);
            Type type = compiledTypes[0];
            Assert.IsNotNull(type);
            Assert.IsNotNull(type.GetInterface(typeof(ITextTokenTestResultModel).FullName));
            CultureInfo[] cultureArr = new[] { CultureInfo.InvariantCulture, CultureInfo.GetCultureInfo(1049) };
            foreach (CultureInfo culture in cultureArr)
            {
                ITextTokenTestResultModel result = AssemblyCompiler.CreateTypeInstance <ITextTokenTestResultModel>(type, model, culture);
                Assert.AreEqual(model.TextProperty, result.TextProperty);
                Assert.AreEqual(model.HtmlProperty, result.HtmlProperty);
                Assert.AreEqual(model.HtmlProperty, result.EncodedHtmlProperty);
                Assert.AreEqual(String.Format(culture, "{0}", model.IntProperty), result.IntProperty);
                Assert.AreEqual(String.Format(culture, "{0:0000.00}", model.IntProperty), result.FormattedIntProperty);
                Assert.AreEqual(String.Format(culture, "{0}", model.FloatProperty), result.FloatProperty);
                Assert.AreEqual(String.Format(culture, "{0:0.##}", model.FloatProperty), result.FormattedFloatProperty);
                Assert.AreEqual(String.Format(culture, "{0:dd.MM.yyyy}", model.DateTimeProperty), result.DateTimeProperty);
                Assert.AreEqual(String.Format(culture, "{0:dd.MM.yyyy HH:mm:ss}", model.DateTimeProperty), result.FormattedDateTimeProperty);
            }
        }