public void t04_DocumentNameComposer_Basic() { SIEEFieldlist fl = new SIEEFieldlist(); var td = new[] { new { n = 01, spec = @"abc", result = @"abc" }, new { n = 02, spec = @"a\\bc", result = @"a\bc" }, new { n = 03, spec = @"a\bc", result = @"a\bc" }, new { n = 04, spec = @"a\<bc", result = @"a<bc", }, new { n = 05, spec = @"abc\", result = @"abc\" }, new { n = 10, spec = @"abc_<:Field_1>_def", result = @"abc_Hello_def" }, new { n = 11, spec = @"abc_<unknown>_def", result = @"abc_<unknown>_def" }, new { n = 12, spec = @"<:Field_1> <:Field_2>", result = @"Hello World" }, new { n = 13, spec = @"<:Field_1>", result = @"Hello" }, new { n = 20, spec = @"x<:Field_1", result = @"x<:Field_1" }, new { n = 21, spec = @"<:Field_1", result = @"<:Field_1" }, new { n = 22, spec = @"<<:Field_1>", result = @"<<:Field_1>" }, new { n = 30, spec = @"abc\>de", result = @"abc\>de" }, new { n = 31, spec = @"abc\\de", result = @"abc\de" }, }; List <KeyValuePair <string, string> > valueList = new List <KeyValuePair <string, string> >(); valueList.Add(new KeyValuePair <string, string>("Field_1", "Hello")); valueList.Add(new KeyValuePair <string, string>("Field_2", "World")); NameSpecParser nsp = new NameSpecParser("", "", valueList); int doOnly = 0; for (int i = 0; i != td.Length; i++) { if (doOnly != 0 && td[i].n != doOnly) { continue; } string result = nsp.Convert(td[i].spec); Assert.AreEqual(td[i].result, result, td[i].n + ": Value"); } Assert.AreEqual(0, doOnly, "Not all batches executed"); }
/// Get the document name based on the filename settings public virtual string getDocumentName(SIEESettings settings, SIEEDocument doc) { // Annotation (exportName) has highest priority if (doc.ScriptingName != null) { return(doc.ScriptingName); } // Check input filename option string nameSpec = settings.GetDocumentNameSpec(); if (nameSpec == null) { return(doc.InputFileName); } // Take name from file name specification NameSpecParser nsp = new NameSpecParser(doc.BatchId, doc.DocumentId, doc.Fieldlist.ToKeyValuePairs()); return(nsp.Convert(nameSpec)); }
public void t06_TestNameSpecParser() { NameSpecParser nsp = new NameSpecParser(); // test data and test loop var td = new[] { new { n = 01, spec = "abc", result = "abc" }, new { n = 02, spec = "a<BatchId>b", result = "a_BatchId_b" }, new { n = 03, spec = "a<DocumentNumber>b", result = "a_DocumentNumber_b" }, new { n = 04, spec = "a<Guid>b", result = "a_Guid_b" }, new { n = 05, spec = "a<Host>b", result = "a_Host_b" }, new { n = 06, spec = "a<Date>b", result = "a_Date_b" }, new { n = 07, spec = "a<Time>b", result = "a_Time_b" }, new { n = 06, spec = "a<UniqueId>b", result = "a_UniqueId_b" }, new { n = 07, spec = "a<:Field>b", result = "a:Field:b" }, new { n = 09, spec = "a<some thing>b", result = "a<some thing>b" }, new { n = 03, spec = "a<PageNumber>b", result = "a_PageNumber_b" }, new { n = 20, spec = @"a\\b\", result = @"a\b\" }, new { n = 21, spec = @"a\<b<", result = @"a<b<" }, new { n = 22, spec = @"a>>b>", result = @"a>>b>" }, new { n = 23, spec = @"a<1<2\34>b", result = @"a<1<2\34>b" }, new { n = 24, spec = @"a<b", result = @"a<b" }, new { n = 24, spec = @"ab<", result = @"ab<" }, new { n = 25, spec = @"a\b", result = @"a\b" }, new { n = 26, spec = @"<>", result = @"<>" }, }; int doOnly = 0; // Test the parsing function for (int i = 0; i != td.Length; i++) { if (doOnly != 0 && td[i].n != doOnly) { continue; } List <NameSpecParser.SubstituteItem> r = nsp.Parse(td[i].spec); setSubstitutionValues(r); string finalString = nsp.ComposeResultString(r); Assert.AreEqual(td[i].result, finalString, "case: " + td[i].n); } Assert.AreEqual(doOnly, 0, "Not all tests executed"); /// Test the substitution process nsp.BatchId = "42"; nsp.DocumentNumber = "0042"; nsp.ValueList = new List <KeyValuePair <string, string> >(); nsp.ValueList.Add(new KeyValuePair <string, string>("myField", "myFieldValue")); Assert.AreEqual("-42-", nsp.Convert("-<BatchId>-")); Assert.AreEqual("-0042-", nsp.Convert("-<DocumentNumber>-")); Assert.AreEqual(true, (DateTime.Parse(nsp.Convert("<Date>")) - DateTime.Now).Days < 1); Assert.AreEqual(true, int.Parse(nsp.Convert("<Time>")) - int.Parse(DateTime.Now.ToString("HHmmss")) > -5); Assert.AreEqual(System.Environment.MachineName, nsp.Convert("<Host>")); Guid newGuid; Assert.AreEqual(true, Guid.TryParse(nsp.Convert("<Guid>"), out newGuid)); Assert.AreEqual(true, nsp.Convert("<UniqueId>").Length == 11); Assert.AreEqual("-myFieldValue-", nsp.Convert("-<:myField>-")); Assert.AreEqual("-noField-", nsp.Convert("-<:noField>-")); nsp.ValueList.Add(new KeyValuePair <string, string>("name", "SomeValue")); Assert.AreEqual("SomeValue", nsp.Convert("<:name>")); }