mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-25 18:30:29 +08:00
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using Masuit.Tools.Strings;
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||
using System;
|
||
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
|
||
|
||
namespace Masuit.Tools.Test
|
||
{
|
||
[TestClass]
|
||
public class TemplateTest
|
||
{
|
||
[TestMethod]
|
||
public void Render_Template()
|
||
{
|
||
var tmp = new Template("{{name}},你好!");
|
||
tmp.Set("name", "万金油");
|
||
string s = tmp.Render();
|
||
Assert.AreEqual("万金油,你好!", s);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void Render_TemplateWithMultiVariables()
|
||
{
|
||
var tmp = new Template("{{one}},{{two}},{{three}}");
|
||
string s = tmp.Set("one", "1").Set("two", "2").Set("three", "3").Render();
|
||
Assert.AreEqual("1,2,3", s);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void Render_TemplateWithUncoverVariable()
|
||
{
|
||
var tmp = new Template("{{name}},{{greet}}!");
|
||
tmp.Set("name", "万金油");
|
||
try
|
||
{
|
||
string s = tmp.Render();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Assert.IsInstanceOfType(e, typeof(ArgumentException));
|
||
Assert.AreEqual("模版变量{{greet}}未被使用", e.Message);
|
||
}
|
||
}
|
||
}
|
||
} |