-
-
Save nafg/f998409f9ef263d5e085 to your computer and use it in GitHub Desktop.
Revisions
-
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ [Fact] public void FunctionalTest() { // arrange var expectedCustomer = new Customer("[email protected]"); var expectedReportBody = "the report body"; Func<IEnumerable<Customer>> getCustomersForCustomerReport = () => new[] {expectedCustomer}; Func<Customer, Report> createCustomerReport = customer => new Report(expectedCustomer.Email, expectedReportBody); var actualToAddress = ""; var actualBody = ""; Action<string, string> sendEmail = (toAddress, body) => { actualToAddress = toAddress; actualBody = body; }; // act Functional.RunCustomerReportBatch(getCustomersForCustomerReport, createCustomerReport, sendEmail); // assert Assert.Equal(expectedCustomer.Email, actualToAddress); Assert.Equal(expectedReportBody, actualBody); } -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ public static Action Compose() { return () => RunCustomerReportBatch( GetCustomersForCustomerReport, CreateCustomerReport, SendEmail); } -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ public static void RunCustomerReportBatch( Func<IEnumerable<Customer>> getCustomersForCustomerReport, Func<Customer, Report> createCustomerReport, Action<string, string> sendEmail) { var customers = getCustomersForCustomerReport(); foreach (var customer in customers) { var report = createCustomerReport(customer); sendEmail(report.ToAddress, report.Body); } } -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ public static IEnumerable<Customer> GetCustomersForCustomerReport() { // pretend to do data access yield return new Customer("[email protected]"); yield return new Customer("[email protected]"); yield return new Customer("[email protected]"); } public static Report CreateCustomerReport(Customer customer) { return new Report(customer.Email, $"This is the report for {customer.Email}!"); } public static void SendEmail(string toAddress, string body) { // pretend to send an email here Console.Out.WriteLine("Sent Email to: {0}, Body: '{1}'", toAddress, body); } -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ var dependency = new ThingThatImplementsIDependency(); // RelyOnThing is something that that takes Action<string> as a dependency. Action relyOnThing = () => RelyOnThing(arg => DoThing(dependency, arg)); -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ public static void DoThing(IDependency dependency, string arg) { } -
mikehadlow revised this gist
Aug 7, 2015 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ public class Thing : IThing { public Thing(IDependency dependency) { } public void Do(string arg) { } } -
mikehadlow renamed this gist
Aug 4, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ [Fact] public void RunCustomerReportBatchShouldSendReports() { // Arrange var customerDataMock = new Mock<ICustomerData>(); -
mikehadlow revised this gist
Aug 4, 2015 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ [Fact] public void ObjectOrientedTest() { // Arrange var customerDataMock = new Mock<ICustomerData>(); var reportBuilderMock = new Mock<IReportBuilder>(); var emailerMock = new Mock<IEmailer>(); var expectedCustomer = new Customer("[email protected]"); var expectedReportBody = "the report body"; customerDataMock.Setup(x => x.GetCustomersForCustomerReport()) .Returns(new[] { expectedCustomer }); reportBuilderMock.Setup(x => x.CreateCustomerReport(expectedCustomer)) .Returns(new Report(expectedCustomer.Email, expectedReportBody)); var sut = new ReportingService( customerDataMock.Object, reportBuilderMock.Object, emailerMock.Object); // Act sut.RunCustomerReportBatch(); // Assert emailerMock.Verify(x => x.Send(expectedCustomer.Email, expectedReportBody)); } -
mikehadlow revised this gist
Aug 4, 2015 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ public static ReportingService Compose() { return new ReportingService( new CustomerData(), new ReportBuilder(), new Emailer() ); } -
mikehadlow revised this gist
Aug 4, 2015 . 1 changed file with 24 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ public class ReportingService { public ReportingService(ICustomerData customerData, IReportBuilder reportBuilder, IEmailer emailer) { CustomerData = customerData; ReportBuilder = reportBuilder; Emailer = emailer; } public ICustomerData CustomerData { get; private set; } public IReportBuilder ReportBuilder { get; private set; } public IEmailer Emailer { get; private set; } public void RunCustomerReportBatch() { var customers = CustomerData.GetCustomersForCustomerReport(); foreach (var customer in customers) { var report = ReportBuilder.CreateCustomerReport(customer); Emailer.Send(report.ToAddress, report.Body); } } } -
mikehadlow revised this gist
Aug 4, 2015 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ public class CustomerData : ICustomerData { public IEnumerable<Customer> GetCustomersForCustomerReport() { // pretend to do data access yield return new Customer("[email protected]"); yield return new Customer("[email protected]"); yield return new Customer("[email protected]"); } } public class ReportBuilder : IReportBuilder { public Report CreateCustomerReport(Customer customer) { return new Report(customer.Email, $"This is the report for {customer.Email}!"); } } public class Emailer : IEmailer { public void Send(string toAddress, string body) { // pretend to send an email here Console.Out.WriteLine("Sent Email to: {0}, Body: '{1}'", toAddress, body); } } -
mikehadlow created this gist
Aug 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ public interface ICustomerData { IEnumerable<Customer> GetCustomersForCustomerReport(); } public interface IReportBuilder { Report CreateCustomerReport(Customer customer); } public interface IEmailer { void Send(string toAddress, string body); }