From 66d2fe9134fc0e5a8be163808046929c1c2b8925 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 3 Oct 2017 13:14:49 +0200 Subject: [PATCH 1/4] refactoring. --- .../CustomFileWriterTest.cs | 19 +++++++++----- src/TestabilityKata.Tests/MailSenderTest.cs | 9 ++++++- src/TestabilityKata.Tests/ProgramTest.cs | 26 ++++++++++--------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/TestabilityKata.Tests/CustomFileWriterTest.cs b/src/TestabilityKata.Tests/CustomFileWriterTest.cs index b0cf46c..aab5692 100644 --- a/src/TestabilityKata.Tests/CustomFileWriterTest.cs +++ b/src/TestabilityKata.Tests/CustomFileWriterTest.cs @@ -10,24 +10,31 @@ namespace TestabilityKata.Tests [TestClass] public class CustomFileWriterTest { + private IMailSender fakeMailSender; + + [TestInitialize] + public void Initialize() + { + fakeMailSender = Substitute.For(); + } + [TestMethod] public void WhenCreatingFileAnEmailIsSentOut() { - var fakeMailSender = Substitute.For(); - const string testFilePath = @"C:\WhenCreatingFileAnEmailIsSentOut.txt"; + var customFileWriter = new CustomFileWriter( + fakeMailSender, + testFilePath); + //if the existing file exists, delete it before running the test, since //we need to get to the point where a new file is created. - if(File.Exists(testFilePath)) + if (File.Exists(testFilePath)) { File.SetAttributes(testFilePath, FileAttributes.Normal); File.Delete(testFilePath); } - var customFileWriter = new CustomFileWriter( - fakeMailSender, - testFilePath); customFileWriter.AppendLine("Some line"); fakeMailSender diff --git a/src/TestabilityKata.Tests/MailSenderTest.cs b/src/TestabilityKata.Tests/MailSenderTest.cs index 358b5b6..5d1c3e2 100644 --- a/src/TestabilityKata.Tests/MailSenderTest.cs +++ b/src/TestabilityKata.Tests/MailSenderTest.cs @@ -8,11 +8,18 @@ namespace TestabilityKata.Tests [TestClass] public class MailSenderTest { + private IMailSender mailSender; + + [TestInitialize] + public void Initialize() + { + mailSender = new MailSender(); + } + [TestMethod] [ExpectedException(typeof(ArgumentException))] public void MailSenderThrowsExceptionIfEmailIsInvalid() { - var mailSender = new MailSender(); mailSender.SendMail("my-invalid-email", "some content"); } } diff --git a/src/TestabilityKata.Tests/ProgramTest.cs b/src/TestabilityKata.Tests/ProgramTest.cs index 9aa99b9..8e61b38 100644 --- a/src/TestabilityKata.Tests/ProgramTest.cs +++ b/src/TestabilityKata.Tests/ProgramTest.cs @@ -9,16 +9,25 @@ namespace TestabilityKata.Tests [TestClass] public class ProgramTest { - [TestMethod] - public void ProgramSendsEmailWhenStartingUp() + private IMailSender fakeMailSender; + private ILogger fakeLogger; + + private IProgram program; + + [TestInitialize] + public void Initialize() { - var fakeMailSender = Substitute.For(); - var fakeLogger = Substitute.For(); + fakeMailSender = Substitute.For(); + fakeLogger = Substitute.For(); - var program = new Program( + program = new Program( fakeLogger, fakeMailSender); + } + [TestMethod] + public void ProgramSendsEmailWhenStartingUp() + { program.Run(); //we here make sure that SendMail was called @@ -34,13 +43,6 @@ public void ProgramSendsEmailWhenStartingUp() [TestMethod] public void ProgramLogsErrorWhenExceptionIsThrown() { - var fakeMailSender = Substitute.For(); - var fakeLogger = Substitute.For(); - - var program = new Program( - fakeLogger, - fakeMailSender); - //we here make the EmailSender's SendMail throw an exception no //matter what arguments it was called with. fakeMailSender From a95279e27c69baa46e1a78a029e9a975693fef15 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Tue, 19 Oct 2021 10:52:32 +0200 Subject: [PATCH 2/4] 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 7da5f4a..83a2050 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 7266487fee9d2b29461b7bf1406b0128df8345cc Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Thu, 21 Oct 2021 13:36:23 +0200 Subject: [PATCH 3/4] indent. --- src/TestabilityKata.Tests/CustomFileWriterTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestabilityKata.Tests/CustomFileWriterTest.cs b/src/TestabilityKata.Tests/CustomFileWriterTest.cs index aab5692..b7d80cb 100644 --- a/src/TestabilityKata.Tests/CustomFileWriterTest.cs +++ b/src/TestabilityKata.Tests/CustomFileWriterTest.cs @@ -29,7 +29,7 @@ public void WhenCreatingFileAnEmailIsSentOut() //if the existing file exists, delete it before running the test, since //we need to get to the point where a new file is created. - if (File.Exists(testFilePath)) + if(File.Exists(testFilePath)) { File.SetAttributes(testFilePath, FileAttributes.Normal); File.Delete(testFilePath); From cdf0b18012c1efb055ddcfe43920c0af975ad9a4 Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 15 Jun 2022 08:30:33 +0200 Subject: [PATCH 4/4] 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