diff --git a/src/TestabilityKata.Tests/TestabilityKata.Tests.csproj b/src/TestabilityKata.Tests/TestabilityKata.Tests.csproj index f8c14f3..14ce7f0 100644 --- a/src/TestabilityKata.Tests/TestabilityKata.Tests.csproj +++ b/src/TestabilityKata.Tests/TestabilityKata.Tests.csproj @@ -1,17 +1,17 @@ - netcoreapp2.0 + net6.0 false - - - - - + + + + + diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index 64971c8..88e9322 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -9,7 +9,9 @@ public static void Main(string[] args) { var mailSender = new MailSender(); new Program( - new Logger(mailSender), + new Logger( + mailSender, + new CustomFileWriterFactory(mailSender)), mailSender) .Run(); } @@ -49,15 +51,15 @@ public enum LogLevel public class Logger { - //we can't do CustomFileWriter yet, because its file name depends on the log level. - //see the next step for that. - private readonly MailSender mailSender; + private readonly CustomFileWriterFactory customFileWriterFactory; public Logger( - MailSender mailSender) + MailSender mailSender, + CustomFileWriterFactory customFileWriterFactory) { this.mailSender = mailSender; + this.customFileWriterFactory = customFileWriterFactory; } public void Log(LogLevel logLevel, string logText) @@ -68,7 +70,7 @@ public void Log(LogLevel logLevel, string logText) { //also log to file - var writer = new CustomFileWriter(mailSender, @"C:\" + logLevel + "-annoying-log-file.txt"); + var writer = customFileWriterFactory.Create(@"C:\" + logLevel + "-annoying-log-file.txt"); writer.AppendLine(logText); //send e-mail about error @@ -90,6 +92,24 @@ public void SendMail(string recipient, string content) } } + public class CustomFileWriterFactory + { + private readonly MailSender mailSender; + + public CustomFileWriterFactory( + MailSender mailSender) + { + this.mailSender = mailSender; + } + + public CustomFileWriter Create(string filePath) + { + return new CustomFileWriter( + mailSender, + filePath); + } + } + public class CustomFileWriter { private readonly MailSender mailSender; diff --git a/src/TestabilityKata/TestabilityKata.csproj b/src/TestabilityKata/TestabilityKata.csproj index ce1697a..41f1d5a 100644 --- a/src/TestabilityKata/TestabilityKata.csproj +++ b/src/TestabilityKata/TestabilityKata.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + net6.0