public void CepDetailsConverter_MustDeserializeAllFields() { //Given string cep = "01001000"; string address = "Praça da Sé"; string complement = "lado ímpar"; string neighbourhood = "Sé"; string city = "São Paulo"; string federativeUnit = "SP"; string ibge = "3550308"; string gia = "1004"; string ddd = "11"; string siafi = "7107"; string json = new StringBuilder() .Append("{") .Append($@"""cep"":""{cep}"",") .Append($@"""logradouro"":""{address}"",") .Append($@"""complemento"":""{complement}"",") .Append($@"""bairro"":""{neighbourhood}"",") .Append($@"""localidade"":""{city}"",") .Append($@"""uf"":""{federativeUnit}"",") .Append($@"""ibge"":""{ibge}"",") .Append($@"""gia"":""{gia}"",") .Append($@"""ddd"":""{ddd}"",") .Append($@"""siafi"":""{siafi}""") .Append("}") .ToString(); CepDetailsConverter converter = new CepDetailsConverter(); using JsonDocument jsonDocument = JsonDocument.Parse(json); IPlainJsonObject plainJsonObject = new PlainJsonObject(jsonDocument); //When CepDetails cepDetails = converter.FromJson(plainJsonObject); //Then cepDetails.Address.Should().Be(address); cepDetails.Cep.Should().Be(cep); cepDetails.City.Should().Be(city); cepDetails.Complement.Should().Be(complement); cepDetails.DDD.Should().Be(ddd); cepDetails.FederativeUnit.Should().Be(federativeUnit); cepDetails.GIA.Should().Be(gia); cepDetails.IBGE.Should().Be(ibge); cepDetails.Neighbourhood.Should().Be(neighbourhood); cepDetails.Siafi.Should().Be(siafi); }
/// <summary> /// ViaCepClient represents a client for ViaCep webservice /// </summary> public ViaCepClient(IRestClient restClient, IViaCepRequestBuilder requestBuilder) { _restClient = restClient; _requestBuilder = requestBuilder; _cepConverter = new CepDetailsConverter(); }