Пример #1
0
    public async Task <int> RunAsync()
    {
        _logger.LogInformation("Main executed");

        // use this token for stopping the services
        _applicationLifetime.ApplicationStopping.ThrowIfCancellationRequested();

        // var address2 = new ValidateAddress(
        //                Guid.NewGuid().ToString(),
        //                new Shipping.Abstractions.Address(
        //                "One Microsoft Way",
        //                "",
        //                "Redmond",
        //                "Washington",
        //                "98052",
        //                "US",
        //                false));

        // var address2 = new ValidateAddress(
        //            Guid.NewGuid().ToString(),
        //            new Shipping.Abstractions.Address(
        //            "Mauerberger  Building",
        //            "2nd floor",
        //            "Technion City",
        //            "Haifa",
        //            "3200003",
        //            "IL",
        //            false));

        // var address2 = new ValidateAddress(
        //        Guid.NewGuid().ToString(),
        //        new Shipping.Abstractions.Address(
        //        "100 East Capitol Street",
        //        "Suite 1000",
        //        "Jackson",
        //        "MS",
        //        "39201",
        //        "US",
        //        false));
        var address2 = new ValidateAddress(
            Guid.NewGuid().ToString(),
            new Shipping.Abstractions.Address(
                "1500 S STRONG DR",
                "Apartment, suite, unit, etc. (optional)",
                "BLOOMINGTON",
                "IL",
                "47403-8741",
                "US",
                false));

        var result2 = await _validationClient.ValidateAddressAsync(address2);

        result2.ValidationBag.TryGetValue("State", out var v);
        _logger.LogInformation("{isVerified}", v);

        return(await Task.FromResult(0));
    }
    public async Task NORMALIZED_Unknown_Address_Successfully()
    {
        var request = new ValidateAddress(
            Guid.NewGuid().ToString(),
            new EasyKeys.Shipping.Abstractions.Address(
                "ATTN John Smith 1800 ISLE PKWY",
                string.Empty,
                "BETTENDORF",
                "IA",
                "52722",
                "US",
                false));

        var result = await _validator.ValidateAddressAsync(request);

        var proposed = result.ProposedAddress;

        Assert.NotNull(proposed);
        Assert.Equal(string.Empty, proposed?.StreetLine);
        Assert.Equal(string.Empty, proposed?.StreetLine2);
        Assert.Equal("52722", proposed?.PostalCode);

        // BUSINESS, RESIDENTIAL
        // MIXED (If it is a multi-tenant based address and contains both business and residential units.)
        // UNKNOWN (If just a zip code is provided, Address Validation Service returns 'unknown' for the business/residential classification)
        Assert.Equal("UNKNOWN", result.ValidationBag.GetValueOrDefault("Classification"));

        // If the address returned includes the address state of "Standardized" and also if the attributes of Resolved = True,
        // DPV = True are present, then the address is likely a valid one.
        Assert.Equal("NORMALIZED", result.ValidationBag.GetValueOrDefault("State"));
        Assert.False(Convert.ToBoolean(result.ValidationBag.GetValueOrDefault("Resolved")));
        Assert.False(Convert.ToBoolean(result.ValidationBag.GetValueOrDefault("DPV")));
    }