示例#1
0
 public double CalculateShippingCost(USPostalAddress destination)
 {
     // Calculating shipping cost between two addresses
     if (destination.State == this.State)
     {
         return(15.0);
     }
     else
     {
         return(25.0);
     }
 }
示例#2
0
    public static USPostalAddress Parse(SqlString s)
    {
        if (s.IsNull)
        {
            return(Null);
        }
        USPostalAddress u = new USPostalAddress();

        string[] parts = s.Value.Split(",".ToCharArray());
        if (parts.Length != 4)
        {
            throw new ArgumentException("The value has incorrect format. Should be <Address>, <City>, <State>, <ZipCode>");
        }
        u._address = parts[0].Trim();
        u._city    = parts[1].Trim();
        u._state   = parts[2].Trim();
        u._zipCode = parts[3].Trim();
        if (!u.ValidateAddress())
        {
            throw new ArgumentException("The value has incorrect format. Attributes are empty or State is incorrect");
        }
        return(u);
    }
示例#3
0
        public void TestIsBlank()
        {
            Assert.IsTrue(new USPostalAddress().IsBlank);
            Assert.IsFalse(new USPostalAddress { AddressLine1 = "31 Mapple Place" }.IsBlank);
            Assert.IsFalse(new USPostalAddress { AddressLine2 = "Apt 1F" }.IsBlank);
            Assert.IsFalse(new USPostalAddress { City = "New York" }.IsBlank);
            Assert.IsFalse(new USPostalAddress { State = (USState)"NJ" }.IsBlank);
            Assert.IsFalse(new USPostalAddress { State = USState.NewYork }.IsBlank);
            Assert.IsFalse(new USPostalAddress { ZipCode = new ZipCode("10314") }.IsBlank);

            var blankAddress = new USPostalAddress
            {
                AddressLine1 = " \r\n",
                AddressLine2 = UnitTestHelper.BLANK_STRING,
                City = "\t\t\t",
                ZipCode = new ZipCode(),
                State = new USState()
            };
            Assert.IsTrue(blankAddress.IsBlank);
        }
示例#4
0
 public void TestUSPostalAddress_IdArg()
 {
     var addressId = new Id(123456789);
     var address = new USPostalAddress(addressId);
     Assert.AreEqual(addressId, address.Id);
     Assert.IsFalse(address.IsNew);
     Assert.IsTrue(address.IsBlank);
 }
示例#5
0
        public void TestUSPostalAddress()
        {
            var address = new USPostalAddress();

            Assert.IsNull(address.AddressLine1);
            Assert.IsNull(address.AddressLine2);
            Assert.IsNull(address.City);
            Assert.IsNotNull(address.State);
            Assert.IsTrue(address.State.IsBlank);
            Assert.IsNull(address.State.Code);
            Assert.IsNotNull(address.ZipCode);
            Assert.IsTrue(address.ZipCode.IsBlank);
            Assert.IsTrue(address.IsNew);
            Assert.IsTrue(address.IsBlank);
        }
示例#6
0
        public void TestState_BlankArg()
        {
            var address = new USPostalAddress { State = new USState() };
            Assert.IsNotNull(address.State);
            Assert.IsTrue(address.State.IsBlank);
            Assert.IsNull(address.State.Code);

            address = AddressSample;
            address.State = new USState();
            Assert.IsNotNull(address.State);
            Assert.IsTrue(address.State.IsBlank);
            Assert.IsNull(address.State.Code);
        }
示例#7
0
        public void TestState()
        {
            var address = new USPostalAddress();
            Assert.IsNotNull(address.State);
            Assert.IsTrue(address.State.IsBlank);
            Assert.IsNull(address.State.Code);

            address.State = (USState)"ny";
            Assert.AreEqual(USState.NewYork, address.State);
            address.State = (USState)"\r\n fL\t  ";
            Assert.AreEqual(USState.Florida, address.State);

            address.State = USState.ArmedForces;
            Assert.AreEqual("AE", address.State.Code);
            Assert.AreEqual(USState.ArmedForces, address.State);
        }
示例#8
0
        public void TestIsEqualTo()
        {
            Assert.IsTrue(AddressSample.IsEqualTo(AddressSample));
            Assert.IsTrue(DirtyAddressSample.IsEqualTo(DirtyAddressSample));
            Assert.IsFalse(AddressSample.IsEqualTo(DirtyAddressSample));

            var otherAddress = AddressSample;
            Assert.IsTrue(AddressSample.IsEqualTo(otherAddress));
            otherAddress.State = USState.NewJersey;
            Assert.IsFalse(AddressSample.IsEqualTo(otherAddress));
            otherAddress.State = (USState)"ny";
            Assert.IsTrue(otherAddress.IsEqualTo(AddressSample));
            otherAddress.ZipCode = new ZipCode("10314");
            Assert.IsFalse(otherAddress.IsEqualTo(AddressSample));
            otherAddress.ZipCode = (ZipCode)"  ..100.-38.\t\r";
            Assert.IsTrue(otherAddress.IsEqualTo(AddressSample));
            otherAddress.AddressLine2 += ".";
            Assert.IsFalse(otherAddress.IsEqualTo(AddressSample));

            Assert.IsFalse(otherAddress.IsEqualTo(DirtyAddressSample));
            otherAddress.AddressLine1 = "\n\r\t  ";
            otherAddress.AddressLine2 = " 34 mapple drive ";
            otherAddress.City = "BROOKLYN";
            otherAddress.State = new USState();
            otherAddress.ZipCode = new ZipCode("11235 ");
            Assert.IsTrue(otherAddress.IsEqualTo(DirtyAddressSample));

            Assert.IsTrue(new USPostalAddress().IsEqualTo(new USPostalAddress()));
            var address1 = new USPostalAddress { ZipCode = new ZipCode("10314") };
            var address2 = new USPostalAddress { ZipCode = new ZipCode("10314-1234") };
            Assert.IsFalse(address1.IsEqualTo(address2));
            address2.ZipCode = (ZipCode)"10314";
            Assert.IsTrue(address1.IsEqualTo(address2));
        }