From baaa6019232f986c7fa4a01a616466fb66af582b Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 3 Oct 2017 10:14:22 +0200 Subject: [PATCH 1/7] open/closed and factory for file writer. --- src/TestabilityKata/Program.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index 7063ab2..a89759e 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -9,7 +9,9 @@ public static void Main(string[] args) { new Program( new Logger( - new MailSender()), + new MailSender(), + new CustomFileWriterFactory( + new MailSender())), new MailSender()) .Run(); } @@ -51,11 +53,14 @@ public class Logger //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) @@ -66,7 +71,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 @@ -88,6 +93,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; From 862afd62aa412dbffc6e503ef4bd780659f692df Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 3 Oct 2017 10:37:45 +0200 Subject: [PATCH 2/7] Revert "open/closed and factory for file writer." This reverts commit baaa6019232f986c7fa4a01a616466fb66af582b. --- src/TestabilityKata/Program.cs | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index a89759e..7063ab2 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -9,9 +9,7 @@ public static void Main(string[] args) { new Program( new Logger( - new MailSender(), - new CustomFileWriterFactory( - new MailSender())), + new MailSender()), new MailSender()) .Run(); } @@ -53,14 +51,11 @@ public class Logger //see the next step for that. private readonly MailSender mailSender; - private readonly CustomFileWriterFactory customFileWriterFactory; public Logger( - MailSender mailSender, - CustomFileWriterFactory customFileWriterFactory) + MailSender mailSender) { this.mailSender = mailSender; - this.customFileWriterFactory = customFileWriterFactory; } public void Log(LogLevel logLevel, string logText) @@ -71,7 +66,7 @@ public void Log(LogLevel logLevel, string logText) { //also log to file - var writer = customFileWriterFactory.Create(@"C:\" + logLevel + "-annoying-log-file.txt"); + var writer = new CustomFileWriter(mailSender, @"C:\" + logLevel + "-annoying-log-file.txt"); writer.AppendLine(logText); //send e-mail about error @@ -93,24 +88,6 @@ 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; From c0dfd028c5ca638dae7fc6c326c5e003cad9592a Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 3 Oct 2017 10:14:22 +0200 Subject: [PATCH 3/7] open/closed and factory for file writer. --- src/TestabilityKata/Program.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index 7063ab2..a89759e 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -9,7 +9,9 @@ public static void Main(string[] args) { new Program( new Logger( - new MailSender()), + new MailSender(), + new CustomFileWriterFactory( + new MailSender())), new MailSender()) .Run(); } @@ -51,11 +53,14 @@ public class Logger //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) @@ -66,7 +71,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 @@ -88,6 +93,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; From 24580829db1e7926c7d3b24eed5fe5388d40de4d Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Wed, 4 Oct 2017 00:18:49 +0200 Subject: [PATCH 4/7] removal of comment. --- src/TestabilityKata/Program.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index a89759e..6c366bc 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -49,9 +49,6 @@ 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; From 6c22af4d0c2297b7898af4a4cd5fc5bef934f92e Mon Sep 17 00:00:00 2001 From: Mathias Lykkegaard Lorenzen Date: Fri, 6 Oct 2017 01:19:42 +0200 Subject: [PATCH 5/7] Update Program.cs --- src/TestabilityKata/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index 6c366bc..6c3453d 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -7,12 +7,12 @@ public class Program { public static void Main(string[] args) { + var mailSender = new MailSender(); new Program( new Logger( - new MailSender(), - new CustomFileWriterFactory( - new MailSender())), - new MailSender()) + mailSender, + new CustomFileWriterFactory(mailSender)), + mailSender) .Run(); } From 7e020acbd141a189b8392b031d9aba032ceb9025 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 19 Oct 2021 10:49:28 +0200 Subject: [PATCH 6/7] indentation. --- src/TestabilityKata/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestabilityKata/Program.cs b/src/TestabilityKata/Program.cs index ced5529..d11291e 100644 --- a/src/TestabilityKata/Program.cs +++ b/src/TestabilityKata/Program.cs @@ -128,7 +128,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."); + mailSender.SendMail("mathias.lorenzen@mailinator.com", "The file " + FilePath + " was created since it didn't exist."); File.WriteAllText(FilePath, ""); } From cdf0b18012c1efb055ddcfe43920c0af975ad9a4 Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 15 Jun 2022 08:30:33 +0200 Subject: [PATCH 7/7] Updated packages. --- .../TestabilityKata.Tests.csproj | 12 ++++++------ src/TestabilityKata/TestabilityKata.csproj | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) 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/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