Skip to content
23 changes: 14 additions & 9 deletions src/TestabilityKata/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ namespace TestabilityKata
public class Program
{
public static void Main(string[] args)
{
new Program().Run();
}

public void Run()
{
try
{
Logger.Log(LogLevel.Information, "Program is starting up or whatever");
MailSender.SendMail("some-invalid-email-address.com", "Program has started.");
new Logger().Log(LogLevel.Information, "Program is starting up or whatever");
new MailSender().SendMail("some-invalid-email-address.com", "Program has started.");
}
catch(Exception ex)
{
Logger.Log(LogLevel.Error, "An error occured: " + ex);
new Logger().Log(LogLevel.Error, "An error occured: " + ex);
}
}
}
Expand All @@ -27,9 +32,9 @@ public enum LogLevel
Error
}

public static class Logger
public class Logger
{
public static void Log(LogLevel logLevel, string logText)
public void Log(LogLevel logLevel, string logText)
{
Console.WriteLine(logLevel + ": " + logText);

Expand All @@ -41,15 +46,15 @@ public static void Log(LogLevel logLevel, string logText)
writer.AppendLine(logText);

//send e-mail about error
MailSender.SendMail("mathias.lorenzen@mailinator.com", logText);
new MailSender().SendMail("mathias.lorenzen@mailinator.com", logText);

}
}
}

public static class MailSender
public class MailSender
{
public static void SendMail(string recipient, string content)
public void SendMail(string recipient, string content)
{
if (!recipient.Contains("@"))
throw new ArgumentException("The recipient must be a valid e-mail.", nameof(recipient));
Expand All @@ -73,7 +78,7 @@ public void AppendLine(string line)
lock(typeof(CustomFileWriter)) {
if (!File.Exists(FilePath))
{
MailSender.SendMail("mathias.lorenzen@mailinator.com", "The file " + FilePath + " was created since it didn't exist.");
new MailSender().SendMail("mathias.lorenzen@mailinator.com", "The file " + FilePath + " was created since it didn't exist.");
File.WriteAllText(FilePath, "");
}

Expand Down