private IEnumerable <Markdown.IElement> Step4DocumentTheRequirement() { yield return(new Markdown.Header3("Fourth step: document the requirement")); yield return(new Markdown.Paragraph("TODO")); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.Step4Sample)))); }
private IEnumerable <Markdown.IElement> Sample1() { var balance = -10; this.Act(() => this.QuickSample1(balance) ) .AssertException($"balance cannot be < 0 and actually is {balance}"); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.QuickSample1)))); }
private IEnumerable <Markdown.IElement> Sample2() { TransactionType transactionType = TransactionType.OnlinePayment; double? onlinePaymentLimit = 10; double paymentAmount = 11; this.Act(() => this.QuickSample2(transactionType, onlinePaymentLimit, paymentAmount) ) .AssertException($"Online Payment Amount ({paymentAmount}) exceeds the Online Payment Limit ({onlinePaymentLimit})"); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.QuickSample2)))); }
private IEnumerable <Markdown.IElement> Step2MakeItWorking() { yield return(new Markdown.Header3("Second step: make it working")); yield return(new Markdown.Paragraph("When time comes you should implement the business requirement. It might look like that:")); var withdrawLimit = 100; var withdrawAmount = 110; this.Act(() => this.Step2Sample(withdrawLimit, withdrawAmount) ) .AssertException($"Withdraw Amount ({withdrawAmount}) exceeds the Withdraw Limit ({withdrawLimit})"); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.Step2Sample)))); yield return(new Markdown.Paragraph("This sample is simplified for sure, but remember that simple solutions are the best.")); }
private IEnumerable <Markdown.IElement> Step1GatherRequirements() { yield return(new Markdown.Header3("First step: business requirements gathering")); yield return(new Markdown.Paragraph("Quite often you might hear during analysis phase of your project such words:")); yield return(new Markdown.Quote("When withdraw limit is set, withdrawn amount cannot exceed the limit")); yield return(new Markdown.Paragraph("When you hear such sentence just start your development by writing it down like that:")); this.Act(() => this.Step1Sample() ) .AssertException("NOT IMPLEMENTED"); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.Step1Sample)))); yield return(new Markdown.Paragraph("This will throw `NotImplementedException` for sure. But we have not finished our job yet.")); }
private IEnumerable <Markdown.IElement> Step3IntroduceDedicatedException() { yield return(new Markdown.Header3("Third step: introduce dedicated exception")); yield return(new Markdown.Paragraph($"I like this step very much. Instead of using some generic exception thrown by" + $" `{nameof(Business.Requirement.Throws)}()` method introduce your own meaningful exception:")); var withdrawLimit = 100; var withdrawAmount = 110; this.Act(() => this.Step3Sample(withdrawLimit, withdrawAmount) ) .AssertException($"Withdraw Amount ({withdrawAmount}) exceeds the Withdraw Limit ({withdrawLimit})"); yield return(new Markdown.Code(ClassReader.ReadMethodBody(nameof(this.Step3Sample)))); yield return(new Markdown.Paragraph("Introducing dedicated exception is not always needed. " + "It allows you to handle (catch) some situations properly. " + "It also gives you a way to derive all thrown business exceptions from your own base `Exception` class.")); }
public static string?Read(string method) { return(ClassReader.ReadMethodBody(method)); }