80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System.Reflection;
|
|
using log4net;
|
|
|
|
namespace skyscraper8.Tests.NUnit;
|
|
|
|
[NonParallelizable]
|
|
public class SkyscrapersTestingFramework
|
|
{
|
|
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
|
|
private static Guid? _sessionId;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
if (_sessionId == null)
|
|
{
|
|
_sessionId = Guid.NewGuid();
|
|
Console.WriteLine("New session: " + _sessionId);
|
|
}
|
|
Console.WriteLine("Setup");
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
Console.WriteLine("TearDown");
|
|
|
|
TestContext currentContext = TestContext.CurrentContext;
|
|
}
|
|
|
|
public TException AssertTargetInvocation<TException>(TestDelegate action)
|
|
where TException : Exception
|
|
{
|
|
TargetInvocationException exeption = Assert.Throws<TargetInvocationException>(action);
|
|
|
|
Assert.That(exeption.InnerException, Is.TypeOf<TException>());
|
|
|
|
return (TException)exeption.InnerException;
|
|
}
|
|
|
|
private DirectoryInfo _samplesDirectory;
|
|
private DirectoryInfo GetSamplesDirectory()
|
|
{
|
|
if (_samplesDirectory == null)
|
|
{
|
|
FileInfo fi = new FileInfo("sample_path.txt");
|
|
if (!fi.Exists)
|
|
{
|
|
logger.WarnFormat("Could not find {0}", fi.FullName);
|
|
}
|
|
else
|
|
{
|
|
logger.InfoFormat("Reading samples path from: {0}", fi.FullName);
|
|
string readAllText = File.ReadAllText(fi.FullName).Trim();
|
|
_samplesDirectory = new DirectoryInfo(readAllText);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
if (_samplesDirectory == null)
|
|
{
|
|
Assert.Inconclusive("Could not find samples directory");
|
|
}
|
|
|
|
return _samplesDirectory;
|
|
}
|
|
|
|
protected FileStream GetStreamSample(string filename)
|
|
{
|
|
DirectoryInfo samplesDirectory = GetSamplesDirectory();
|
|
FileInfo file = new FileInfo(Path.Combine(samplesDirectory.FullName, filename));
|
|
if (!file.Exists)
|
|
{
|
|
Assert.Inconclusive(String.Format("Could not find sample file: {0}", file.FullName));
|
|
}
|
|
return file.OpenRead();
|
|
}
|
|
}
|