public void TheSystemThrowsAFileNotFOundExceptionWhenGivenAPathToAMissingFile() { FileManager fileManager = new FileManager(@"C:\MissingFileThereIsNoFileHere.txt"); Assert.IsTrue(fileManager.GetEvenMoreContent().Contains("This line won't execute as the exception will be thrown before it's hit")); }
protected void Page_Load(object sender, EventArgs e) { // The first two lines find and set the name of the directory and file that the content is stored in string appDataDirectory = Server.MapPath("/App_Data"); string contentFilePath = string.Format(@"{0}\{1}", appDataDirectory, "Content.txt"); // Then a file manager is created to read the content from the file FileManager contentManager = new FileManager(contentFilePath); // The text property of the label contained in the ASPX file is set with the content returned by the FileManager lblContent.Text = contentManager.GetContent(); string outcomeOfAddingEvenMoreContent = String.Empty; try { outcomeOfAddingEvenMoreContent = contentManager.GetEvenMoreContent(); } catch(Exception ex) { outcomeOfAddingEvenMoreContent = ex.Message; } finally { lblEvenMoreContent.Text = outcomeOfAddingEvenMoreContent; } }
public void TheFileManagerHandlesAMissingFIle() { FileManager fileManager = new FileManager(@"C:\MissingFileThereIsNoFileHere.txt"); Assert.IsTrue(fileManager.GetContent().Contains("Oops! The content could not be found at the location specified.")); }
public void TheFileManagerCanReadAFile() { FileManager fileManager = new FileManager(TEST_FILE_PATH); Assert.AreEqual("Here is some test content.", fileManager.GetContent()); }