public static void Main(string[] args) { if(args.Length == 0) { help(); return; } int count = 10; string format = "[FirstName][space][LastName]"; // standard format int index=0; // Scan Arguments while(index < args.Length) { if(args[index].ToUpper().StartsWith("/C:")) // Count parameter { string countStr = args[0].Substring(3); Int32.TryParse(countStr,out count); } else if (args[index].ToUpper().StartsWith("/F:")) // Format parameter { format = args[index].Substring(3); } else if (args[index].ToUpper().StartsWith("/H")) // Format parameter { help(); return; } else { Console.WriteLine("Unknown argument"); return; } index++; } NameRandomiser nameMaker = new NameRandomiser(); string [] name; NameRandomiser.FormatElement[] formatList; formatList = nameMaker.checkFormat(format); if(formatList == null) { Console.WriteLine("Invalid format '"+format+"'"); return; } for(int i=0; i < count; i++) { name = nameMaker.randomName(NameRandomiser.Gender.either); Console.WriteLine(nameMaker.applyFormat(name,formatList)); } }
public void CheckFormat() { NameRandomiser nr = new NameRandomiser(); NameRandomiser.FormatElement[] f = nr.checkFormat("[unknown]"); Assert.IsNull(f); f = nr.checkFormat("[FirstName][space][LastName]"); Assert.IsNotNull(f); Assert.AreEqual(NameRandomiser.FormatElement.FirstName,f[0]); Assert.AreEqual(NameRandomiser.FormatElement.space,f[1]); Assert.AreEqual(NameRandomiser.FormatElement.LastName,f[2]); }
public void ApplyFormat() { NameRandomiser nr = new NameRandomiser(); NameRandomiser.FormatElement[] f; f = nr.checkFormat("[FirstName]space][LastName]"); // missing [ Assert.IsNull(f); f = nr.checkFormat("[FirstName][space][LastName]"); Assert.IsNotNull(f); string [] name; name = nr.randomName(); string result = nr.applyFormat(name,f); Assert.IsNotNull(result); name = new string[2] {"John", "Smith"}; result = nr.applyFormat(name,f); Assert.AreEqual("John Smith",result); f = nr.checkFormat("[LastName][comma][Firstname]"); result = nr.applyFormat(name,f); Assert.AreEqual("Smith,John",result); string s = "[LastName][comma][FistName]"; // missing r f = nr.checkFormat(s); Assert.IsNull(f); s = "[lastname][COMMA][Firstname]"; // mixed case OK f = nr.checkFormat(s); Assert.IsNotNull(f); s = "[FI][TAB][LI]"; // First initial + tab + last initial f = nr.checkFormat(s); Assert.IsNotNull(f); result = nr.applyFormat(name,f); Assert.AreEqual("J\tS",result); }
public void RandomName() { NameRandomiser nr = new NameRandomiser(); string [] name= nr.randomName(NameMaker.NameRandomiser.Gender.either); Assert.AreEqual(name.Length,2,"Two strings expected"); }