private static void AssertRentalPricing(RentalPricing source, RentalPricing destination) { if (source == null && destination == null) { return; } source.Bond.ShouldBe(destination.Bond); source.PaymentFrequencyType.ShouldBe(destination.PaymentFrequencyType); source.RentalPrice.ShouldBe(destination.RentalPrice); source.RentalPriceText.ShouldBe(destination.RentalPriceText); }
// REF: http://reaxml.realestate.com.au/docs/reaxml1-xml-format.html#rent private static RentalPricing ExtractRentalPricing(XElement xElement, CultureInfo cultureInfo) { xElement.ShouldNotBe(null); // Quote: There can be multiple rent elements if you wish to specify a price for both monthly and weekly. // However, at least one of the rent elements must be for a weekly period. // Result: FML :( var rentElements = xElement.Elements("rent").ToArray(); if (!rentElements.Any()) { return(null); } // We will only use the WEEKLY one. var rentalPricing = new RentalPricing(); foreach (var rentElement in rentElements) { // Have to have a period. var frequency = rentElement.AttributeValueOrDefault("period"); if (string.IsNullOrWhiteSpace(frequency)) { continue; } if (frequency.Equals("week", StringComparison.InvariantCultureIgnoreCase) || frequency.Equals("weekly", StringComparison.InvariantCultureIgnoreCase)) { rentalPricing.PaymentFrequencyType = PaymentFrequencyType.Weekly; } else if (frequency.Equals("month", StringComparison.InvariantCultureIgnoreCase) || frequency.Equals("monthly", StringComparison.InvariantCultureIgnoreCase)) { rentalPricing.PaymentFrequencyType = PaymentFrequencyType.Monthly; } rentalPricing.RentalPrice = rentElement.MoneyValueOrDefault(cultureInfo); var displayAttributeValue = rentElement.AttributeValueOrDefault("display"); var isDisplay = string.IsNullOrWhiteSpace(displayAttributeValue) || displayAttributeValue.ParseOneYesZeroNoToBool(); rentalPricing.RentalPriceText = isDisplay ? rentalPricing.RentalPrice.ToString() : null; // NOTE: We only parse the first one. You have more than one? Pffftttt!!! Die! break; } // NOTE: Even though we have set the rental price text to be the last // rental period's value ... this can now be overwritten by // whatever value they might have in here ... if they have a value. var priceView = xElement.ValueOrDefault("priceView"); if (!string.IsNullOrWhiteSpace(priceView)) { rentalPricing.RentalPriceText = priceView; } rentalPricing.Bond = xElement.MoneyValueOrDefault(cultureInfo, "bond"); return(rentalPricing); }