using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;
using Systin.Library;
namespace Systin.Library.UnitTests{
[TestFixture]
public class FileReaderUnitTest
{
const string PathToTestTextFile = @"E:\Projects\Systin\TestDirectory\TestSuite\Test.txt";
const string ExpectedTextContained = @"Test_Method_called";
/// <summary>
/// Loadeds the test file does not return null value.
/// </summary>
[Test]
[Category("FileAccess")]
public void LoadedTestFileDoesNotReturnNullValue()
{
TestFileLoader readFile = this.LoadTestTextFile();
Assert.IsNotNull(readFile, "Attempt to read test file resulted in null object returned");
}
/// <summary>
/// Loadeds the test file contains expected string.
/// </summary>
[Test]
public void FileReaderFactoryCreatorCreatesEmptyFileReaderObject()
{
TestFileLoader file = TestFileLoader.Factory();
Assert.IsNotNull(file, "The File reader object returned is null when it should not be");
Assert.AreEqual(file.FileName, String.Empty, "TestFileName is not empty");
}
/// <summary>
/// Opens the test file method accepts test file info as input.
/// </summary>
[Test]
[Category("FileAccess")]
public void OpenTestFileMethodAcceptsTestFileInfoAsInput()
{
FileInfo file = new FileInfo(PathToTestTextFile);
TestFileLoader testInputFile = TestFileLoader.OpenTestFile(file);
Assert.AreEqual(testInputFile.FileHandle.FullName, PathToTestTextFile);
}
/// <summary>
/// Attempts to load instructions with A null file reader object.
/// </summary>
[Test]
[ExpectedException(typeof(ArgumentException))]
public void AttemptToLoadInstructionsWithANullFileReaderObject()
{
TestFileLoader emptyInputFile = TestFileLoader.Factory();
TestFileLoader.LoadInstructionFileContent(emptyInputFile);
}
/// <summary>
/// Gets the instructions from A valid test input file.
/// </summary>
[Test]
[Category("FileAccess")]
[Ignore("Instructions object on inputFile value is null for some reason")]
public void GetInstructionsFromAValidTestInputFile()
{
TestFileLoader inputFile = this.LoadTestTextFile();
TestFileLoader.LoadInstructionFileContent(inputFile);
Assert.IsTrue(inputFile.TestFileContent.Length > 0);
Assert.IsTrue(inputFile.Instructions.Count > 0);
}
/// <summary>
/// Opens the and process input file processes test input correctly.
/// </summary>
[Test]
[Category("FileAccess")]
public void OpenAndProcessInputFileProcessesTestInputCorrectly()
{
TestFileLoader inputFile = TestFileLoader.OpenAndProcessInputFile(this.GetTestFileInfoObject());
Assert.IsTrue(inputFile.TestFileContent.Length > 0);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void LoadContentsWithANullFile()
{
TestFileLoader.LoadInstructionFileContent(null);
}
#region Helper methods
private FileInfo GetTestFileInfoObject()
{
return new FileInfo(PathToTestTextFile);
}
private TestFileLoader LoadTestTextFile()
{
return (TestFileLoader.OpenTestFile(new FileInfo(PathToTestTextFile)));
}
#endregion
}
}
|