From c8dffe209fbef7f4e309584300ebda99ec528d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPete?= Date: Tue, 22 Jun 2021 16:32:00 -0400 Subject: [PATCH] Added Shouldly and updated all tests --- .../CandidateManager.Tests.csproj | 1 + src/CandidateManager.Tests/CandidateTests.cs | 121 ++++++++++-------- 2 files changed, 72 insertions(+), 50 deletions(-) diff --git a/src/CandidateManager.Tests/CandidateManager.Tests.csproj b/src/CandidateManager.Tests/CandidateManager.Tests.csproj index 08b4eb2..76ac905 100644 --- a/src/CandidateManager.Tests/CandidateManager.Tests.csproj +++ b/src/CandidateManager.Tests/CandidateManager.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/src/CandidateManager.Tests/CandidateTests.cs b/src/CandidateManager.Tests/CandidateTests.cs index 0255b30..3750ee7 100644 --- a/src/CandidateManager.Tests/CandidateTests.cs +++ b/src/CandidateManager.Tests/CandidateTests.cs @@ -6,6 +6,7 @@ using CandidateManager.Core.Interfaces; using CandidateManager.Core.Processors; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; namespace CandidateManager.Tests { @@ -15,15 +16,15 @@ public class CandidateTests [TestMethod] public void ShouldThrowWithEmptyName() { - Assert.ThrowsException(() => new Candidate("", "pskelly@threewill.com", "999-0000","ThreeWill")); - Assert.ThrowsException(() => new Candidate(null, "pskelly@threewill.com","999-0000","ThreeWill")); + Should.Throw(() => new Candidate("", "pskelly@threewill.com","999-0000","ThreeWill")); + Should.Throw(() => new Candidate(null, "pskelly@threewill.com","999-0000","ThreeWill")); } [TestMethod] public void ShouldThrowWithEmptyOrNullPhone() { - Assert.ThrowsException(() => new Candidate("Pete Skelly", "", "999-0000", "ThreeWill")); - Assert.ThrowsException(() => new Candidate("Pete Skelly", null, "999-0000", "ThreeWill")); + Should.Throw(() => new Candidate("Pete Skelly", "", "999-0000", "ThreeWill")); + Should.Throw(() => new Candidate("Pete Skelly", null, "999-0000", "ThreeWill")); } [TestMethod] @@ -31,117 +32,137 @@ public void ShouldThrowWithNullOrEmptyEmail() { Assert.ThrowsException(() => new Candidate("Pete Skelly", "", "555-9999", "ThreeWill")); Assert.ThrowsException(() => new Candidate("Pete Skelly", null, "555-9999", "ThreeWill")); + + Should.Throw(() => new Candidate("Pete Skelly", "", "555-9999", "ThreeWill")); + Should.Throw(() => new Candidate("Pete Skelly", null, "555-9999", "ThreeWill")); + } [TestMethod] public void ShouldThrowWithNullOrEmptyCompany() { - Assert.ThrowsException(() => new Candidate("Pete Skelly", "", "555-9999", "")); - Assert.ThrowsException(() => new Candidate("Pete Skelly", null, "555-9999", null)); + Should.Throw(() => new Candidate("Pete Skelly", "", "555-9999", "")); + Should.Throw(() => new Candidate("Pete Skelly", null, "555-9999", null)); } [TestMethod] public void DeserilaizesThreeWillIngest() { + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../ThreeWillFlowInput.json"); string flowMessage = File.ReadAllText(filePath); - JsonSerializerOptions options = new() { - WriteIndented = true, - PropertyNameCaseInsensitive = true - }; - FlowIngest flowInput = JsonSerializer.Deserialize(flowMessage,options); - Assert.AreEqual(flowInput.Recruiter, "pskelly@threewill.com"); - Assert.AreEqual(flowInput.Company, "ThreeWill"); - Assert.AreEqual(flowInput.FileName, "8e294c8c-b3a2-43f8-8d91-51acf75fc5e4.docx"); + + //Act + FlowIngest flowInput = flowMessage.FromJson(); + + //Assert + flowInput.Recruiter.ShouldBe("pskelly@threewill.com"); + flowInput.Company.ShouldBe("ThreeWill"); + flowInput.FileName.ShouldBe("8e294c8c-b3a2-43f8-8d91-51acf75fc5e4.docx"); + } [TestMethod] public void DeserilaizesThompsonIngest() { + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../ThompsonFlowInput.json"); string flowMessage = File.ReadAllText(filePath); + + //Act FlowIngest flowInput = flowMessage.FromJson(); - Assert.AreEqual(flowInput.Recruiter, "pskelly@threewill.com"); - Assert.AreEqual(flowInput.Company, "Thompson"); - Assert.AreEqual(flowInput.FileName, "5085578f-e0c1-4dd6-9d5e-80b7d2615d66.doc"); + + //Assert + flowInput.Recruiter.ShouldBe("pskelly@threewill.com"); + flowInput.Company.ShouldBe("Thompson"); + flowInput.FileName.ShouldBe("5085578f-e0c1-4dd6-9d5e-80b7d2615d66.doc"); } [TestMethod] public void DeserilaizesHireNetworksIngest() { + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../HireNetworksFloInput.json"); string flowMessage = File.ReadAllText(filePath); + + //Act FlowIngest flowInput = flowMessage.FromJson(); - Assert.AreEqual(flowInput.Recruiter, "pskelly@threewill.com"); - Assert.AreEqual(flowInput.Company, "HireNetworks"); - Assert.AreEqual(flowInput.FileName, "87048d1a-985a-4705-8eed-6f1562a98ea3.docx"); + + //Assert + flowInput.Recruiter.ShouldBe("pskelly@threewill.com"); + flowInput.Company.ShouldBe("HireNetworks"); + flowInput.FileName.ShouldBe("87048d1a-985a-4705-8eed-6f1562a98ea3.docx"); } [TestMethod] public void DoesDeserilaizeThreeWillCandidate() { + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../ThreeWillFlowInput.json"); string flowMessage = File.ReadAllText(filePath); - FlowIngest flowInput = flowMessage.FromJson(); - Assert.AreEqual("pskelly@threewill.com", flowInput.Recruiter); - Assert.AreEqual("ThreeWill", flowInput.Company); - Assert.AreEqual("8e294c8c-b3a2-43f8-8d91-51acf75fc5e4.docx", flowInput.FileName); - + + //Act + FlowIngest flowInput = flowMessage.FromJson(); ICandidateProcessor processor = CandidateProcessorFactory.CreateCandidateProcessor(flowInput.Company); - - Assert.IsInstanceOfType(processor, typeof(ThreeWillCandidateProcessor)); Candidate candidate = processor.Process(flowInput.BodyHtml); - Assert.AreEqual("ThreeWill", candidate.Company); - Assert.AreEqual("Timm Peddie", candidate.Name); - Assert.AreEqual("(415) 484-3004", candidate.Phone); - Assert.AreEqual("timm_peddie@yahoo.com", candidate.EmailAddress); + + //Assert + processor.ShouldBeAssignableTo(); + candidate.Company.ShouldBe("ThreeWill"); + candidate.Name.ShouldBe("Timm Peddie"); + candidate.Phone.ShouldBe("(415) 484-3004"); + candidate.EmailAddress.ShouldBe("timm_peddie@yahoo.com"); } [TestMethod] public void DoesDeserilaizeThompsonCandidate() { + + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../ThompsonFlowInput.json"); string flowMessage = File.ReadAllText(filePath); - FlowIngest flowInput = flowMessage.FromJson(); - Assert.AreEqual("pskelly@threewill.com", flowInput.Recruiter); - Assert.AreEqual("Thompson", flowInput.Company); - Assert.AreEqual("5085578f-e0c1-4dd6-9d5e-80b7d2615d66.doc", flowInput.FileName); + //Act + FlowIngest flowInput = flowMessage.FromJson(); ICandidateProcessor processor = CandidateProcessorFactory.CreateCandidateProcessor(flowInput.Company); - - Assert.IsInstanceOfType(processor, typeof(ThompsonCandidateProcessor)); Candidate candidate = processor.Process(flowInput.BodyHtml); - Assert.AreEqual("Thompson", candidate.Company); - Assert.AreEqual("Sean Jones", candidate.Name); - Assert.AreEqual("(508) 410-5429", candidate.Phone); - Assert.AreEqual("seanj516@gmail.com", candidate.EmailAddress); + + //Assert + processor.ShouldBeAssignableTo(); + candidate.Company.ShouldBe("Thompson"); + candidate.Name.ShouldBe("Sean Jones"); + candidate.Phone.ShouldBe("(508) 410-5429"); + candidate.EmailAddress.ShouldBe("seanj516@gmail.com"); + } [TestMethod] public void DoesDeserilaizeStratfieldCandidate() { + + //Arrange string curDir = Directory.GetCurrentDirectory(); string filePath = Path.Combine(curDir, "../../../StratfieldFlowInput.json"); string flowMessage = File.ReadAllText(filePath); + + //Act FlowIngest flowInput = flowMessage.FromJson(); - Assert.AreEqual("ebrady@stratfieldconsulting.com", flowInput.Recruiter); - Assert.AreEqual("Stratfield", flowInput.Company); - Assert.AreEqual("8b4a016a-a33d-416d-811c-204c4795b86a.docx", flowInput.FileName); - ICandidateProcessor processor = CandidateProcessorFactory.CreateCandidateProcessor(flowInput.Company); - Assert.IsInstanceOfType(processor, typeof(StratfieldCandidateProcessor)); Candidate candidate = processor.Process(flowInput.BodyHtml); - Assert.AreEqual("Stratfield", candidate.Company); - Assert.AreEqual("Jean-Patrick Guichard", candidate.Name); - Assert.AreEqual(Constants.FIELD_DEFAULT, candidate.Phone); - Assert.AreEqual(Constants.FIELD_DEFAULT, candidate.EmailAddress); + + //Assert + processor.ShouldBeAssignableTo(); + candidate.Company.ShouldBe("Stratfield"); + candidate.Name.ShouldBe("Jean-Patrick Guichard"); + candidate.Phone.ShouldBe(Constants.FIELD_DEFAULT); + candidate.EmailAddress.ShouldBe(Constants.FIELD_DEFAULT); } } }