public void op_GetHashCode(string value)
        {
            var expected = value.GetHashCode();
            var actual   = BritishPostcode.FromString(value).GetHashCode();

            Assert.Equal(expected, actual);
        }
        public void op_FromString_string_whenPartialUnit(string expected,
                                                         string value)
        {
            var actual = BritishPostcode.FromString(value).ToString();

            Assert.Equal <BritishPostcode>(expected, actual);
        }
        public void opImplicit_string_BritishPostcode()
        {
            const string expected = "GU21 4XG";
            string       actual   = BritishPostcode.FromString(expected);

            Assert.Equal(expected, actual);
        }
        public void op_Equals_object_whenString()
        {
            BritishPostcode obj = "GU21 4XG";

            // ReSharper disable SuspiciousTypeConversion.Global
            Assert.False(obj.Equals((object)"GU21 4XG"));
            // ReSharper restore SuspiciousTypeConversion.Global
        }
        public void op_Equals_BritishPostcode_whenSame()
        {
            BritishPostcode obj = "GU21 4XG";

            // ReSharper disable EqualExpressionComparison
            Assert.True(obj.Equals(obj));
            Assert.True(obj.Equals((object)obj));
            // ReSharper restore EqualExpressionComparison
        }
        public void op_Compare_BritishPostcode_BritishPostcode_whenSame()
        {
            BritishPostcode obj = "GU21 4XG";

            const int expected = 0;
            var       actual   = BritishPostcode.Compare(obj, obj);

            Assert.Equal(expected, actual);
        }
        public void op_FromString_string_whenPeriod()
        {
            const string original = ".AB10 1AA.";
            var          obj      = BritishPostcode.FromString(original);

            Assert.Equal("AB", obj.Area);
            Assert.Equal("AB10", obj.District);
            Assert.Equal("AB10 1", obj.Sector);
            Assert.Equal("AB10 1AA", obj.Unit);
        }
        public void op_FromString_string_whenPlaceName()
        {
            const string original = "ABERDEEN";
            var          obj      = BritishPostcode.FromString(original);

            Assert.Null(obj.Area);
            Assert.Null(obj.District);
            Assert.Null(obj.Sector);
            Assert.Null(obj.Unit);
        }
        public void op_FromString_string_whenThreeParts()
        {
            const string original = "GU21 4XG BB";
            var          obj      = BritishPostcode.FromString(original);

            Assert.Null(obj.Area);
            Assert.Null(obj.District);
            Assert.Null(obj.Sector);
            Assert.Null(obj.Unit);
        }
        public void op_Equals_BritishPostcode(bool expected,
                                              string value,
                                              string comparand)
        {
            BritishPostcode obj   = value;
            BritishPostcode other = comparand;

            Assert.Equal(expected, obj.Equals(other));
            Assert.Equal(expected, obj.Equals((object)other));
        }
        public void op_CompareTo_BritishPostcode(int expected,
                                                 string value,
                                                 string comparand)
        {
            BritishPostcode postcode1 = value;
            BritishPostcode postcode2 = comparand;

            Assert.Equal(expected, postcode1.CompareTo(postcode2));
            Assert.Equal(expected, postcode1.CompareTo((object)postcode2));
        }
        public void opInequality_BritishPostcode_BritishPostcode(bool expected,
                                                                 string comparand1,
                                                                 string comparand2)
        {
            BritishPostcode postcode1 = comparand1;
            BritishPostcode postcode2 = comparand2;

            var actual = postcode1 != postcode2;

            Assert.Equal(expected, actual);
        }
        public void op_Compare_BritishPostcode_BritishPostcode(int expected,
                                                               string comparand1,
                                                               string comparand2)
        {
            BritishPostcode postcode1 = comparand1;
            BritishPostcode postcode2 = comparand2;

            var actual = BritishPostcode.Compare(postcode1, postcode2);

            Assert.Equal(expected, actual);
        }
        public void opGreaterThan_BritishPostcode_BritishPostcode(bool expected,
                                                                  string comparand1,
                                                                  string comparand2)
        {
            BritishPostcode postcode1 = comparand1;
            BritishPostcode postcode2 = comparand2;

            var actual = postcode1 > postcode2;

            Assert.Equal(expected, actual);
        }
        public void op_FromString_stringEmpty()
        {
            var obj = BritishPostcode.FromString(string.Empty);

            Assert.Null(obj.Area);
            Assert.Null(obj.District);
            Assert.Null(obj.Sector);
            Assert.Null(obj.Unit);

            Assert.Null(obj.OutCode);
            Assert.Null(obj.InCode);
        }
        public void opImplicit_BritishPostcode_stringEmpty()
        {
            BritishPostcode obj = string.Empty;

            Assert.Null(obj.Area);
            Assert.Null(obj.District);
            Assert.Null(obj.Sector);
            Assert.Null(obj.Unit);

            Assert.Null(obj.OutCode);
            Assert.Null(obj.InCode);
        }
        public void opImplicit_BritishPostcode_string()
        {
            BritishPostcode obj = "GU21 4XG";

            Assert.Equal("GU", obj.Area);
            Assert.Equal("GU21", obj.District);
            Assert.Equal("GU21 4", obj.Sector);
            Assert.Equal("GU21 4XG", obj.Unit);

            Assert.Equal("GU21", obj.OutCode);
            Assert.Equal("4XG", obj.InCode);
        }
        public void op_FromString_string_WhenInvalid(string value)
        {
            var obj = BritishPostcode.FromString(value);

            Assert.Null(obj.Area);
            Assert.Null(obj.District);
            Assert.Null(obj.Sector);
            Assert.Null(obj.Unit);

            Assert.Null(obj.OutCode);
            Assert.Null(obj.InCode);
        }
        public void op_FromString_string_whenLondonWC()
        {
            const string original = "WC1A 2HR";
            var          obj      = BritishPostcode.FromString(original);

            Assert.Equal("WC", obj.Area);
            Assert.Equal("WC1A", obj.District);
            Assert.Equal("WC1A 2", obj.Sector);
            Assert.Equal("WC1A 2HR", obj.Unit);

            Assert.Equal("WC1A", obj.OutCode);
            Assert.Equal("2HR", obj.InCode);
        }
        public void op_FromString_string_whenOnlySector()
        {
            const string original = "GU21 4";
            var          obj      = BritishPostcode.FromString(original);

            Assert.Equal("GU", obj.Area);
            Assert.Equal("GU21", obj.District);
            Assert.Equal("GU21 4", obj.Sector);
            Assert.Null(obj.Unit);

            Assert.Equal("GU21", obj.OutCode);
            Assert.Null(obj.InCode);
        }
        public void op_FromString_string(string value,
                                         string area,
                                         string district,
                                         string number,
                                         string sector,
                                         string unit)
        {
            var obj = BritishPostcode.FromString(value);

            Assert.Equal(area, obj.Area);
            Assert.Equal(district, obj.District);
            Assert.Equal(number, obj.DistrictNumber);
            Assert.Equal(sector, obj.Sector);
            Assert.Equal(unit, obj.Unit);

            Assert.Equal(district, obj.OutCode);
            Assert.Equal(unit.RemoveFromStart(district, StringComparison.OrdinalIgnoreCase).Trim(), obj.InCode);
        }
        public void op_CompareTo_object_whenString()
        {
            BritishPostcode obj = "GU21 4XG";

            Assert.Throws <ArgumentOutOfRangeException>(() => obj.CompareTo((object)"GU21 4XG"));
        }
        public void op_ToString(string expected)
        {
            var actual = BritishPostcode.FromString(expected).ToString();

            Assert.Equal(expected, actual);
        }
 public void op_FromString_stringNull()
 {
     Assert.Throws <ArgumentNullException>(() => BritishPostcode.FromString(null));
 }
        public void op_FromString_string_whenNoSpaces(string expected)
        {
            var actual = BritishPostcode.FromString(expected.RemoveAny(' ')).ToString();

            Assert.Equal(expected, actual);
        }