コード例 #1
0
        public void GivenAStreetNumberAndNoStreetName_Validate_ShouldHaveAValidationError()
        {
            // Arrange.
            var address = new Address{ StreetNumber = "a" };

            // Act & Assert.
            _addressValidator.ShouldHaveValidationErrorFor(a => a.Street, address);
        }
コード例 #2
0
        public void Copy(Address newAddress)
        {
            if (newAddress == null)
            {
                throw new ArgumentNullException("newAddress");
            }

            if (newAddress.IsStreetNumberModified)
            {
                StreetNumber = newAddress.StreetNumber;
            }

            if (newAddress.IsStreetModified)
            {
                Street = newAddress.Street;
            }

            if (newAddress.IsSuburbModified)
            {
                Suburb = newAddress.Suburb;
            }

            if (newAddress.IsMunicipalityModified)
            {
                Municipality = newAddress.Municipality;
            }

            if (newAddress.IsStateModified)
            {
                State = newAddress.State;
            }

            if (newAddress.IsCountryIsoCodeModified)
            {
                CountryIsoCode = newAddress.CountryIsoCode;
            }

            if (newAddress.IsPostcodeModified)
            {
                Postcode = newAddress.Postcode;
            }

            if (newAddress.IsLatitudeModified)
            {
                Latitude = newAddress.Latitude;
            }

            if (newAddress.IsLongitudeModified)
            {
                Longitude = newAddress.Longitude;
            }

            if (newAddress.IsIsStreetDisplayedModified)
            {
                IsStreetDisplayed = newAddress.IsStreetDisplayed;
            }
        }
コード例 #3
0
        public void Copy(Listing newListing)
        {
            if (newListing == null)
            {
                throw new ArgumentNullException("newListing");
            }

            if (!newListing.IsModified)
            {
                return;
            }

            base.Copy(newListing);

            if (newListing.IsAgencyIdModified)
            {
                AgencyId = newListing.AgencyId;
            }

            if (newListing.IsStatusTypeModified)
            {
                StatusType = newListing.StatusType;
            }

            if (newListing.IsCreatedOnModified)
            {
                CreatedOn = newListing.CreatedOn;
            }

            if (newListing.IsTitleModified)
            {
                Title = newListing.Title;
            }

            if (newListing.IsDescriptionModified)
            {
                Description = newListing.Description;
            }

            if (newListing.IsAddressModified)
            {
                if (newListing.Address == null)
                {
                    Address = null;
                }
                else
                {
                    if (Address == null)
                    {
                        Address = new Address();
                    }

                    if (newListing.Address.IsModified)
                    {
                        Address.Copy(newListing.Address);
                    }

                    IsAddressModified = true;
                }
            }

            if (newListing.IsAgentsModified)
            {
                if (newListing.Agents == null)
                {
                    Agents = null;
                }
                else
                {
                    Agents = new List<ListingAgent>();
                    foreach (var newAgent in newListing.Agents)
                    {
                        var agent = new ListingAgent();
                        agent.Copy(newAgent);
                        Agents.Add(agent);
                    }
                }
            }

            if (newListing.IsImagesModified)
            {
                if (newListing.Images == null)
                {
                    Images = null;
                }
                else
                {
                    Images = new List<Media>();
                    foreach (var newImage in newListing.Images)
                    {
                        var image = new Media();
                        image.Copy(newImage);
                        Images.Add(image);
                    }
                }
            }

            if (newListing.IsFloorPlansModified)
            {
                if (newListing.FloorPlans == null)
                {
                    FloorPlans = null;
                }
                else
                {
                    FloorPlans = new List<Media>();
                    foreach (var newFloorPlan in newListing.FloorPlans)
                    {
                        var floorPlan = new Media();
                        floorPlan.Copy(newFloorPlan);
                        FloorPlans.Add(floorPlan);
                    }
                }
            }

            if (newListing.IsVideosModified)
            {
                if (newListing.Videos == null)
                {
                    Videos = null;
                }
                else
                {
                    Videos = new List<Media>();
                    foreach (var newVideo in newListing.Videos)
                    {
                        var video = new Media();
                        video.Copy(newVideo);
                        Videos.Add(video);
                    }
                }
            }

            if (newListing.IsInspectionsModified)
            {
                if (newListing.Inspections == null)
                {
                    Inspections = null;
                }

                else
                {
                    Inspections = new List<Inspection>();
                    foreach (var newInspection in newListing.Inspections)
                    {
                        var inspection = new Inspection();
                        inspection.Copy(newInspection);
                        Inspections.Add(inspection);
                    }

                }
            }

            if (newListing.IsLandDetailsModified)
            {
                if (newListing.LandDetails == null)
                {
                    LandDetails = null;
                }
                else
                {
                    if (LandDetails == null)
                    {
                        LandDetails = new LandDetails();
                    }

                    if (newListing.LandDetails.IsModified)
                    {
                        LandDetails.Copy(newListing.LandDetails);
                    }

                    IsLandDetailsModified = true;
                }
            }

            if (newListing.IsFeaturesModified)
            {
                if (newListing.Features == null)
                {
                    Features = null;
                }
                else
                {
                    if (Features == null)
                    {
                        Features = new Features();
                    }

                    if (newListing.Features.IsModified)
                    {
                        Features.Copy(newListing.Features);
                    }

                    IsFeaturesModified = true;
                }
            }

            if (newListing.IsLinksModified)
            {
                Links = newListing.Links == null
                    ? null
                    : new List<string>(newListing.Links);
            }
        }
コード例 #4
0
 private static void AssertAddress(Address address,
     string streetNumber,
     bool isModified)
 {
     address.IsStreetDisplayed.ShouldBe(true);
     address.IsIsStreetDisplayedModified.ShouldBe(isModified);
     address.StreetNumber.ShouldBe(streetNumber);
     address.IsStreetNumberModified.ShouldBe(isModified);
     address.Street.ShouldBe("Main Road");
     address.IsStreetModified.ShouldBe(isModified);
     address.Suburb.ShouldBe("RICHMOND");
     address.IsSuburbModified.ShouldBe(isModified);
     address.Municipality.ShouldBe("Yarra");
     address.IsMunicipalityModified.ShouldBe(isModified);
     address.State.ShouldBe("vic");
     address.IsStateModified.ShouldBe(isModified);
     address.CountryIsoCode.ShouldBe("AU");
     address.IsCountryIsoCodeModified.ShouldBe(isModified);
     address.Postcode.ShouldBe("3121");
     address.IsPostcodeModified.ShouldBe(isModified);
 }
コード例 #5
0
        private static void ExtractLatitudeLongitudes(XElement document, Address address)
        {
            document.ShouldNotBe(null);
            address.ShouldNotBe(null);

            var latitudeElement = document.Descendants("Latitude").FirstOrDefault() ??
                                  document.Descendants("latitude").FirstOrDefault();
            if (latitudeElement != null)
            {
                address.Latitude = latitudeElement.DecimalValueOrDefault();
            }

            var longitudeElement = document.Descendants("Longitude").FirstOrDefault() ??
                                   document.Descendants("longitude").FirstOrDefault();
            if (latitudeElement != null)
            {
                address.Longitude = longitudeElement.DecimalValueOrDefault();
            }
        }
コード例 #6
0
        private static Address ExtractAddress(XElement document, string addressDelimeter)
        {
            document.ShouldNotBe(null);

            var addressElement = document.Element("address");
            if (addressElement == null)
            {
                return null;
            }

            var address = new Address();

            // Land and CommericalLand should only provide lot numbers. 
            var lotNumber = addressElement.ValueOrDefault("lotNumber");
            var subNumber = addressElement.ValueOrDefault("subNumber");
            var streetNumber = addressElement.ValueOrDefault("streetNumber");

            // LOGIC:
            // So, we're trying to create a streetnumber value that contains the rea values
            //     Sub Number
            //     Lot Number
            //     Street Number
            // into a single value. URGH.
            // This is because REA have over fricking complicated shiz (again). So lets just
            // keep this simple, eh? :)
            
            // FORMAT: subnumber lotnumber streetnumber
            // eg. 23a/135 smith street
            //     6/23a 135 smith street
            //     23a lot 33 smith street
            //     23a lot 33/135 smith street

            // Lot number logic: If the value contains the word LOT in it, then we don't
            // need to do anything. Otherwise, we should have a value the starts with 'LOT'.
            // eg. LOT 123abc
            var lotNumberResult = string.IsNullOrWhiteSpace(lotNumber)
                ? string.Empty
                : lotNumber.IndexOf("lot", StringComparison.InvariantCultureIgnoreCase) > 0
                    ? lotNumber
                    : string.Format("LOT {0}", lotNumber);

            // Sub number and Street number logic: A sub number can exist -before- the street number.
            // A street number might NOT exist, so a sub number is all by itself.
            // When we want to show a sub number, we probably want to show it, like this:
            //    'subNumber`delimeter`streetNumber`
            //   eg. 12a/432
            // But .. sometimes, the sub number -already- contains a delimeter! so then we want this:
            //   eg. 45f/231 15
            // So we don't put a delimeter in there, but a space. Urgh! confusing, so sowwy.

            var subNumberLotNumber = string.Format("{0} {1}",
                subNumber,
                lotNumberResult).Trim();

            // We only have a delimeter if we have a sub-or-lot number **and**
            // a street number.
            // Also, we use the default delimeter if we don't have one already in the
            // sub-or-lot number.
            var delimeter = string.IsNullOrWhiteSpace(subNumberLotNumber)
                ? string.Empty
                : subNumberLotNumber.IndexOfAny(new[] {'/', '\\', '-'}) > 0
                    ? " "
                    : string.IsNullOrWhiteSpace(streetNumber)
                        ? string.Empty
                        : addressDelimeter;

            address.StreetNumber = string.Format("{0}{1}{2}",
                subNumberLotNumber,
                delimeter,
                streetNumber).Trim();

            address.Street = addressElement.ValueOrDefault("street");
            address.Suburb = addressElement.ValueOrDefault("suburb");
            address.State = addressElement.ValueOrDefault("state");

            // REA Xml Rule: Country is ommited == default to Australia.
            // Reference: http://reaxml.realestate.com.au/docs/reaxml1-xml-format.html#country
            var country = addressElement.ValueOrDefault("country");
            address.CountryIsoCode = !string.IsNullOrEmpty(country)
                ? ConvertCountryToIsoCode(country)
                : "AU";

            address.Postcode = addressElement.ValueOrDefault("postcode");

            var isStreetDisplayedText = addressElement.AttributeValueOrDefault("display");
            address.IsStreetDisplayed = string.IsNullOrWhiteSpace(isStreetDisplayedText) ||
                                        addressElement.AttributeBoolValueOrDefault("display");


            // Technically, the <municipality/> element is not a child of the <address/> element.
            // But I feel that it's sensible to still parse for it, in here.
            address.Municipality = document.ValueOrDefault("municipality");

            // Finally - Lat/Longs. These are -not- part of the REA XML standard.
            // ~BUT~ some multi-loaders are sticking this data into some xml!
            ExtractLatitudeLongitudes(document, address);

            return address;
        }