public void ProcessClass()
 {
     tg.ProcessClass();
     string path = @"C:\TestFiles\FileUtilityTest.cs";
     FileUtility fu = new FileUtility(path);
     fu.WriteString(tg.TestText);
 }
示例#2
0
 /// From the description of the Code Exercise:
 /// The following is a class that allows a user to save strings to a file and then later retrieve the first index of a specified string.  
 /// Currently the class can create and read space-delimited and tab-delimited strings.  
 /// A user wants the class to be extended to (1) append all strings from a HashSet<string> to a file and 
 /// (2) return a comma separated list of every index where the string appears in the file. 
 /// We always leave code better than we find it, so create automated unit tests, add the desired functionality, 
 /// and refactor the code to make it better.
 /// Please see the implementation in FileUtility class and NUnit test for it in StringsTest.cs
 public static void Main(string[] args)
 {
     string path = @"C:\TestFiles\test.txt";
     Console.WriteLine(path.Split('\\').Last());
     HashSet<string> hash = new HashSet<string>("apple juice,orange juice,mango juice".Split(','));
     FileUtility fu = new FileUtility(path);
     switch( args[0])
     {
         case "s":
             fu.AppendStringToSpaceDelimitedFile("Space delimited text");
             Console.WriteLine( fu.GetIndexOfStringInFile("delimited"));
             break;
         case "t":
             fu.AppendStringToTabDelimitedFile("Tab delimited text");
             Console.WriteLine(fu.GetIndexOfStringInFile("delimited"));
             break;
         case "hs":
             fu.AppendHashToSpaceDelimitedFile(hash);
             Console.WriteLine(fu.GetIndexesOfString("juice"));
             break;
         case "ht":
             fu.AppendHashToTabDelimitedFile(hash);
             Console.WriteLine(fu.GetIndexesOfString("juice"));
             break;
         default:
             break;
     }
     Console.WriteLine( fu.GetIndexOfStringInFile("delimited"));
 }
 public void GenerateMethodTest()
 {
     tg.GetMethods();
     MethodInfo mi = tg.TypeToTest.GetMethod("GetIndexOfStringInFile");
     string actual = tg.GenerateMethodTest(mi);
     string path = @"C:\TestFiles\testmethodgen.txt";
     FileUtility fu = new FileUtility(path);
     fu.WriteString(actual);
     //Expect(actual, Is.EqualTo("public void GetIndexOfStringInFile()"));
     Expect(actual.IndexOf("[Test]"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("public void GetIndexOfStringInFile()"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("{"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("string strToAppend = expected;"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("fu.AppendStringToSpaceDelimitedFile(strToAppend);"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("string strToFind = \"delimited\";"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("Int32 actual = fu.GetIndexOfStringInFile(strToFind);"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("Expect(actual, Is.EqualTo(2));"), Is.Not.EqualTo(-1));
     Expect(actual.IndexOf("}"), Is.Not.EqualTo(-1));
 }
 public void Init()
 {
     expected = "A delimited text";
     fu = new FileUtility(path);
     fu.Clear();
 }
 public void FileUtility()
 {
     FileUtility actual = new FileUtility(path);
       Expect(path.Split('\\').Last(), Is.EqualTo(fu.fileName));
       Expect(path, Is.EqualTo(fu.path));
 }