예제 #1
0
 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));
 }
예제 #2
0
        public void Parse_GirobankNotAllowed_IsInvalid()
        {
            // Arrange
            const string girobankPostcode = "GIR 0AA";

            // Act
            Assert.Throws <FormatException>(() => Postcode.Parse(girobankPostcode));
        }
예제 #3
0
 public void TestAll()
 {
     foreach (var line in File.ReadLines(@"C:\temp\postcodes.txt"))
     {
         var postcode = Postcode.Parse(line);
         Assert.Equal(line, postcode.ToString());
     }
 }
예제 #4
0
        public void Parse_BfpoNotAllowed_IsInvalid()
        {
            // Arrange
            const string bfpoPostcode = "BFPO 805";

            // Act
            Assert.Throws <FormatException>(() => Postcode.Parse(bfpoPostcode));
        }
예제 #5
0
        public void Parse_OutcodeOnlyPassed_NotValidByDefault()
        {
            // Arrange
            const string input = "LS25";

            // Act
            Assert.Throws <FormatException>(() => Postcode.Parse(input));
        }
예제 #6
0
        public void Parse_SantaNotAllowed_IsInvalid()
        {
            // Arrange
            const string santaPostcode = "SAN TA1";

            // Act
            Assert.Throws <FormatException>(() => Postcode.Parse(santaPostcode));
        }
예제 #7
0
        public void Parse_OverseasTerritoriesNotAllowed_IsInvalid()
        {
            // Arrange
            const string overseasTerritoryPostcode = "TDCU 1ZZ";

            // Act
            Assert.Throws <FormatException>(() => Postcode.Parse(overseasTerritoryPostcode));
        }
예제 #8
0
 public void DenormalisedParsesCorrectly()
 {
     foreach (var(expected, s) in ValidTestCases())
     {
         var postcode = Postcode.Parse(s);
         Assert.Equal(expected, postcode.ToString());
     }
 }
예제 #9
0
        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));
        }
예제 #10
0
        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));
        }
예제 #11
0
        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"));
        }
예제 #12
0
        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"));
        }
예제 #13
0
        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"));
        }
예제 #14
0
        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"));
        }
예제 #15
0
        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);
        }
예제 #16
0
        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"));
        }
예제 #17
0
        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"));
        }
예제 #18
0
        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"));
        }
예제 #19
0
        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));
        }
예제 #20
0
        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"));
        }
예제 #21
0
        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));
        }
예제 #22
0
 public void Parse_NullOrEmptyOrWhitespaceInput_NotValid(string input)
 {
     Assert.Throws <FormatException>(() => Postcode.Parse(input));
 }