Mam klasę:
using System;
using System.IO;
using System.Text;
namespace NetLogger.Core.Logging
{
internal class FileLogger : ILogger, IDisposable
{
private static Encoding UTF8NoBOM = new UTF8Encoding(false, true);
private StreamWriter writer;
public FileLogger(string path) : this(path, false, UTF8NoBOM)
{
}
public FileLogger(string path, bool append) : this(path, append, UTF8NoBOM)
{
}
public FileLogger(string path, bool append, Encoding encoding)
{
this.Encoding = encoding;
this.Path = path;
this.writer = new StreamWriter(path, append, encoding);
}
public Encoding Encoding { get; private set; }
public string Path { get; private set; }
public void Log<T>(T data, Func<T, string> formatter = null)
{
if (data == null) throw new ArgumentNullException("data");
this.writer.WriteLine(formatter != null ? formatter(data) : data.ToString());
this.writer.Flush();
}
#region IDisposable Support
private bool disposedValue = false;
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
if (writer != null)
{
writer.Close();
writer = null;
}
}
disposedValue = true;
}
}
#endregion IDisposable Support
}
}
Uczę się nieco o testach jednostkowych, zabrałem się za bibliotekę NUnit oraz Moq, ale bladego pojęcia nie mam jak przetestować tą klasę? Chciałbym przetestować funkcję Log, pod kątem czy rzuca wyjątek jak prześlemy null, czy odpowiednio formatuje obiekty itp. Z tego co czytałem funkcje powinny być odizolowane od systemu, a tam siedzi SteamWriter więc jak to ogarnąć?