예제 #1
0
        private static void CopyToViewModel(KeyValuePair <string, ConvertToResult> convertToResultKeyValuePair,
                                            ConvertViewModel viewModel)
        {
            if (convertToResultKeyValuePair.Value == null)
            {
                throw new ArgumentNullException("convertToResultKeyValuePair");
            }

            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            var errors = new List <ValidationError>();

            var listings = convertToResultKeyValuePair.Value.Listings.Select(x => x.Listing).ToList();

            if (listings.Any())
            {
                foreach (var listing in listings)
                {
                    var ruleSet = listing.StatusType == StatusType.Current
                        ? ValidatorMediator.MinimumRuleSet
                        : null;
                    var validationResults = ValidatorMediator.Validate(listing, ruleSet);
                    if (validationResults.Errors != null &&
                        validationResults.Errors.Any())
                    {
                        errors.AddRange(ValidationError.ConvertToValidationErrors(listing.ToString(),
                                                                                  validationResults.Errors));
                    }
                }

                if (viewModel.Listings == null)
                {
                    viewModel.Listings = new List <Listing>();
                }

                viewModel.Listings.AddRange(listings);
            }

            if (errors.Any())
            {
                if (viewModel.ValidationErrors == null)
                {
                    viewModel.ValidationErrors = new Dictionary <string, string>();
                }

                var convertedErrors = ConvertErrorsToDictionary(convertToResultKeyValuePair.Key, errors);
                foreach (var convertedError in convertedErrors)
                {
                    viewModel.ValidationErrors.Add(convertedError);
                }
            }
        }
예제 #2
0
            public void GivenARentalListing_Validate_ValidatesTheListingWithNoErrors()
            {
                // Arrange.
                var listing = GetListing(typeof(RentalListing));

                // Arrange.
                var result = ValidatorMediator.Validate(listing);

                // Assert.
                result.Errors.Count.ShouldBe(0);
            }
            public void GivenAWithdrawnResidentialListingWithStrictValidation_Validate_ValidatesTheListingWithNoErrors()
            {
                // Arrange.
                var listing = GetListing("Sample Data\\Transmorgrifiers\\REA\\Residential\\REA-Residential-Withdrawn.xml");

                // Arrange.
                var result = ValidatorMediator.Validate(listing);

                // Assert.
                result.Errors.Count.ShouldBe(4);
            }
        public void GivenARentalListing_Validate_ValidatesTheListingWithNoErrors()
        {
            // Arrange.
            var listing = FakeData.FakeListings.CreateAFakeRentalListing();

            // Arrange.
            var result = ValidatorMediator.Validate(listing);

            // Assert.
            result.Errors.Count.ShouldBe(0);
        }
        public void GivenARemovedResidentialListing_Validate_ValidatesTheListingWithNoErrors()
        {
            // Arrange.
            var listing = FakeResidentialListing(StatusType.Removed);

            // Arrange.
            var result = ValidatorMediator.Validate(listing, ListingValidatorRuleSet.Minimum);

            // Assert.
            result.Errors.Count.ShouldBe(0);
        }
예제 #6
0
            public void GivenARentalListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
            {
                // Arrange.
                var listing = (RentalListing)GetListing(typeof(RentalListing));

                listing.Id           = null;
                listing.AgencyId     = null;
                listing.PropertyType = PropertyType.Unknown;

                // Arrange.
                var result = ValidatorMediator.Validate(listing, ValidatorMediator.MinimumRuleSet);

                // Assert.
                result.Errors.Count.ShouldBe(3);
            }
예제 #7
0
            public void GivenALandListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
            {
                // Arrange.
                var listing = (LandListing)GetListing(typeof(LandListing));

                listing.Id           = null;
                listing.AgencyId     = null;
                listing.CategoryType = CategoryType.Unknown; // That's allowed, now :(

                // Arrange.
                var result = ValidatorMediator.Validate(listing, ValidatorMediator.MinimumRuleSet);

                // Assert.
                result.Errors.Count.ShouldBe(2);
            }
예제 #8
0
            public void GivenARuralListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
            {
                // Arrange.
                var listing = (RuralListing)GetListing(typeof(RuralListing));

                listing.Id                = null;
                listing.AgencyId          = null;
                listing.Pricing.SalePrice = -1;

                // Arrange.
                var result = ValidatorMediator.Validate(listing);

                // Assert.
                result.Errors.Count.ShouldBe(3);
            }
        public void GivenARentalListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
        {
            // Arrange.
            var listing = FakeData.FakeListings.CreateAFakeRentalListing();

            listing.Id           = null;
            listing.AgencyId     = null;
            listing.PropertyType = PropertyType.Unknown;

            // Arrange.
            var result = ValidatorMediator.Validate(listing);

            // Assert.
            result.Errors.Count.ShouldBe(3);
        }
        public void GivenALandListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
        {
            // Arrange.
            var listing = FakeData.FakeListings.CreateAFakeLandListing();

            listing.Id           = null;
            listing.AgencyId     = null;
            listing.CategoryType = LandCategoryType.Unknown; // That's allowed, now :(

            // Arrange.
            var result = ValidatorMediator.Validate(listing, ListingValidatorRuleSet.Minimum);

            // Assert.
            result.Errors.Count.ShouldBe(2);
        }
        public void GivenACurrentResidentialListingWithSomeRequiredMissingData_Validate_ValidatesTheListingWithSomeErrors()
        {
            // Arrange.
            var listing = FakeData.FakeListings.CreateAFakeResidentialListing();

            listing.Id                = null;
            listing.AgencyId          = null;
            listing.Pricing.SalePrice = -1;

            // Arrange.
            var result = ValidatorMediator.Validate(listing);

            // Assert.
            result.Errors.Count.ShouldBe(3);
        }
예제 #12
0
        private static void CopyToViewModel(KeyValuePair <string, ConvertToResult> convertToResultKeyValuePair,
                                            ConvertViewModel viewModel)
        {
            if (convertToResultKeyValuePair.Value == null)
            {
                throw new ArgumentNullException("convertToResultKeyValuePair");
            }

            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            var errors = new List <ValidationError>();

            var listings = convertToResultKeyValuePair.Value.Listings != null
                ? convertToResultKeyValuePair.Value.Listings.Select(x => x.Listing).ToList()
                : null;

            var invalidData = convertToResultKeyValuePair.Value.Errors != null
                ? convertToResultKeyValuePair.Value.Errors.Select(x => x.ExceptionMessage).ToList()
                : null;

            var unhandledData = convertToResultKeyValuePair.Value.UnhandledData != null
                ? convertToResultKeyValuePair.Value.UnhandledData.Select(x => x).ToList()
                : null;

            if (listings != null &&
                listings.Any())
            {
                foreach (var listing in listings)
                {
                    // We only do strict validation (the bare minimum needed to store a listing) if this is current.
                    var validationResults = ValidatorMediator.Validate(listing, listing.StatusType == StatusType.Current);
                    if (validationResults.Errors != null &&
                        validationResults.Errors.Any())
                    {
                        errors.AddRange(ValidationError.ConvertToValidationErrors(listing.ToString(),
                                                                                  validationResults.Errors));
                    }
                }

                if (viewModel.Listings == null)
                {
                    viewModel.Listings = new List <Listing>();
                }

                viewModel.Listings.AddRange(listings);
            }

            if (viewModel.ValidationErrors == null)
            {
                viewModel.ValidationErrors = new Dictionary <string, string>();
            }

            if (invalidData != null &&
                invalidData.Any())
            {
                CreateError(viewModel.ValidationErrors, convertToResultKeyValuePair.Key, invalidData);
            }

            if (unhandledData != null &&
                unhandledData.Any())
            {
                var errorList = new [] { string.Format("Found: {0} unhandled data segments", unhandledData.Count) };
                CreateError(viewModel.ValidationErrors, convertToResultKeyValuePair.Key,
                            errorList);
            }

            if (errors.Any())
            {
                var convertedErrors = ConvertErrorsToDictionary(convertToResultKeyValuePair.Key, errors);
                foreach (var convertedError in convertedErrors)
                {
                    viewModel.ValidationErrors.Add(convertedError);
                }
            }
        }