Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
b498ec8616 | |||
c6e6b29905 | |||
854658f732 |
@ -7,5 +7,5 @@ public interface IAddress
|
||||
public string City { get; set; }
|
||||
public string Subdivision { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
public string CountryCode { get; set; }
|
||||
}
|
@ -11,8 +11,23 @@ public record Address(bool Normalized = false) : IAddress
|
||||
public required string City { get; set; }
|
||||
public required string Subdivision { get; set; }
|
||||
public required string PostalCode { get; set; }
|
||||
public required string Country { get; set; }
|
||||
public required string CountryCode { get; set; }
|
||||
public GeoPoint? Location { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public bool IsNormalized() => Normalized;
|
||||
|
||||
public static Address CreateFrom(IAddress address, GeoPoint? location = null, string? note = null, bool normalized = false)
|
||||
{
|
||||
return new Address(normalized)
|
||||
{
|
||||
Line1 = address.Line1,
|
||||
Line2 = address.Line2,
|
||||
City = address.City,
|
||||
Subdivision = address.Subdivision,
|
||||
PostalCode = address.PostalCode,
|
||||
CountryCode = address.CountryCode,
|
||||
Location = location,
|
||||
Note = note,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Svrnty.GeoManagement.Abstractions.Abstractions;
|
||||
using Svrnty.GeoManagement.Abstractions.Models;
|
||||
|
||||
@ -11,7 +13,7 @@ public static class ServiceCollectionExtensions
|
||||
toAddress.Line2 = address.Line2;
|
||||
toAddress.City = address.City;
|
||||
toAddress.PostalCode = address.PostalCode;
|
||||
toAddress.Country = address.Country;
|
||||
toAddress.CountryCode = address.CountryCode;
|
||||
toAddress.Subdivision = address.Subdivision;
|
||||
}
|
||||
|
||||
@ -21,7 +23,7 @@ public static class ServiceCollectionExtensions
|
||||
address.Line2 = fromAddress.Line2;
|
||||
address.City = fromAddress.City;
|
||||
address.PostalCode = fromAddress.PostalCode;
|
||||
address.Country = fromAddress.Country;
|
||||
address.CountryCode = fromAddress.CountryCode;
|
||||
address.Subdivision = fromAddress.Subdivision;
|
||||
}
|
||||
|
||||
@ -40,10 +42,10 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(address.Line2))
|
||||
{
|
||||
return $"{address.Line1}, {address.City}, {address.Subdivision} {address.PostalCode}, {address.Country}";
|
||||
return $"{address.Line1}, {address.City}, {address.Subdivision} {address.PostalCode}, {address.CountryCode}";
|
||||
}
|
||||
|
||||
return $"{address.Line2}, {address.Line1}, {address.City}, {address.Subdivision} {address.PostalCode}, {address.Country}";
|
||||
return $"{address.Line2}, {address.Line1}, {address.City}, {address.Subdivision} {address.PostalCode}, {address.CountryCode}";
|
||||
}
|
||||
|
||||
private static string FormatCompactOneLine(IAddress address)
|
||||
@ -60,9 +62,21 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(address.Line2))
|
||||
{
|
||||
return $"{address.Line1}\n{address.City}, {address.Subdivision} {address.PostalCode}\n{address.Country}";
|
||||
return $"{address.Line1}\n{address.City}, {address.Subdivision} {address.PostalCode}\n{address.CountryCode}";
|
||||
}
|
||||
|
||||
return $"{address.Line2}, {address.Line1}\n{address.City}, {address.Subdivision} {address.PostalCode}\n{address.Country}";
|
||||
return $"{address.Line2}, {address.Line1}\n{address.City}, {address.Subdivision} {address.PostalCode}\n{address.CountryCode}";
|
||||
}
|
||||
|
||||
public static string GetHash(this IAddress address)
|
||||
=> ComputeSha256Hex(address.GetFormattedAddress());
|
||||
|
||||
private static string ComputeSha256Hex(string input)
|
||||
{
|
||||
using SHA256 sha256 = SHA256.Create();
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(input);
|
||||
byte[] hash = sha256.ComputeHash(bytes);
|
||||
|
||||
return Convert.ToHexString(hash).ToLower();
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ internal static class GoogleAddressMapper
|
||||
City = city,
|
||||
Subdivision = subdivision,
|
||||
PostalCode = postalCode,
|
||||
Country = country,
|
||||
CountryCode = country,
|
||||
Location = location,
|
||||
Note = null
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ public class GoogleProviderTests : IDisposable
|
||||
City = _testData.ValidAddress.City,
|
||||
Subdivision = _testData.ValidAddress.Subdivision,
|
||||
PostalCode = _testData.ValidAddress.PostalCode,
|
||||
Country = _testData.ValidAddress.Country,
|
||||
CountryCode = _testData.ValidAddress.Country,
|
||||
Location = null,
|
||||
Note = null
|
||||
};
|
||||
@ -90,7 +90,7 @@ public class GoogleProviderTests : IDisposable
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.Line1);
|
||||
Assert.NotNull(result.City);
|
||||
Assert.NotNull(result.Country);
|
||||
Assert.NotNull(result.CountryCode);
|
||||
Assert.True(result.IsNormalized());
|
||||
Assert.NotNull(result.Location);
|
||||
}
|
||||
@ -106,7 +106,7 @@ public class GoogleProviderTests : IDisposable
|
||||
City = _testData.NormalizeTestAddress.City,
|
||||
Subdivision = _testData.NormalizeTestAddress.Subdivision,
|
||||
PostalCode = _testData.NormalizeTestAddress.PostalCode,
|
||||
Country = _testData.NormalizeTestAddress.Country,
|
||||
CountryCode = _testData.NormalizeTestAddress.Country,
|
||||
Location = null,
|
||||
Note = null
|
||||
};
|
||||
@ -150,7 +150,7 @@ public class GoogleProviderTests : IDisposable
|
||||
City = _testData.InvalidAddress.City,
|
||||
Subdivision = _testData.InvalidAddress.Subdivision,
|
||||
PostalCode = _testData.InvalidAddress.PostalCode,
|
||||
Country = _testData.InvalidAddress.Country,
|
||||
CountryCode = _testData.InvalidAddress.Country,
|
||||
Location = null,
|
||||
Note = null
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user