public void Copy(ListingAgent newListingAgent) { if (newListingAgent == null) { throw new ArgumentNullException("newListingAgent"); } if (newListingAgent.IsNameModified) { Name = newListingAgent.Name; } if (newListingAgent.IsCommunicationsModified) { if (newListingAgent.Communications == null) { Communications = newListingAgent.Communications; } else { Communications = new List<Communication>(); foreach (var newCommunication in newListingAgent.Communications) { var communication = new Communication(); communication.Copy(newCommunication); Communications.Add(communication); } } } if (newListingAgent.IsOrderModified) { Order = newListingAgent.Order; } }
public void Copy(ListingAgent newListingAgent) { if (newListingAgent == null) { throw new ArgumentNullException("newListingAgent"); } if (newListingAgent.IsNameModified) { Name = newListingAgent.Name; } if (newListingAgent.IsCommunicationsModified) { if (newListingAgent.Communications == null) { Communications = newListingAgent.Communications; } else { Communications = new List <Communication>(); foreach (var newCommunication in newListingAgent.Communications) { var communication = new Communication(); communication.Copy(newCommunication); Communications.Add(communication); } } } if (newListingAgent.IsOrderModified) { Order = newListingAgent.Order; } }
public void GiveACommunicationWithAnUnknownType_Validate_ShouldHaveAValidationError() { // Arrange. var listingAgent = new ListingAgent { Name = "a", Communications = new List<Communication> { new Communication { CommunicationType = CommunicationType.Unknown, Details = "a" } } }; // Act. _validator.ShouldHaveChildValidator(agent => agent.Communications, typeof(CommunicationValidator)); var result = _validator.Validate(listingAgent); //_validator.ShouldNotHaveValidationErrorFor(agent => agent.Communications, new[] {communication}); // Assert. result.Errors.ShouldContain(x => x.PropertyName == "Communications[0].CommunicationType"); }
public void GiveSomeCommunication_Validate_ShouldNotHaveAValidationError() { // Arrange. var listingAgent = new ListingAgent { Name = "a", Communications = new List<Communication> { new Communication { CommunicationType = CommunicationType.Email, Details = "a" } } }; // Act. _validator.ShouldHaveChildValidator(agent => agent.Communications, typeof (CommunicationValidator)); var result = _validator.Validate(listingAgent); //_validator.ShouldNotHaveValidationErrorFor(agent => agent.Communications, new[] {communication}); // Assert. result.Errors.Count.ShouldBe(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); } }
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); } }
private static IList<ListingAgent> ExtractAgent(XElement document) { document.ShouldNotBe(null); var agentElements = document.Elements("listingAgent").ToArray(); if (!agentElements.Any()) { return null; } var agents = new List<ListingAgent>(); foreach (var agentElement in agentElements) { var agent = new ListingAgent { Name = agentElement.ValueOrDefault("name") }; var orderValue = agentElement.AttributeValueOrDefault("id"); int order = 0; if (!string.IsNullOrWhiteSpace(orderValue) && int.TryParse(orderValue, out order)) { agent.Order = order; } var email = agentElement.ValueOrDefault("email"); agent.Communications = new List<Communication>(); if (!string.IsNullOrWhiteSpace(email)) { agent.Communications.Add(new Communication { CommunicationType = CommunicationType.Email, Details = email }); } var phoneMobile = agentElement.ValueOrDefault("telephone", "type", "mobile"); if (!string.IsNullOrWhiteSpace(phoneMobile)) { agent.Communications.Add(new Communication { CommunicationType = CommunicationType.Mobile, Details = phoneMobile }); } var phoneOffice = agentElement.ValueOrDefault("telephone", "type", "BH"); if (!string.IsNullOrWhiteSpace(phoneOffice)) { agent.Communications.Add(new Communication { CommunicationType = CommunicationType.Landline, Details = phoneOffice }); } // Some listings have this element but no data provided. :( // So we don't add 'emtpy' agents. if (!string.IsNullOrWhiteSpace(agent.Name)) { agents.Add(agent); } } var counter = 0; return agents.Any() ? agents .OrderBy(x => x.Order) .Select(x => new ListingAgent { Name = x.Name, Order = ++counter, Communications = x.Communications }) .ToList() : null; }