GivenTheFileREAResidentialCurrent_ParseThenSerializeThenDeserialize_ReturnsAResidentialAvailableListing(string fileName, bool isFloorPlansCleared, StatusType statusType) { // Arrange. ResidentialListing expectedListing; if (statusType == StatusType.Available) { expectedListing = FakeListings.CreateAFakeResidentialListing(); } else { expectedListing = CreateAFakeEmptyResidentialListing("Residential-Sold-ABCD1234"); expectedListing.StatusType = StatusType.Sold; expectedListing.SourceStatus = "sold"; expectedListing.Pricing = new SalePricing { SoldOn = new DateTime(2009, 1, 10, 12, 30, 00), SoldPrice = 580000M, SoldPriceText = "$580,000" }; } if (isFloorPlansCleared) { expectedListing.FloorPlans = new List <Media>(); } var reaXml = File.ReadAllText(FakeDataFolder + fileName); var reaXmlTransmorgrifier = new ReaXmlTransmorgrifier(); // Parse the xml, once for the first time. var tempResult = reaXmlTransmorgrifier.Parse(reaXml); var source = tempResult.Listings.First().Listing; var json = source.SerializeObject(); // Act. var result = JsonConvertHelpers.DeserializeObject(json); // Assert. var listingResult = new ListingResult { Listing = result, SourceData = "blahblah" }; var parsedResult = new ParsedResult { Listings = new List <ListingResult> { listingResult }, UnhandledData = new List <string>(), Errors = new List <ParsedError>(), TransmorgrifierName = "REA" }; AssertResidentialListing(parsedResult, expectedListing); }
public void GivenSomeJsonOfASingleListing_DeserializeObjectToAbstractListing_ReturnsAListing() { // Arrange. var listing = FakeListings.CreateAFakeListing <ResidentialListing>(); var json = listing.SerializeObject(); // Act. var convertedListing = JsonConvertHelpers.DeserializeObject <Listing>(json); // Assert. convertedListing.Id.ShouldBe(listing.Id); }
public void GivenAnOlderStatusType_DeserializeObject_ReturnsAListingWithTheCorrectlyConvertedStatusType(string oldStatusType, StatusType expectedStatusType) { // Arrange. var listing = FakeData.FakeListings.CreateAFakeResidentialListing(); var originalJson = JsonConvertHelpers.SerializeObject(listing); var json = originalJson.Replace("Available", oldStatusType); json.ShouldContain($"\"StatusType\": \"{oldStatusType}\""); // Act. var newListing = JsonConvertHelpers.DeserializeObject(json); // Assert. newListing.StatusType.ShouldBe(expectedStatusType); }