Exemple #1
0
            public void GivenSomeValidJson_Parse_ReturnsAListing(Type listingType,
                                                                 int listingCount)
            {
                // Arrange.
                var existingListing = CreateListings(listingType, listingCount);
                var json            = JsonConvertHelpers.SerializeObject(existingListing);
                var transmorgrifier = new JsonTransmorgrifier();

                // Act.
                var result = transmorgrifier.Parse(json);

                // Assert.
                result.Listings.Count.ShouldBe(listingCount);
                result.UnhandledData.Count.ShouldBe(0);
                result.Errors.Count.ShouldBe(0);

                for (var i = 0; i < result.Listings.Count; i++)
                {
                    if (listingType == typeof(ResidentialListing))
                    {
                        ResidentialListingAssertHelpers.AssertResidentialListing(
                            (ResidentialListing)result.Listings[i].Listing,
                            (ResidentialListing)existingListing[i]);
                    }
                    else if (listingType == typeof(RentalListing))
                    {
                        RentalListingAssertHelpers.AssertRuralListing(
                            (RentalListing)result.Listings[i].Listing,
                            (RentalListing)existingListing[i]);
                    }
                    else if (listingType == typeof(LandListing))
                    {
                        LandListingAssertHelpers.AssertLandListing(
                            (LandListing)result.Listings[i].Listing,
                            (LandListing)existingListing[i]);
                    }
                    else if (listingType == typeof(RuralListing))
                    {
                        RuralListingAssertHelpers.AssertRuralListing(
                            (RuralListing)result.Listings[i].Listing,
                            (RuralListing)existingListing[i]);
                    }
                    else
                    {
                        throw new Exception($"Failed to assert the suggested type: '{listingType}'.");
                    }
                }
            }
Exemple #2
0
        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);
        }
Exemple #3
0
            public void GivenSomeJsonWithAnMissingListingType_Parse_ReturnsAnError()
            {
                // Arrange.
                var existingListing = CreateListings(typeof(ResidentialListing), 1);
                var json            = JsonConvertHelpers.SerializeObject(existingListing).Replace("\"Residential\",", "\"blah\",");

                var transmorgrifier = new JsonTransmorgrifier();

                // Act.
                var result = transmorgrifier.Parse(json);

                // Assert.
                result.Listings.Count.ShouldBe(0);
                result.UnhandledData.Count.ShouldBe(0);
                result.Errors.Count.ShouldBe(1);
                result.Errors.First()
                .ExceptionMessage.ShouldBe(
                    "Invalid value found in the expected json-property 'listingType'. Only the following values (ie. listing types) as supported: residential, rental, land or rural.");
                result.Errors.First().InvalidData.ShouldNotBeNullOrWhiteSpace();
            }