public void Parse_ValidPostcodeAtStartOfLongerString_IsInvalid(string invalidPostcode, PostcodeParseOptions options) { // Act Assert.Throws <FormatException>(() => Postcode.Parse(invalidPostcode, options), string.Format("No exception thrown when parsing {0}", invalidPostcode)); }
public void Parse_GirobankNotAllowed_IsInvalid() { // Arrange const string girobankPostcode = "GIR 0AA"; // Act Assert.Throws <FormatException>(() => Postcode.Parse(girobankPostcode)); }
public void TestAll() { foreach (var line in File.ReadLines(@"C:\temp\postcodes.txt")) { var postcode = Postcode.Parse(line); Assert.Equal(line, postcode.ToString()); } }
public void Parse_BfpoNotAllowed_IsInvalid() { // Arrange const string bfpoPostcode = "BFPO 805"; // Act Assert.Throws <FormatException>(() => Postcode.Parse(bfpoPostcode)); }
public void Parse_OutcodeOnlyPassed_NotValidByDefault() { // Arrange const string input = "LS25"; // Act Assert.Throws <FormatException>(() => Postcode.Parse(input)); }
public void Parse_SantaNotAllowed_IsInvalid() { // Arrange const string santaPostcode = "SAN TA1"; // Act Assert.Throws <FormatException>(() => Postcode.Parse(santaPostcode)); }
public void Parse_OverseasTerritoriesNotAllowed_IsInvalid() { // Arrange const string overseasTerritoryPostcode = "TDCU 1ZZ"; // Act Assert.Throws <FormatException>(() => Postcode.Parse(overseasTerritoryPostcode)); }
public void DenormalisedParsesCorrectly() { foreach (var(expected, s) in ValidTestCases()) { var postcode = Postcode.Parse(s); Assert.Equal(expected, postcode.ToString()); } }
public void Parse_InputContainsVariousSeparatorsBetweenIncodeAndOutcode_AllAreValid(string input, string expectedOutcode, string expectedIncode) { // Act Postcode output = Postcode.Parse(input); // Assert Assert.That(output.OutCode, Is.EqualTo(expectedOutcode)); Assert.That(output.InCode, Is.EqualTo(expectedIncode)); }
public void Parse_InvalidPostcodeContainsValidPostcodeAsSubstring_IsInvalid() { // Arrange const string input = "QS81 8SH"; // "S81 8SH" is valid. "QS81 8SH" looks valid at first glance, // but isn't as postcodes can't start with Q. // Act Assert.Throws <FormatException>(() => Postcode.Parse(input)); }
public void Parse_WhitespaceSurroundsValidInput_WhitespaceIsStripped() { // Arrange const string input = " LS25 6LG "; // Act Postcode output = Postcode.Parse(input); // Assert Assert.That(output.OutCode, Is.EqualTo("LS25")); Assert.That(output.InCode, Is.EqualTo("6LG")); }
public void Parse_NonWhitespaceNonAlphanumericSurroundsInput_IsStripped() { // Arrange const string input = "%LS25 6LG\""; // Act Postcode output = Postcode.Parse(input); // Assert Assert.That(output.OutCode, Is.EqualTo("LS25")); Assert.That(output.InCode, Is.EqualTo("6LG")); }
public void Parse_GirobankAllowed_IsValid() { // Arrange const string girobankPostcode = "GIR 0AA"; // Act Postcode output = Postcode.Parse(girobankPostcode, PostcodeParseOptions.MatchGirobank); // Assert Assert.That(output.OutCode, Is.EqualTo("GIR")); Assert.That(output.InCode, Is.EqualTo("0AA")); }
public void Parse_OverseasTerritoriesAllowed_IsValid() { // Arrange const string overseasTerritoryPostcode = "TDCU 1ZZ"; // Act Postcode output = Postcode.Parse(overseasTerritoryPostcode, PostcodeParseOptions.MatchOverseasTerritories); // Assert Assert.That(output.OutCode, Is.EqualTo("TDCU")); Assert.That(output.InCode, Is.EqualTo("1ZZ")); }
public void Parse_OutcodeOnlyPassedIncodeOptionalSet_IsValid() { // Arrange const string input = "LS25"; // Act Postcode output = Postcode.Parse(input, PostcodeParseOptions.IncodeOptional); // Assert Assert.That(output.OutCode, Is.EqualTo(input)); Assert.That(output.InCode, Is.Null); }
public void Parse_ValidPostcode_ReturnedObjectHasOutcodeAndIncodeSet() { // Arrange const string input = "LS25 6LG"; // Act Postcode output = Postcode.Parse(input); // Assert Assert.That(output.OutCode, Is.EqualTo("LS25")); Assert.That(output.InCode, Is.EqualTo("6LG")); }
public void Parse_SantaAllowed_IsValid() { // Arrange const string santaPostcode = "SAN TA1"; // Act Postcode output = Postcode.Parse(santaPostcode, PostcodeParseOptions.MatchSanta); // Assert Assert.That(output.OutCode, Is.EqualTo("SAN")); Assert.That(output.InCode, Is.EqualTo("TA1")); }
public void Parse_MixedCaseInput_OutputIsUppercase() { // Arrange const string input = "ls25 6Lg"; // Act Postcode output = Postcode.Parse(input); // Assert Assert.That(output.OutCode, Is.EqualTo("LS25")); Assert.That(output.InCode, Is.EqualTo("6LG")); }
public void ToString_ReturnsStringRepresentationOfPostcode(string input, PostcodeParseOptions options, string expectedToString) { // Arrange Postcode postcode = Postcode.Parse(input, options); // Act string actualToString = postcode.ToString(); // Assert Assert.That(actualToString, Is.EqualTo(expectedToString)); }
public void Parse_BfpoAllowed_IsValid() { // Arrange const string bfpoPostcode = "BFPO 805"; // Act Postcode output = Postcode.Parse(bfpoPostcode, PostcodeParseOptions.MatchBfpo); // Assert Assert.That(output.OutCode, Is.EqualTo("BFPO")); Assert.That(output.InCode, Is.EqualTo("805")); }
public void Parse_CanCombineOptions(string input, string expectedOutcode, string expectedIncode) { // Arrange const PostcodeParseOptions options = PostcodeParseOptions.IncodeOptional ^ PostcodeParseOptions.MatchBfpo ^ PostcodeParseOptions.MatchGirobank ^ PostcodeParseOptions.MatchOverseasTerritories ^ PostcodeParseOptions.MatchSanta; // Act Postcode output = Postcode.Parse(input, options); // Assert Assert.That(output.InCode, Is.EqualTo(expectedIncode)); Assert.That(output.OutCode, Is.EqualTo(expectedOutcode)); }
public void Parse_NullOrEmptyOrWhitespaceInput_NotValid(string input) { Assert.Throws <FormatException>(() => Postcode.Parse(input)); }