Ejemplo n.º 1
0
        public void Should_have_error_when_fax_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                                                 new AddressSettings
            {
                FaxEnabled  = true,
                FaxRequired = true
            });

            model.FaxNumber = null;
            validator.ShouldHaveValidationErrorFor(x => x.FaxNumber, model);
            model.FaxNumber = "";
            validator.ShouldHaveValidationErrorFor(x => x.FaxNumber, model);


            //not required
            validator = new AddressValidator(_localizationService, _stateProvinceService,
                                             new AddressSettings
            {
                FaxEnabled  = true,
                FaxRequired = false
            });
            model.FaxNumber = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.FaxNumber, model);
            model.FaxNumber = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.FaxNumber, model);
        }
        public void Should_have_error_when_company_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(T, new AddressSettings
            {
                CompanyEnabled  = true,
                CompanyRequired = true
            });

            model.Company = null;
            validator.ShouldHaveValidationErrorFor(x => x.Company, model);
            model.Company = "";
            validator.ShouldHaveValidationErrorFor(x => x.Company, model);


            //not required
            validator = new AddressValidator(T, new AddressSettings
            {
                CompanyEnabled  = true,
                CompanyRequired = false
            });
            model.Company = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.Company, model);
            model.Company = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.Company, model);
        }
Ejemplo n.º 3
0
        public void Should_have_error_when_zippostalcode_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                                                 new AddressSettings
            {
                ZipPostalCodeEnabled  = true,
                ZipPostalCodeRequired = true
            });

            model.ZipPostalCode = null;
            validator.ShouldHaveValidationErrorFor(x => x.ZipPostalCode, model);
            model.ZipPostalCode = "";
            validator.ShouldHaveValidationErrorFor(x => x.ZipPostalCode, model);


            //not required
            validator = new AddressValidator(_localizationService, _stateProvinceService,
                                             new AddressSettings
            {
                ZipPostalCodeEnabled  = true,
                ZipPostalCodeRequired = false
            });
            model.ZipPostalCode = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.ZipPostalCode, model);
            model.ZipPostalCode = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.ZipPostalCode, model);
        }
        public void Should_have_error_when_streetaddress2_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(T, new AddressSettings
            {
                StreetAddress2Enabled  = true,
                StreetAddress2Required = true
            });

            model.Address2 = null;
            validator.ShouldHaveValidationErrorFor(x => x.Address2, model);
            model.Address2 = "";
            validator.ShouldHaveValidationErrorFor(x => x.Address2, model);

            //not required
            validator = new AddressValidator(T, new AddressSettings
            {
                StreetAddress2Enabled  = true,
                StreetAddress2Required = false
            });
            model.Address2 = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.Address2, model);
            model.Address2 = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.Address2, model);
        }
        public void Should_have_error_when_phone_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(T, new AddressSettings()
            {
                PhoneEnabled  = true,
                PhoneRequired = true
            });

            model.PhoneNumber = null;
            validator.ShouldHaveValidationErrorFor(x => x.PhoneNumber, model);
            model.PhoneNumber = "";
            validator.ShouldHaveValidationErrorFor(x => x.PhoneNumber, model);

            //not required
            validator = new AddressValidator(T, new AddressSettings()
            {
                PhoneEnabled  = true,
                PhoneRequired = false
            });
            model.PhoneNumber = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.PhoneNumber, model);
            model.PhoneNumber = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.PhoneNumber, model);
        }
Ejemplo n.º 6
0
        public void IsAddressValid_Will_Return_True_For_An_Address_With_All_Required_And_Valid_Values()
        {
            Fake <AddressInfo>();
            Fake <StateInfo, StateInfoProvider>().WithData(
                new StateInfo
            {
                StateID   = 10,
                StateName = "TestState"
            });
            Fake <CountryInfo, CountryInfoProvider>().WithData(
                new CountryInfo
            {
                CountryID   = 2,
                CountryName = "TestCountry"
            });

            var address = new AddressInfo
            {
                AddressID        = 1,
                AddressLine1     = "1234 Test",
                AddressStateID   = 10,
                AddressCountryID = 2,
                AddressZip       = "11111"
            };

            var sut = new AddressValidator(new string[] { "12345" });

            sut.IsAddressValid(address).Should().BeTrue();
        }
Ejemplo n.º 7
0
        public void Should_have_error_when_city_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService,
                                                 new AddressSettings()
            {
                CityEnabled  = true,
                CityRequired = true
            });

            model.City = null;
            validator.ShouldHaveValidationErrorFor(x => x.City, model);
            model.City = "";
            validator.ShouldHaveValidationErrorFor(x => x.City, model);


            //not required
            validator = new AddressValidator(_localizationService,
                                             new AddressSettings()
            {
                CityEnabled  = true,
                CityRequired = false
            });
            model.City = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.City, model);
            model.City = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.City, model);
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Address address;
            IValidator <Address> validator;

            try
            {
                address = new Address
                {
                    AddressLine1 = AddressLine1,
                    AddressLine2 = AddressLine2,
                    City         = City,
                    Country      = Country,
                    PostalCode   = PostalCode,
                    Region       = Region,
                    State        = State
                };

                validator = new AddressValidator(Partner);

                WriteObject(validator.IsValid(address));
            }
            finally
            {
                address = null;
            }
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            OrganizationProfile  profile;
            IValidator <Address> validator;

            if (ShouldProcess("Updates the partner's organization profile"))
            {
                profile = Partner.Profiles.OrganizationProfile.Get();

                profile.CompanyName = UpdateValue(CompanyName, profile.CompanyName);
                profile.Email       = UpdateValue(Email, profile.Email);
                profile.Language    = UpdateValue(Language, profile.Language);
                profile.Culture     = UpdateValue(Culture, profile.Culture);

                profile.DefaultAddress.AddressLine1 = UpdateValue(AddressLine1, profile.DefaultAddress.AddressLine1);
                profile.DefaultAddress.AddressLine2 = UpdateValue(AddressLine2, profile.DefaultAddress.AddressLine2);
                profile.DefaultAddress.City         = UpdateValue(City, profile.DefaultAddress.City);
                profile.DefaultAddress.Country      = UpdateValue(Country, profile.DefaultAddress.Country);
                profile.DefaultAddress.PostalCode   = UpdateValue(PostalCode, profile.DefaultAddress.PostalCode);
                profile.DefaultAddress.State        = UpdateValue(State, profile.DefaultAddress.State);
                profile.DefaultAddress.FirstName    = UpdateValue(FirstName, profile.DefaultAddress.FirstName);
                profile.DefaultAddress.LastName     = UpdateValue(LastName, profile.DefaultAddress.LastName);
                profile.DefaultAddress.PhoneNumber  = UpdateValue(PhoneNumber, profile.DefaultAddress.PhoneNumber);

                validator = new AddressValidator(Partner);

                if (validator.IsValid(profile.DefaultAddress))
                {
                    profile = Partner.Profiles.OrganizationProfile.Update(profile);
                    WriteObject(new PSOrganizationProfile(profile));
                }
            }
        }
        public void Should_have_error_when_company_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    CompanyEnabled = true,
                    CompanyRequired = true
                });
            model.Company = null;
            validator.ShouldHaveValidationErrorFor(x => x.Company, model);
            model.Company = "";
            validator.ShouldHaveValidationErrorFor(x => x.Company, model);

            //not required
            validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    CompanyEnabled = true,
                    CompanyRequired = false
                });
            model.Company = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.Company, model);
            model.Company = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.Company, model);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Validates the address using Geocoding.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="returnLatLongInfo">Whether to return lat/long info.</param>
        /// <returns>Matching addresses with reliability values.</returns>
        public IEnumerable <AddressModel> Validate(string address, bool returnLatLongInfo = false)
        {
            var addressValidator = new AddressValidator();
            var result           = addressValidator.ValidateAddress(address, returnLatLongInfo ? DatabaseType.GNAF : DatabaseType.PAF);

            return((result).ToAddressModel());
        }
        public void CanDetectInvalidAddress()
        {
            var invalidAddress   = "invalid";
            var addressValidator = new AddressValidator(Network.Main);

            Assert.False(addressValidator.IsValid(invalidAddress));
        }
        public AddressValidatorTestsFixture()
        {
            AddressesProviderMock = new Mock <IIpRulesProvider>();
            var loggerMock = new Mock <ILogger <AddressValidator> >().Object;

            Sut = new AddressValidator(AddressesProviderMock.Object, loggerMock);
        }
Ejemplo n.º 14
0
        public async void AddressValidatorReturnsCorrectResult(IAddress model, bool expectedResult)
        {
            var sut    = new AddressValidator();
            var result = await sut.IsValidAsync(model);

            result.Should().Be(expectedResult);
        }
        public void IsValidCNAddress()
        {
            Address          address;
            AddressValidator validator;
            Mock <IPartner>  partnerOperations;

            partnerOperations = new Mock <IPartner>();
            partnerOperations.Setup(p => p.CountryValidationRules.ByCountry("CN").Get())
            .Returns(OperationFactory.Instance.GetResource <CountryValidationRules>("GetCountryValidationRules-CN"));
            partnerOperations.Setup(p => p.Validations.IsAddressValid(It.IsAny <Address>())).Returns(true);

            validator = new AddressValidator(partnerOperations.Object);

            address = new Address
            {
                AddressLine1 = "5 Danling Street",
                City         = "Haidian District",
                Country      = "CN",
                FirstName    = "John",
                LastName     = "Doe",
                PhoneNumber  = "(86-10) 5917-0101",
                PostalCode   = "100080",
                State        = "BJ"
            };

            Assert.AreEqual(true, validator.IsValid(address));
        }
        public void IsValidDEAddress()
        {
            Address          address;
            AddressValidator validator;
            Mock <IPartner>  partnerOperations;

            partnerOperations = new Mock <IPartner>();
            partnerOperations.Setup(p => p.CountryValidationRules.ByCountry("DE").Get())
            .Returns(OperationFactory.Instance.GetResource <CountryValidationRules>("GetCountryValidationRules-DE"));
            partnerOperations.Setup(p => p.Validations.IsAddressValid(It.IsAny <Address>())).Returns(true);

            validator = new AddressValidator(partnerOperations.Object);

            address = new Address
            {
                AddressLine1 = "Walter-Gropius-Str. 5",
                City         = "München",
                Country      = "DE",
                FirstName    = "John",
                LastName     = "Doe",
                PhoneNumber  = "49 (89) 3176 4900",
                PostalCode   = "80807"
            };

            Assert.AreEqual(true, validator.IsValid(address));
        }
        public void InvalidAddressValueTest()
        {
            Address          address;
            AddressValidator validator;
            Mock <IPartner>  partnerOperations;

            partnerOperations = new Mock <IPartner>();
            partnerOperations.Setup(p => p.CountryValidationRules.ByCountry("US").Get())
            .Returns(OperationFactory.Instance.GetResource <CountryValidationRules>("GetCountryValidationRules-US"));
            partnerOperations.Setup(p => p.Validations.IsAddressValid(It.IsAny <Address>())).Returns(false);

            validator = new AddressValidator(partnerOperations.Object);

            address = new Address
            {
                AddressLine1 = "1 Microsoft Way",
                City         = "Redmond",
                Country      = "US",
                FirstName    = "John",
                LastName     = "Doe",
                PhoneNumber  = "425-55-5555",
                PostalCode   = "98052",
                State        = "Washington"
            };

            validator.IsValid(address);
        }
        /// <summary>
        /// Gets the RDAP information from the RDAP endpoint.
        /// </summary>
        /// <returns>The rdap data.</returns>
        /// <param name="address">Address to query.</param>
        private async Task <RdapAnalysisResult> GetRdapDataAsync(string address)
        {
            string rdapApiUrl = Config.GetValue <string>("rdapApiUrl");
            string type       = string.Empty;

            switch (AddressValidator.GetAddressType(address))
            {
            case AddressType.Domain:
                type = "domain";
                break;

            case AddressType.IPAddress:
                type = "ip";
                break;

            default:
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            Uri                rdapAnalyzeRoute = new Uri($"{rdapApiUrl}/api/v1/analyze/{type}/{address}");
            RdapWorker         rdapWorker       = new RdapWorker(rdapAnalyzeRoute);
            RdapAnalysisResult result           = await rdapWorker.FetchDataAsync();

            return(result);
        }
Ejemplo n.º 19
0
        public void IsValidGBAddress()
        {
            Address          address;
            AddressValidator validator;
            Mock <IPartner>  partnerOperations;

            try
            {
                partnerOperations = new Mock <IPartner>();
                partnerOperations.Setup(p => p.CountryValidationRules.ByCountry("GB").Get())
                .Returns(OperationFactory.Instance.GetResource <CountryValidationRules>("GetCountryValidationRules-GB"));
                partnerOperations.Setup(p => p.Validations.IsAddressValid(It.IsAny <Address>())).Returns(true);

                validator = new AddressValidator(partnerOperations.Object);

                address = new Address
                {
                    AddressLine1 = "Manchester Business Park 3000 Aviator Way",
                    City         = "Manchester",
                    Country      = "GB",
                    FirstName    = "John",
                    LastName     = "Doe",
                    PhoneNumber  = "0344 800 2400",
                    PostalCode   = "M22 5TG"
                };

                Assert.AreEqual(true, validator.IsValid(address));
            }
            finally
            {
                address           = null;
                partnerOperations = null;
                validator         = null;
            }
        }
 public ImporterValidatorTests()
 {
     var countryRepository = A.Fake<Domain.ICountryRepository>();
     var addressValidator = new AddressValidator(countryRepository);
     var contactValidator = new ContactValidator();
     validator = new ImporterValidator(addressValidator, contactValidator);
 }
Ejemplo n.º 21
0
        public ExporterValidatorTests()
        {
            var countryRepository = A.Fake <Domain.ICountryRepository>();
            var addressValidator  = new AddressValidator(countryRepository);
            var contactValidator  = new ContactValidator();

            validator = new ExporterValidator(addressValidator, contactValidator);
        }
        public void AddressValidatorReturnsTrueForIpV6Address()
        {
            string input    = IPAddress.IPv6Loopback.ToString();
            bool   expected = true;
            bool   actual   = AddressValidator.IsAddressValid(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 23
0
    static void Main()
    {
        AddressValidator firstInstance  = AddressValidator.getInstance();
        AddressValidator secondInstance = AddressValidator.getInstance();

        Console.WriteLine("firstInstance: " + firstInstance.GetHashCode());
        Console.WriteLine("secondInstance: " + secondInstance.GetHashCode());
    }
        public void AddressValidatorReturnsFalseForInvalidIpV4Address()
        {
            string input    = "123";
            bool   expected = false;
            bool   actual   = AddressValidator.IsAddressValid(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets extended attributes associated with the addresses. Extended attributes are things such as
        /// region names and other data associated with an address stored in the Geocoding system.
        /// </summary>
        /// <param name="addresses">The addresses.</param>
        /// <returns>Adresses with their attributes.</returns>
        public IEnumerable <AddressModel> GetAttributes(IEnumerable <AddressModel> addresses)
        {
            var query            = addresses.Select(address => new Address(address.Line1, address.Line2, address.Line3, address.Locality, address.State, address.Postcode)).ToArray();
            var addressValidator = new AddressValidator();
            var result           = addressValidator.AssignRegionsToAddresses(query);

            return((result).ToAddressModel());
        }
        public void AddressValidatorReturnsFalseForEmptyString()
        {
            string input    = string.Empty;
            bool   expected = false;
            bool   actual   = AddressValidator.IsAddressValid(input);

            Assert.AreEqual(expected, actual);
        }
        public void AddressValidatorReturnsUnknownWhenInputStringIsInvalid()
        {
            string      input    = "!@#$%!@#$";
            AddressType expected = AddressType.Unknown;
            AddressType actual   = AddressValidator.GetAddressType(input);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 28
0
        public void Validates_To_False_If_Address_Null(Address address, bool expected)
        {
            var sut = new AddressValidator();

            var result = sut.IsValid(address);

            result.Should().Be(expected);
        }
        public void CheckCashAddress()
        {
            var address          = "17hFbeAibPyJ36PeH4hFDsjr35YC7wWmhv";
            var addressValidator = new AddressValidator(Network.Main, BCash.Instance.Mainnet);
            var parsedAddress    = addressValidator.GetBitcoinAddress(address);
            var result           = parsedAddress.ScriptPubKey.GetDestinationAddress(BCash.Instance.Mainnet).ToString();

            Assert.Equal("bitcoincash:qpykm9qwke5zj8je0sqqwu2tde6ej7lsvu2z4swqqj", result);
        }
Ejemplo n.º 30
0
        public void Should_not_have_error_when_email_is_correct_format()
        {
            var validator = new AddressValidator(T, new AddressSettings());

            var model = new AddressModel();

            model.Email = "*****@*****.**";
            validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
        public void Should_not_have_error_when_lastName_is_specified()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings());

            var model = new AddressModel();
            model.LastName = "Smith";
            validator.ShouldNotHaveValidationErrorFor(x => x.LastName, model);
        }
        public void Should_have_error_when_email_is_wrong_format()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings());

            var model = new AddressModel();
            model.Email = "adminexample.com";
            validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Ejemplo n.º 33
0
        public void Should_not_have_error_when_lastName_is_specified()
        {
            var validator = new AddressValidator(T, new AddressSettings());

            var model = new AddressModel();

            model.LastName = "Smith";
            validator.ShouldNotHaveValidationErrorFor(x => x.LastName, model);
        }
        public void CanDetectInvalidAddress()
        {
            PrepareNetworks.EnsureLiteCoinPrepared();

            var invalidAddress   = "invalid";
            var addressValidator = new AddressValidator(NBitcoin.Litecoin.Networks.Testnet);

            Assert.False(addressValidator.IsValid(invalidAddress));
        }
Ejemplo n.º 35
0
        public void Should_not_have_error_when_email_is_correct_format()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings());

            var model = new AddressModel();
            model.Email = "*****@*****.**";
            validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
Ejemplo n.º 36
0
        public void Should_not_have_error_when_firstName_is_specified()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings());

            var model = new AddressModel();
            model.FirstName = "John";
            validator.ShouldNotHaveValidationErrorFor(x => x.FirstName, model);
        }
        public void Should_have_error_when_email_is_null_or_empty()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings());

            var model = new AddressModel();
            model.Email = null;
            validator.ShouldHaveValidationErrorFor(x => x.Email, model);
            model.Email = "";
            validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Ejemplo n.º 38
0
        public void Should_have_error_when_lastName_is_null_or_empty()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings());

            var model = new AddressModel();
            model.LastName = null;
            validator.ShouldHaveValidationErrorFor(x => x.LastName, model);
            model.LastName = "";
            validator.ShouldHaveValidationErrorFor(x => x.LastName, model);
        }
Ejemplo n.º 39
0
        public void ReturnCandidateList()
        {
            // Arrange
            var addressValidator = new AddressValidator(this.apiUrl, this.authId, this.authToken);
            var addressToValidate = new Address { Street = "315 Bowery", City = "New York", State = "NY", Zip = string.Empty };

            // Act
            List<CandidateAddress> candidateAddresses = addressValidator.Validate(addressToValidate);

            // Assert
            Assert.That(candidateAddresses.Count > 0);
        }
 public ImportNotificationValidatorTests()
 {
     var countryRepository = A.Fake<Domain.ICountryRepository>();
     var addressValidator = new AddressValidator(countryRepository);
     var contactValidator = A.Fake<ContactValidator>();
     var exporterValidator = new ExporterValidator(addressValidator, contactValidator);
     var facilityValidator = A.Fake<FacilityValidator>();
     var facilitiesValidator = new FacilityCollectionValidator(facilityValidator);
     var importerValidator = new ImporterValidator(addressValidator, contactValidator);
     var importRepository = A.Fake<Domain.ImportNotification.IImportNotificationRepository>();
     var preconsentedValidator = new PreconsentedValidator(importRepository);
     var producerValidator = new ProducerValidator(addressValidator, contactValidator);
     var draftImportRepository = A.Fake<DataAccess.Draft.IDraftImportNotificationRepository>();
     var shipmentValidator = new ShipmentValidator(draftImportRepository);
     var entryOrExitPointRepository = A.Fake<Domain.TransportRoute.IEntryOrExitPointRepository>();
     var competentAuthorityRepository = A.Fake<Domain.ICompetentAuthorityRepository>();
     var stateOfExportValidator = new StateOfExportValidator(entryOrExitPointRepository, competentAuthorityRepository);
     var stateOfImportValidator = new StateOfImportValidator(countryRepository, competentAuthorityRepository, entryOrExitPointRepository);
     var transitStateValidator = new TransitStateValidator(entryOrExitPointRepository, competentAuthorityRepository);
     var transitStatesValidator = new TransitStateCollectionValidator(transitStateValidator);
     var wasteOperationValidator = new WasteOperationValidator();
     var wasteTypeValidator = new WasteTypeValidator();
     var chemicalCompositionValidator = new ChemicalCompositionValidator();
     validator = new ImportNotificationValidator(exporterValidator,
         facilitiesValidator,
         importerValidator,
         preconsentedValidator,
         producerValidator,
         shipmentValidator,
         stateOfExportValidator,
         stateOfImportValidator,
         transitStatesValidator,
         wasteOperationValidator,
         wasteTypeValidator,
         chemicalCompositionValidator);
 }
 public void Validate_AddressWithNoPostcode_GeneratesListOfErrors()
 {
     var address = new Address();
     var result = new AddressValidator().Validate(address);
     Assert.That(result.Errors.Count, Is.EqualTo(1));
 }
 public void SetUp()
 {
     sanFrancisco = AddressMother.SanFrancisco(ConstituentMother.ConstituentWithName(ConstituentNameMother.JamesFranklin()));
     validator = new AddressValidator();
 }
Ejemplo n.º 43
0
        public void Should_not_have_error_when_fax_is_specified()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    FaxEnabled = true
                });

            var model = new AddressModel();
            model.FaxNumber = "Fax";
            validator.ShouldNotHaveValidationErrorFor(x => x.FaxNumber, model);
        }
Ejemplo n.º 44
0
        public void Should_have_error_when_fax_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    FaxEnabled = true,
                    FaxRequired = true
                });
            model.FaxNumber = null;
            validator.ShouldHaveValidationErrorFor(x => x.FaxNumber, model);
            model.FaxNumber = "";
            validator.ShouldHaveValidationErrorFor(x => x.FaxNumber, model);


            //not required
            validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    FaxEnabled = true,
                    FaxRequired = false
                });
            model.FaxNumber = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.FaxNumber, model);
            model.FaxNumber = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.FaxNumber, model);
        }
Ejemplo n.º 45
0
        public void Should_not_have_error_when_city_is_specified()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    CityEnabled = true
                });

            var model = new AddressModel();
            model.City = "City";
            validator.ShouldNotHaveValidationErrorFor(x => x.City, model);
        }
Ejemplo n.º 46
0
        public void Should_not_have_error_when_zippostalcode_is_specified()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    StreetAddress2Enabled = true
                });

            var model = new AddressModel();
            model.ZipPostalCode = "zip";
            validator.ShouldNotHaveValidationErrorFor(x => x.ZipPostalCode, model);
        }
Ejemplo n.º 47
0
        public void Should_have_error_when_zippostalcode_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    ZipPostalCodeEnabled = true,
                    ZipPostalCodeRequired = true
                });
            model.ZipPostalCode = null;
            validator.ShouldHaveValidationErrorFor(x => x.ZipPostalCode, model);
            model.ZipPostalCode = "";
            validator.ShouldHaveValidationErrorFor(x => x.ZipPostalCode, model);


            //not required
            validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    ZipPostalCodeEnabled = true,
                    ZipPostalCodeRequired = false
                });
            model.ZipPostalCode = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.ZipPostalCode, model);
            model.ZipPostalCode = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.ZipPostalCode, model);
        }
 public new void Setup()
 {
     _validator = new AddressValidator(_localizationService);
 }
 public AddressValidatorTests()
 {
     countryRepository = A.Fake<ICountryRepository>();
     A.CallTo(() => countryRepository.GetUnitedKingdomId()).Returns(unitedKingdomCountryId);
     validator = new AddressValidator(countryRepository);
 }
        public void Should_not_have_error_when_phone_is_specified()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    PhoneEnabled = true
                });

            var model = new AddressModel();
            model.PhoneNumber = "Phone";
            validator.ShouldNotHaveValidationErrorFor(x => x.PhoneNumber, model);
        }
        public void Should_not_have_error_when_company_is_specified()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    CompanyEnabled = true
                });

            var model = new AddressModel();
            model.Company = "Company";
            validator.ShouldNotHaveValidationErrorFor(x => x.Company, model);
        }
        public void Should_have_error_when_streetaddress_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    StreetAddressEnabled = true,
                    StreetAddressRequired = true
                });
            model.Address1 = null;
            validator.ShouldHaveValidationErrorFor(x => x.Address1, model);
            model.Address1 = "";
            validator.ShouldHaveValidationErrorFor(x => x.Address1, model);

            //not required
            validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    StreetAddressEnabled = true,
                    StreetAddressRequired = false
                });
            model.Address1 = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.Address1, model);
            model.Address1 = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.Address1, model);
        }
        public void Should_have_error_when_phone_is_null_or_empty_based_on_required_setting()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    PhoneEnabled = true,
                    PhoneRequired = true
                });
            model.PhoneNumber = null;
            validator.ShouldHaveValidationErrorFor(x => x.PhoneNumber, model);
            model.PhoneNumber = "";
            validator.ShouldHaveValidationErrorFor(x => x.PhoneNumber, model);

            //not required
            validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    PhoneEnabled = true,
                    PhoneRequired = false
                });
            model.PhoneNumber = null;
            validator.ShouldNotHaveValidationErrorFor(x => x.PhoneNumber, model);
            model.PhoneNumber = "";
            validator.ShouldNotHaveValidationErrorFor(x => x.PhoneNumber, model);
        }
 public AddressValidatorFacts()
 {
     _addressValidator = new AddressValidator();    
 }
Ejemplo n.º 55
0
        public void Should_not_have_error_when_streetaddress2_is_specified()
        {
            var validator = new AddressValidator(_localizationService, _stateProvinceService,
                new AddressSettings
                {
                    StreetAddress2Enabled = true
                });

            var model = new AddressModel();
            model.Address2 = "Street address 2";
            validator.ShouldNotHaveValidationErrorFor(x => x.Address2, model);
        }