Exemple #1
0
            public static void ValidPostcode6SpaceInWrongPlace()
            {
                var postcode = Postcode.Parse("EC1 A1BB");

                if (postcode.FirstPart != "EC1A")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "1BB")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #2
0
            public static void ValidPostcode3SpaceInWrongPlace()
            {
                var postcode = Postcode.Parse("CR 26XH");

                if (postcode.FirstPart != "CR2")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "6XH")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #3
0
            public static void ValidPostcode4SpaceInWrongPlace()
            {
                var postcode = Postcode.Parse("DN5 51PT");

                if (postcode.FirstPart != "DN55")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "1PT")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #4
0
            public static void ValidPostcode2SpaceInWrongPlace()
            {
                var postcode = Postcode.Parse("M601 NW");

                if (postcode.FirstPart != "M60")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "1NW")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #5
0
            public static void ValidPostcode5NoSpace()
            {
                var postcode = Postcode.Parse("W1A1HQ");

                if (postcode.FirstPart != "W1A")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "1HQ")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #6
0
            public static void ValidPostcode1()
            {
                var postcode = Postcode.Parse("M1 1AA");

                if (postcode.FirstPart != "M1")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "1AA")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #7
0
            public static void NoSpace()
            {
                var postcode = Postcode.Parse("IP164AY");

                if (postcode.FirstPart != "IP16")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != "4AY")
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #8
0
            public static void PartPostcode3()
            {
                var postcode = Postcode.Parse("TS1");

                if (postcode.FirstPart != "TS1")
                {
                    throw new FailedUnitTestException();
                }
                if (postcode.LastPart != null)
                {
                    throw new FailedUnitTestException();
                }
            }
Exemple #9
0
        private bool PropertyMatchesShortlist(RightmovePropertyListing rightmovePropertyListing, bool fullTest = true)
        {
            // The property might be excluded more than once if it is a featured property so we
            // need to account for this, hence why we don't use the _removedProperties.Add()
            // method and instead use the indexer

            if (_shortlist.MinimumPrice > 0 && rightmovePropertyListing.Price > 0 && rightmovePropertyListing.Price < _shortlist.MinimumPrice)
            {
                if (OptionsForm.DebugingEnabled)
                {
                    _removedProperties[rightmovePropertyListing.Link] = "Price too low: " + rightmovePropertyListing.PriceQualifier + " " + rightmovePropertyListing.Price;
                }
                return(false);
            }

            if (_shortlist.MaximumPrice > 0 && rightmovePropertyListing.Price > 0 && rightmovePropertyListing.Price > _shortlist.MaximumPrice)
            {
                if (OptionsForm.DebugingEnabled)
                {
                    _removedProperties[rightmovePropertyListing.Link] = "Price too high: " + rightmovePropertyListing.PriceQualifier + " " + rightmovePropertyListing.Price;
                }
                return(false);
            }

            if (_shortlist.MaximumPrice > 0 && rightmovePropertyListing.Price > 0 && rightmovePropertyListing.Price == _shortlist.MaximumPrice && rightmovePropertyListing.PriceQualifier == "Offers in Excess of")
            {
                if (OptionsForm.DebugingEnabled)
                {
                    _removedProperties[rightmovePropertyListing.Link] = "Price too high: Offers in Excess of " + rightmovePropertyListing.PriceQualifier + " " + rightmovePropertyListing.Price;
                }
                return(false);
            }

            if (_shortlist.ExcludePriceOnApplication && rightmovePropertyListing.PriceQualifier == "POA")
            {
                if (OptionsForm.DebugingEnabled)
                {
                    _removedProperties[rightmovePropertyListing.Link] = "POA excluded.";
                }
                return(false);
            }

            if (_shortlist.ExcludeOffersInvited && rightmovePropertyListing.PriceQualifier == "Offers Invited")
            {
                if (OptionsForm.DebugingEnabled)
                {
                    _removedProperties[rightmovePropertyListing.Link] = "Offers Invited excluded.";
                }
                return(false);
            }

            if (_shortlist.ExcludeTerms.Count() > 0)
            {
                string excludedTermFound = null;
                foreach (string term in _shortlist.ExcludeTerms)
                {
                    var regex = new Regex(@"\b" + term + @"\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                    if (regex.IsMatch(rightmovePropertyListing.Title))
                    {
                        excludedTermFound = term;
                        break;
                    }
                    else if (regex.IsMatch(rightmovePropertyListing.Description))
                    {
                        excludedTermFound = term;
                        break;
                    }
                    else if (!string.IsNullOrEmpty(rightmovePropertyListing.PriceQualifier) && regex.IsMatch(rightmovePropertyListing.PriceQualifier))
                    {
                        excludedTermFound = term;
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(excludedTermFound))
                {
                    if (OptionsForm.DebugingEnabled)
                    {
                        _removedProperties[rightmovePropertyListing.Link] = "Excluded term found: " + excludedTermFound;
                    }
                    return(false);
                }
            }

            if (fullTest)
            {
                // We only test for terms that must be included in a full test
                // as the search listings page doesn't include the full
                // description so we could potentially filter out matching
                // properties if we were to do this prior to having the full
                // description of the property.

                if (_shortlist.ExcludeTerms.Count() > 0)
                {
                    bool requiredTermFound = false;
                    foreach (string term in _shortlist.IncludeTerms)
                    {
                        var regex = new Regex(@"\b" + term + @"\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                        if (regex.IsMatch(rightmovePropertyListing.Title))
                        {
                            requiredTermFound = true;
                            break;
                        }
                        else if (regex.IsMatch(rightmovePropertyListing.Description))
                        {
                            requiredTermFound = true;
                            break;
                        }
                        else if (!string.IsNullOrEmpty(rightmovePropertyListing.PriceQualifier) && regex.IsMatch(rightmovePropertyListing.PriceQualifier))
                        {
                            requiredTermFound = true;
                            break;
                        }
                    }
                    if (!requiredTermFound)
                    {
                        if (OptionsForm.DebugingEnabled)
                        {
                            _removedProperties[rightmovePropertyListing.Link] = "One or more required terms were not found.";
                        }
                        return(false);
                    }
                }

                // Annoyingly, not all properties on Rightmove list when they were added so any with a DateTime.MinValue
                // are properties that were added on an unknown date.

                if (_shortlist.ExcludePostcodes.Count() > 0)
                {
                    var postcodeRegex = new Regex("propertyPostcode: \"([^\"]+)\",", RegexOptions.Compiled);
                    var postcodeMatch = postcodeRegex.Match(rightmovePropertyListing.Html);
                    if (postcodeMatch.Success)
                    {
                        var postcode = Postcode.Parse(postcodeMatch.Groups[1].Value);
                        foreach (string excludePostcode in _shortlist.ExcludePostcodes)
                        {
                            var excludedPostcode = Postcode.Parse(excludePostcode);
                            if (excludedPostcode.IsPartcialMatch(postcode))
                            {
                                return(false);
                            }
                        }
                    }
                }

                //TODO: finish filtering the listings....
                // AddedAfter, etc.
            }

            return(true);
        }