public void GivenASalePricing_Validate_ShouldNotHaveAValidationError() { // Arrange. var salePricing = new SalePricing { SalePrice = 1234, SalePriceText = "Contact agent" }; // Act & Assert. _validator.ShouldHaveChildValidator(listing => listing.Pricing, typeof(SalePricingValidator)); _validator.ShouldNotHaveValidationErrorFor(listing => listing.Pricing, salePricing); }
public void Copy(SalePricing newSalePricing) { if (newSalePricing == null) { throw new ArgumentNullException(); } if (newSalePricing.IsSalePriceModified) { SalePrice = newSalePricing.SalePrice; } if (newSalePricing.IsSalePriceTextModified) { SalePriceText = newSalePricing.SalePriceText; } if (newSalePricing.IsSoldPriceModified) { SoldPrice = newSalePricing.SoldPrice; } if (newSalePricing.IsSoldPriceTextModified) { SoldPriceText = newSalePricing.SoldPriceText; } if (newSalePricing.IsSoldOnModified) { SoldOn = newSalePricing.SoldOn; } if (newSalePricing.IsUnderOffer) { IsUnderOffer = newSalePricing.IsUnderOffer; } }
private static void AssertSalePrice(SalePricing pricing, string salePriceText, bool isModified) { pricing.SalePrice.ShouldBe(500000m); pricing.IsSalePriceModified.ShouldBe(isModified); pricing.SalePriceText.ShouldBe(salePriceText); pricing.IsSalePriceTextModified.ShouldBe(isModified); pricing.IsUnderOffer.ShouldBe(false); pricing.IsUnderOfferModified.ShouldBe(isModified); }
private static void ExtractSoldPrice(XElement element, SalePricing salePricing) { element.ShouldNotBe(null); salePricing.SoldPrice = element.DecimalValueOrDefault(); var soldDisplayAttribute = element.ValueOrDefault(null, "display"); // NOTE 1: no display price assumes a 'YES' and that the price -is- to be displayed. // NOTE 2: A _display attribute_ value of 'range' can only valid for commerical properties ... // and .. we don't handle commerical. So it will end up throwing an exception // which is legit in this case. var isDisplay = string.IsNullOrWhiteSpace(soldDisplayAttribute) || soldDisplayAttribute.ParseOneYesZeroNoToBool(); salePricing.SoldPriceText = isDisplay ? salePricing.SoldPrice.Value.ToString("C0") : null; }
private static SalePricing ExtractSalePricing(XElement document, CultureInfo cultureInfo) { document.ShouldNotBe(null); var salePricing = new SalePricing { SalePrice = document.MoneyValueOrDefault(cultureInfo, "price") }; // Selling data. var salePriceText = document.ValueOrDefault("priceView"); var displayAttributeValue = document.ValueOrDefault("price", "display"); var isDisplay = string.IsNullOrWhiteSpace(displayAttributeValue) || displayAttributeValue.ParseOneYesZeroNoToBool(); // NOTE: If Display="no" then we do not display anything for the price, regardless // of any other data provided. Otherwise, make a decision. salePricing.SalePriceText = isDisplay ? string.IsNullOrWhiteSpace(salePriceText) ? salePricing.SalePrice.ToString("C0") : salePriceText : null; var isUnderOffer = document.ValueOrDefault("underOffer", "value"); salePricing.IsUnderOffer = !string.IsNullOrWhiteSpace(isUnderOffer) && isUnderOffer.ParseOneYesZeroNoToBool(); // Sold data. var soldDetails = document.Element("soldDetails"); if (soldDetails != null) { // SoldPrice could be price or soldPrice. Thanks REA for such a great schema. var soldPrice = soldDetails.Element("price") ?? soldDetails.Element("soldPrice"); if (soldPrice != null) { ExtractSoldPrice(soldPrice, salePricing); } var soldDate = soldDetails.Element("date") ?? soldDetails.Element("soldDate"); if (soldDate != null) { ExtractSoldOn(soldDate, salePricing); } } return salePricing; }
private static void ExtractSoldOn(XElement element, SalePricing salePricing) { element.ShouldNotBe(null); // SoldOn could be date or soldData. Thanks REA for such a great schema. var soldOnText = element.ValueOrDefault(); if (!string.IsNullOrWhiteSpace(soldOnText)) { salePricing.SoldOn = ToDateTime(soldOnText); } }