57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
using Moq;
|
|
using Newtonsoft.Json;
|
|
using Landmark.OLA.Models.Addresses;
|
|
|
|
namespace Landmark.OLA.Integration.Tests
|
|
{
|
|
public class AddressValidationControllerTest : OlaIntegrationTest
|
|
{
|
|
public Address testResult;
|
|
|
|
public AddressValidationControllerTest() : base()
|
|
{
|
|
testResult = new Address()
|
|
{
|
|
Address1 = "111 South First Street",
|
|
City = "Milwaukee",
|
|
State = Models.Addresses.Enums.StateOption.WI,
|
|
PostalCode = "53207",
|
|
Country = Models.Addresses.Enums.CountryOption.UnitedStates
|
|
};
|
|
mockUspsVendorClient.Setup(repo => repo.CompareAddress(It.IsAny<Address>()))
|
|
.Returns(Task.FromResult(testResult));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanValidateAddress()
|
|
{
|
|
// Arrange
|
|
var requestAddress = new Address
|
|
{
|
|
Address1 = "111 South First Street",
|
|
City = "Milwaukee",
|
|
State = Models.Addresses.Enums.StateOption.WI,
|
|
PostalCode = "53207",
|
|
Country = Models.Addresses.Enums.CountryOption.UnitedStates
|
|
};
|
|
|
|
// Act
|
|
var request = new StringContent(JsonConvert.SerializeObject(requestAddress), Encoding.UTF8,
|
|
"application/json");
|
|
var httpResponse = await _client.PostAsync("/api/AddressValidation/", request);
|
|
|
|
// Must be successful.
|
|
httpResponse.EnsureSuccessStatusCode();
|
|
|
|
// Deserialize and examine results.
|
|
var stringResponse = await httpResponse.Content.ReadAsStringAsync();
|
|
var resultAddress = JsonConvert.DeserializeObject<Address>(stringResponse);
|
|
Assert.NotNull(resultAddress.Address1);
|
|
Assert.Equal(testResult.Address1, resultAddress.Address1);
|
|
}
|
|
}
|
|
} |