-
-
Save JayBazuzi/3cbd1d60f746c6cf434f32aeb6c64d85 to your computer and use it in GitHub Desktop.
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 characters
| interface ITaxInfo { | |
| async GetTaxInfo(sin: SIN) -> TaxInfo? | |
| class Error {} | |
| } | |
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 characters
| abstract class TaxInfoTests(subject: ITaxInfo) { | |
| Null_when_SIN_does_not_exist() { | |
| result = subject.GetTaxInfo(A_SIN_WHICH_DOES_NOT_EXIST); | |
| Assert.IsNull(result) | |
| } | |
| class Fake : TaxInfoTests(InMemoryTaxInfo()) {} | |
| @Explicit("Integration test") | |
| class Live : TaxInfoTests(CanadianRevenueAgencyTaxInfo()) {} | |
| } |
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 characters
| class CanadianRevenueAgencyTaxInfo : ITaxInfo? { | |
| async ITaxInfo.GetTaxInfo(sin: SIN) -> TaxInfo? => { | |
| val response = await HTTP.Request("http://cra.ca/taxinfo/?sin={sin}") | |
| if (!response.success) return None | |
| return Decode(await response.ReadContent()); | |
| } | |
| } | |
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 characters
| class InMemoryTaxInfo : ITaxInfo { | |
| public TaxInfosBySSN: Map<SIN, TaxInfo> = { | |
| A_SIN -> A_TAX_INFO, | |
| ANOTHER_SIN -> ANOTHER_TAX_INFO, | |
| } | |
| async ITaxInfo.GetTaxInfo(sin: SIN) -> TaxInfo? => TaxInfosBySSN.TryGet(sin) | |
| } | |
| class NoTaxInfo : ITaxInfo { | |
| async ITaxInfo.GetTaxInfo(sin: SIN) -> TaxInfo? => None | |
| } | |
| class VerySlowTaxInfo : InMemoryTaxInfo { | |
| async ITaxInfo.GetTaxInfo(sin: SIN) -> TaxInfo? => { | |
| await Async.Wait(TimeSpan.Minutes(10)); | |
| return await base.GetTaxInfo(sin); | |
| } | |
| } | |
| class OfflineTaxInfo : ITaxInfo { | |
| async ITaxInfo.GetTaxInfo(sin: SIN) -> TaxInfo? => throw ITaxInfo.Error() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment