public void ToStringTest() { const string file_name = "TestFile"; const string ext = "log"; var now = DateTime.Now; var processor = new PatternString("{FileName}[{date:yyy-MM-ddTHH-mm-ss}].{ext}") { //{ "FileName", () => "TestFile" }, //["FileName"] = () => "TestFile", //["date"] = () => DateTime.Now, //["ext"] = () => ext, { "FileName", "TestFile" }, { "date", () => now }, { "ext", ext } }; var result = processor.ToString(); Assert.That.Value(result).IsEqual($"{file_name}[{now:yyy-MM-ddTHH-mm-ss}].{ext}"); }
public void ChangePatternTest() { const string file_name = "TestFile"; const string ext = "log"; var now = DateTime.Now; var processor = new PatternString("[[FileName]][[[date:yyy-MM-ddTHH-mm-ss]]].[[ext]]") { //{ "FileName", () => "TestFile" }, //["FileName"] = () => "TestFile", //["date"] = () => DateTime.Now, //["ext"] = () => ext, { "FileName", "TestFile" }, { "date", () => now }, { "ext", ext }, }; processor.Pattern = @"\[\[(?<name>\w+)(:(?<format>.*?))?\]\]"; var result = processor.ToString(); Debug.WriteLine(result); Assert.That.Value(result).IsEqual($"{file_name}[{now:yyy-MM-ddTHH-mm-ss}].{ext}"); }