Esempio n. 1
0
        public void TestAllFieldsFilledCorrectly()
        {
            const string responsePayload = "{\"results\":[" +
                                           "{\"coordinate\":{\"latitude\":1.1,\"longitude\":2.2,\"accuracy\":\"3\",\"license\":4}," +
                                           "\"distance\":5.5," +
                                           "\"address\":{\"street\":\"6\",\"city\":\"7\",\"state_abbreviation\":\"8\",\"zipcode\":\"9\"}" +
                                           "},]}";

            var    nativeSerializer = new NativeSerializer();
            Result result;

            using (var payloadStream = new MemoryStream(Encoding.ASCII.GetBytes(responsePayload)))
            {
                var response = nativeSerializer.Deserialize <SmartyResponse>(payloadStream) ?? new SmartyResponse {
                };
                result = response.Results[0];
            }

            #region [ Result ]

            Assert.AreEqual(5.5, result.Distance);

            #endregion

            #region [ Coordinate ]

            var coordinate = result.Coordinate;
            Assert.IsNotNull(coordinate);
            Assert.AreEqual(1.1, coordinate.Latitude);
            Assert.AreEqual(2.2, coordinate.Longitude);
            Assert.AreEqual("3", coordinate.Accuracy);
            Assert.AreEqual(4, coordinate.License);

            #endregion

            #region [ Address ]

            var address = result.Address;
            Assert.IsNotNull(address);
            Assert.AreEqual("6", address.Street);
            Assert.AreEqual("7", address.City);
            Assert.AreEqual("8", address.StateAbbreviation);
            Assert.AreEqual("9", address.ZipCode);

            #endregion
        }
        public void TestAllFieldsFilledCorrectly()
        {
            const string responsePayload = "[{\"input_id\":\"1234\",\"organization\":\"1\",\"address1\":\"2\",\"address2\":\"3\"," +
                                           "\"address3\":\"4\",\"address4\":\"5\",\"address5\":\"6\",\"address6\":\"7\",\"address7\":\"8\"," +
                                           "\"address8\":\"9\",\"address9\":\"10\",\"address10\":\"11\",\"address11\":\"12\",\"address12\":\"13\"," +
                                           "\"components\":{\"country_iso_3\":\"14\",\"super_administrative_area\":\"15\"," +
                                           "\"administrative_area\":\"16\",\"sub_administrative_area\":\"17\",\"dependent_locality\":\"18\"," +
                                           "\"dependent_locality_name\":\"19\",\"double_dependent_locality\":\"20\",\"locality\":\"21\"," +
                                           "\"postal_code\":\"22\",\"postal_code_short\":\"23\",\"postal_code_extra\":\"24\"," +
                                           "\"premise\":\"25\",\"premise_extra\":\"26\",\"premise_number\":\"27\",\"premise_number_prefix\":\"27.1\",\"premise_type\":\"28\"," +
                                           "\"thoroughfare\":\"29\",\"thoroughfare_predirection\":\"30\",\"thoroughfare_postdirection\":\"31\"," +
                                           "\"thoroughfare_name\":\"32\",\"thoroughfare_trailing_type\":\"33\",\"thoroughfare_type\":\"34\"," +
                                           "\"dependent_thoroughfare\":\"35\",\"dependent_thoroughfare_predirection\":\"36\"," +
                                           "\"dependent_thoroughfare_postdirection\":\"37\",\"dependent_thoroughfare_name\":\"38\"," +
                                           "\"dependent_thoroughfare_trailing_type\":\"39\",\"dependent_thoroughfare_type\":\"40\"," +
                                           "\"building\":\"41\",\"building_leading_type\":\"42\",\"building_name\":\"43\"," +
                                           "\"building_trailing_type\":\"44\",\"sub_building_type\":\"45\",\"sub_building_number\":\"46\"," +
                                           "\"sub_building_name\":\"47\",\"sub_building\":\"48\",\"post_box\":\"49\",\"post_box_type\":\"50\"," +
                                           "\"post_box_number\":\"51\"},\"metadata\":{\"latitude\":52.0,\"longitude\":53.0," +
                                           "\"geocode_precision\":\"54\",\"max_geocode_precision\":\"55\",\"address_format\":\"56\"}," +
                                           "\"analysis\":{\"verification_status\":\"57\",\"address_precision\":\"58\",\"max_address_precision\":\"59\"," +
                                           "\"changes\":{\"organization\":\"60\",\"address1\":\"61\",\"address2\":\"62\",\"address3\":\"63\"," +
                                           "\"address4\":\"64\",\"address5\":\"65\",\"address6\":\"66\",\"address7\":\"67\",\"address8\":\"68\"," +
                                           "\"address9\":\"69\",\"address10\":\"70\",\"address11\":\"71\",\"address12\":\"72\",\"components\":{" +
                                           "\"super_administrative_area\":\"73\",\"administrative_area\":\"74\",\"sub_administrative_area\":\"75\"," +
                                           "\"building\":\"76\",\"dependent_locality\":\"77\",\"dependent_locality_name\":\"78\"," +
                                           "\"double_dependent_locality\":\"79\",\"country_iso_3\":\"80\",\"locality\":\"81\",\"postal_code\":\"82\"," +
                                           "\"postal_code_short\":\"83\",\"postal_code_extra\":\"84\",\"premise\":\"85\",\"premise_extra\":\"86\"," +
                                           "\"premise_number\":\"87\",\"premise_type\":\"88\",\"premise_number_prefix\":\"89\",\"thoroughfare\":\"90\"," +
                                           "\"thoroughfare_predirection\":\"91\",\"thoroughfare_postdirection\":\"92\",\"thoroughfare_name\":\"93\"," +
                                           "\"thoroughfare_trailing_type\":\"94\",\"thoroughfare_type\":\"95\",\"dependent_thoroughfare\":\"96\"," +
                                           "\"dependent_thoroughfare_predirection\":\"97\",\"dependent_thoroughfare_postdirection\":\"98\"," +
                                           "\"dependent_thoroughfare_name\":\"99\",\"dependent_thoroughfare_trailing_type\":\"100\"," +
                                           "\"dependent_thoroughfare_type\":\"101\",\"building_leading_type\":\"102\"," +
                                           "\"building_name\":\"103\",\"building_trailing_type\":\"104\",\"sub_building_type\":\"105\"," +
                                           "\"sub_building_number\":\"106\",\"sub_building_name\":\"107\",\"sub_building\":\"108\"," +
                                           "\"post_box\":\"109\",\"post_box_type\":\"110\",\"post_box_number\":\"111\"}}}}]";

            var       nativeSerializer = new NativeSerializer();
            Candidate candidate;

            using (var payloadStream = new MemoryStream(Encoding.ASCII.GetBytes(responsePayload)))
            {
                var candidates = nativeSerializer.Deserialize <Candidate[]>(payloadStream) ?? new Candidate[0];
                candidate = candidates[0];
            }

            #region [ Candidate ]

            Assert.AreEqual("1234", candidate.InputId);
            Assert.AreEqual("1", candidate.Organization);
            Assert.AreEqual("2", candidate.Address1);
            Assert.AreEqual("3", candidate.Address2);
            Assert.AreEqual("4", candidate.Address3);
            Assert.AreEqual("5", candidate.Address4);
            Assert.AreEqual("6", candidate.Address5);
            Assert.AreEqual("7", candidate.Address6);
            Assert.AreEqual("8", candidate.Address7);
            Assert.AreEqual("9", candidate.Address8);
            Assert.AreEqual("10", candidate.Address9);
            Assert.AreEqual("11", candidate.Address10);
            Assert.AreEqual("12", candidate.Address11);
            Assert.AreEqual("13", candidate.Address12);

            #endregion

            #region [ Components ]

            var components = candidate.Components;
            Assert.IsNotNull(components);
            Assert.AreEqual("14", components.CountryIso3);
            Assert.AreEqual("15", components.SuperAdministrativeArea);
            Assert.AreEqual("16", components.AdministrativeArea);
            Assert.AreEqual("17", components.SubAdministrativeArea);
            Assert.AreEqual("18", components.DependentLocality);
            Assert.AreEqual("19", components.DependentLocalityName);
            Assert.AreEqual("20", components.DoubleDependentLocality);
            Assert.AreEqual("21", components.Locality);
            Assert.AreEqual("22", components.PostalCode);
            Assert.AreEqual("23", components.PostalCodeShort);
            Assert.AreEqual("24", components.PostalCodeExtra);
            Assert.AreEqual("25", components.Premise);
            Assert.AreEqual("26", components.PremiseExtra);
            Assert.AreEqual("27", components.PremiseNumber);
            Assert.AreEqual("27.1", components.PremiseNumberPrefix);
            Assert.AreEqual("28", components.PremiseType);
            Assert.AreEqual("29", components.Thoroughfare);
            Assert.AreEqual("30", components.ThoroughfarePredirection);
            Assert.AreEqual("31", components.ThoroughfarePostdirection);
            Assert.AreEqual("32", components.ThoroughfareName);
            Assert.AreEqual("33", components.ThoroughfareTrailingType);
            Assert.AreEqual("34", components.ThoroughfareType);
            Assert.AreEqual("35", components.DependentThoroughfare);
            Assert.AreEqual("36", components.DependentThoroughfarePredirection);
            Assert.AreEqual("37", components.DependentThoroughfarePostdirection);
            Assert.AreEqual("38", components.DependentThoroughfareName);
            Assert.AreEqual("39", components.DependentThoroughfareTrailingType);
            Assert.AreEqual("40", components.DependentThoroughfareType);
            Assert.AreEqual("41", components.Building);
            Assert.AreEqual("42", components.BuildingLeadingType);
            Assert.AreEqual("43", components.BuildingName);
            Assert.AreEqual("44", components.BuildingTrailingType);
            Assert.AreEqual("45", components.SubBuildingType);
            Assert.AreEqual("46", components.SubBuildingNumber);
            Assert.AreEqual("47", components.SubBuildingName);
            Assert.AreEqual("48", components.SubBuilding);
            Assert.AreEqual("49", components.PostBox);
            Assert.AreEqual("50", components.PostBoxType);
            Assert.AreEqual("51", components.PostBoxNumber);

            #endregion

            #region [ Metadata ]

            var metadata = candidate.Metadata;
            Assert.IsNotNull(metadata);
            Assert.AreEqual(52, metadata.Latitude, 0.001);
            Assert.AreEqual(53, metadata.Longitude, 0.001);
            Assert.AreEqual("54", metadata.GeocodePrecision);
            Assert.AreEqual("55", metadata.MaxGeocodePrecision);
            Assert.AreEqual("56", metadata.AddressFormat);

            #endregion

            #region [ Analysis ]

            var analysis = candidate.Analysis;
            Assert.IsNotNull(analysis);
            Assert.AreEqual("57", analysis.VerificationStatus);
            Assert.AreEqual("58", analysis.AddressPrecision);
            Assert.AreEqual("59", analysis.MaxAddressPrecision);

            #region [ Changes ]

            var changes = analysis.Changes;
            Assert.IsNotNull(changes);
            Assert.AreEqual("60", changes.Organization);
            Assert.AreEqual("61", changes.Address1);
            Assert.AreEqual("62", changes.Address2);
            Assert.AreEqual("63", changes.Address3);
            Assert.AreEqual("64", changes.Address4);
            Assert.AreEqual("65", changes.Address5);
            Assert.AreEqual("66", changes.Address6);
            Assert.AreEqual("67", changes.Address7);
            Assert.AreEqual("68", changes.Address8);
            Assert.AreEqual("69", changes.Address9);
            Assert.AreEqual("70", changes.Address10);
            Assert.AreEqual("71", changes.Address11);
            Assert.AreEqual("72", changes.Address12);

            #region [ Changes.Components ]

            var ccomponents = changes.Components;
            Assert.IsNotNull(ccomponents);
            Assert.AreEqual("73", ccomponents.SuperAdministrativeArea);
            Assert.AreEqual("74", ccomponents.AdministrativeArea);
            Assert.AreEqual("75", ccomponents.SubAdministrativeArea);
            Assert.AreEqual("76", ccomponents.Building);
            Assert.AreEqual("77", ccomponents.DependentLocality);
            Assert.AreEqual("78", ccomponents.DependentLocalityName);
            Assert.AreEqual("79", ccomponents.DoubleDependentLocality);
            Assert.AreEqual("80", ccomponents.CountryIso3);
            Assert.AreEqual("81", ccomponents.Locality);
            Assert.AreEqual("82", ccomponents.PostalCode);
            Assert.AreEqual("83", ccomponents.PostalCodeShort);
            Assert.AreEqual("84", ccomponents.PostalCodeExtra);
            Assert.AreEqual("85", ccomponents.Premise);
            Assert.AreEqual("86", ccomponents.PremiseExtra);
            Assert.AreEqual("87", ccomponents.PremiseNumber);
            Assert.AreEqual("88", ccomponents.PremiseType);
            Assert.AreEqual("89", ccomponents.PremiseNumberPrefix);
            Assert.AreEqual("90", ccomponents.Thoroughfare);
            Assert.AreEqual("91", ccomponents.ThoroughfarePredirection);
            Assert.AreEqual("92", ccomponents.ThoroughfarePostdirection);
            Assert.AreEqual("93", ccomponents.ThoroughfareName);
            Assert.AreEqual("94", ccomponents.ThoroughfareTrailingType);
            Assert.AreEqual("95", ccomponents.ThoroughfareType);
            Assert.AreEqual("96", ccomponents.DependentThoroughfare);
            Assert.AreEqual("97", ccomponents.DependentThoroughfarePredirection);
            Assert.AreEqual("98", ccomponents.DependentThoroughfarePostdirection);
            Assert.AreEqual("99", ccomponents.DependentThoroughfareName);
            Assert.AreEqual("100", ccomponents.DependentThoroughfareTrailingType);
            Assert.AreEqual("101", ccomponents.DependentThoroughfareType);
            Assert.AreEqual("102", ccomponents.BuildingLeadingType);
            Assert.AreEqual("103", ccomponents.BuildingName);
            Assert.AreEqual("104", ccomponents.BuildingTrailingType);
            Assert.AreEqual("105", ccomponents.SubBuildingType);
            Assert.AreEqual("106", ccomponents.SubBuildingNumber);
            Assert.AreEqual("107", ccomponents.SubBuildingName);
            Assert.AreEqual("108", ccomponents.SubBuilding);
            Assert.AreEqual("109", ccomponents.PostBox);
            Assert.AreEqual("110", ccomponents.PostBoxType);
            Assert.AreEqual("111", ccomponents.PostBoxNumber);

            #endregion

            #endregion

            #endregion
        }
        public void TestFullJSONDeserialization()
        {
            var nativeserializer = new NativeSerializer();
            var RawJSON          = @"[
            {
                ""input_id"": ""blah"",
                ""input_index"": 0,
                ""candidate_index"": 4242,
                ""addressee"": ""John Smith"",
                ""delivery_line_1"": ""3214 N University Ave # 409"",
                ""delivery_line_2"": ""blah blah"",
                ""last_line"": ""Provo UT 84604-4405"",
                ""delivery_point_barcode"": ""846044405140"",
                ""components"": {
                    ""primary_number"": ""3214"",
                    ""street_predirection"": ""N"",
                    ""street_postdirection"": ""Q"",
                    ""street_name"": ""University"",
                    ""street_suffix"": ""Ave"",
                    ""secondary_number"": ""409"",
                    ""secondary_designator"": ""#"",
                    ""extra_secondary_number"": ""410"",
                    ""extra_secondary_designator"": ""Apt"",
                    ""pmb_number"": ""411"",
                    ""pmb_designator"": ""Box"",
                    ""city_name"": ""Provo"",
                    ""default_city_name"": ""Provo"",
                    ""state_abbreviation"": ""UT"",
                    ""zipcode"": ""84604"",
                    ""plus4_code"": ""4405"",
                    ""delivery_point"": ""14"",
                    ""delivery_point_check_digit"": ""0"",
                    ""urbanization"": ""urbanization""
                },
                ""metadata"": {
                    ""record_type"": ""S"",
                    ""zip_type"": ""Standard"",
                    ""county_fips"": ""49049"",
                    ""county_name"": ""Utah"",
                    ""carrier_route"": ""C016"",
                    ""congressional_district"": ""03"",
                    ""building_default_indicator"": ""hi"",
                    ""rdi"": ""Commercial"",
                    ""elot_sequence"": ""0016"",
                    ""elot_sort"": ""A"",
                    ""latitude"": 40.27658,
                    ""longitude"": -111.65759,
                    ""precision"": ""Zip9"",
                    ""time_zone"": ""Mountain"",
                    ""utc_offset"": -7,
                    ""dst"": true,
                    ""ews_match"": true
                },
                ""analysis"": {
                    ""dpv_match_code"": ""S"",
                    ""dpv_footnotes"": ""AACCRR"",
                    ""dpv_cmra"": ""Y"",
                    ""dpv_vacant"": ""N"",
                    ""active"": ""Y"",
                    ""footnotes"": ""footnotes"",
                    ""lacslink_code"": ""lacslink_code"",
                    ""lacslink_indicator"": ""lacslink_indicator"",
                    ""suitelink_match"": true
                }
            }
            ]";

            var Bytes  = Encoding.ASCII.GetBytes(RawJSON);
            var Stream = new MemoryStream(Bytes);

            var actual     = nativeserializer.Deserialize <List <Candidate> >(Stream);
            var components = actual[0].Components;
            var metadata   = actual[0].Metadata;
            var analysis   = actual[0].Analysis;

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(0, actual[0].InputIndex);
            Assert.AreEqual(4242, actual[0].CandidateIndex);
            Assert.AreEqual("John Smith", actual[0].Addressee);
            Assert.AreEqual("3214 N University Ave # 409", actual[0].DeliveryLine1);
            Assert.AreEqual("blah blah", actual[0].DeliveryLine2);
            Assert.AreEqual("Provo UT 84604-4405", actual[0].LastLine);
            Assert.AreEqual("846044405140", actual[0].DeliveryPointBarcode);
            Assert.AreEqual("3214", components.PrimaryNumber);
            Assert.AreEqual("N", components.StreetPredirection);
            Assert.AreEqual("Q", components.StreetPostdirection);
            Assert.AreEqual("University", components.StreetName);
            Assert.AreEqual("Ave", components.StreetSuffix);
            Assert.AreEqual("409", components.SecondaryNumber);
            Assert.AreEqual("#", components.SecondaryDesignator);
            Assert.AreEqual("410", components.ExtraSecondaryNumber);
            Assert.AreEqual("Apt", components.ExtraSecondaryDesignator);
            Assert.AreEqual("411", components.PmbNumber);
            Assert.AreEqual("Box", components.PmbDesignator);
            Assert.AreEqual("Provo", components.CityName);
            Assert.AreEqual("Provo", components.DefaultCityName);
            Assert.AreEqual("UT", components.State);
            Assert.AreEqual("84604", components.ZipCode);
            Assert.AreEqual("4405", components.Plus4Code);
            Assert.AreEqual("14", components.DeliveryPoint);
            Assert.AreEqual("0", components.DeliveryPointCheckDigit);
            Assert.AreEqual("urbanization", components.Urbanization);
            Assert.AreEqual("S", metadata.RecordType);
            Assert.AreEqual("Standard", metadata.ZipType);
            Assert.AreEqual("49049", metadata.CountyFips);
            Assert.AreEqual("Utah", metadata.CountyName);
            Assert.AreEqual("C016", metadata.CarrierRoute);
            Assert.AreEqual("03", metadata.CongressionalDistrict);
            Assert.AreEqual("hi", metadata.BuildingDefaultIndicator);
            Assert.AreEqual("Commercial", metadata.Rdi);
            Assert.AreEqual("0016", metadata.ElotSequence);
            Assert.AreEqual("A", metadata.ElotSort);
            Assert.AreEqual(40.27658, metadata.Latitude);
            Assert.AreEqual(-111.65759, metadata.Longitude);
            Assert.AreEqual("Zip9", metadata.Precision);
            Assert.AreEqual("Mountain", metadata.TimeZone);
            Assert.AreEqual(-7, metadata.UtcOffset);
            Assert.AreEqual(true, metadata.ObeysDst);
            Assert.AreEqual(true, metadata.IsEwsMatch);
            Assert.AreEqual("S", analysis.DpvMatchCode);
            Assert.AreEqual("AACCRR", analysis.DpvFootnotes);
            Assert.AreEqual("Y", analysis.Cmra);
            Assert.AreEqual("N", analysis.Vacant);
            Assert.AreEqual("Y", analysis.Active);
            Assert.AreEqual("footnotes", analysis.Footnotes);
            Assert.AreEqual("lacslink_code", analysis.LacsLinkCode);
            Assert.AreEqual("lacslink_indicator", analysis.LacsLinkIndicator);
            Assert.AreEqual(true, analysis.IsSuiteLinkMatch);
            //TODO: Finish writing tests
        }