SimonCropp / CountryData

Provides a .net wrapper around the GeoNames Data
Other
74 stars 8 forks source link

Add the ability to create a UK postcode based on chosen format #343

Closed LJBerridge closed 3 years ago

LJBerridge commented 3 years ago

Is It possible to create a postcode based on a format in the following file?

https://github.com/SimonCropp/CountryData/blob/master/Data/countryInfo.json.txt

For example: The UK has the following formats - "@# #@@|@## #@@|@@# #@@|@@## #@@|@#@ #@@|@@#@ #@@|GIR0AA"

It would be great if you could do the following - .RuleFor(Add => Add.Postcode, f => f.Country().UnitedKingdom().PostCode(@@## #@@))

SimonCropp commented 3 years ago

cant you already achieve this?


        var faker = new Faker<Target>()
            .RuleFor(
                property: u => u.RandomPostCode,
                setter: (f, u) => f.Country().UnitedKingdom().PostCode())
            .RuleFor(
                property: u => u.RandomPostCodes,
                setter: (f, u) => f.Country().UnitedKingdom().PostCode(10))
LJBerridge commented 3 years ago

Hey Simon,

you can, however when using f.Country().UnitedKingdom().PostCode() the result is always the area code only. See the below 100 results -

NG14,HD4,LL41,PH7,TD15,DG13,RG8,PH14,PE32,AB53,PA16,NE85,PE20,TF13,LA6,WF9,CV33,IV27,AL2,N1,SK17,PO17,CB8,TN12,N14,DT6,SA37,PL30,CO6,GU14,RH17,NR14,TD9,LN13,TA19,TR2,SW2,PL26,SS17,NN14,B66,GL52,SA18,BA16,TA3,SW1E,LE21,ML11,GL9,EX37,EH45,BA2,IV27,PL15,DA2,DG7,B79,HP18,DT2,EX32,LL77,GL51,EH21,HG3,SK17,LD2,RG27,NN13,WA7,KT6,PH2,RM12,BT41,TN6,LL24,SA62,WD1,DE4,IV40,TR14,EX39,SY10,DH1,W1,IP14,NN6,TN15,RH14,OX2,FK20,BD13,CR6,HR2,L68,SA33,SN13,IV3,AB35,SY20,DH98

For example the first postcode in that list is NG14, the second part would be 6LJ for Pepper Road, Calverton, Nottingham. The only reason it causes me an issue is that I have a service which checks whether the post code is valid when a record is saved and this format alone isn't valid. More a nice to have than an issue with the projecct.

SimonCropp commented 3 years ago

in that case, I am happy to accept a Pull Request for this