Ejemplo n.º 1
0
        public async Task ValidateSearchByFullAddressAsync()
        {
            var fixtureResults = ResultsFixture.GetSampleResults();
            var clientMock     = new Mock <IViaCepClient>();

            clientMock
            .Setup(c => c.SearchAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(fixtureResults);

            var results = await clientMock.Object.SearchAsync(fixtureResults.First().StateInitials, fixtureResults.First().City, fixtureResults.First().Street, CancellationToken.None);

            Assert.NotNull(results);

            var list = results.ToList();

            Assert.True(list.Any());
            Assert.Contains(list, r => r.ZipCode.Equals("12345-678", StringComparison.InvariantCultureIgnoreCase));
            Assert.Contains(list, r => r.ZipCode.Equals("98765-432", StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 2
0
        public async Task ValidateSearchByZipCodeWithoutGiaCodeAsync()
        {
            var fixtureResults = ResultsFixture.GetSampleResults();
            var clientMock     = new Mock <IViaCepClient>();

            clientMock
            .Setup(c => c.SearchAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(fixtureResults.First(r => !r.GIACode.HasValue));

            var result = await clientMock.Object.SearchAsync("12345678", CancellationToken.None);

            Assert.NotNull(result);
            Assert.Equal("", result.Unit);
            Assert.Equal("Rua Direita", result.Street);
            Assert.Equal(string.Empty, result.Complement);
            Assert.Null(result.GIACode);
            Assert.Equal(1, result.IBGECode);
            Assert.Equal("Centro", result.Neighborhood);
            Assert.Equal("São Paulo", result.City);
            Assert.Equal("SP", result.StateInitials);
        }
Ejemplo n.º 3
0
        public void ValidateSearchByZipCode()
        {
            var fixtureResults = ResultsFixture.GetSampleResults();
            var clientMock     = new Mock <IViaCepClient>();

            clientMock
            .Setup(c => c.Search(It.IsAny <string>()))
            .Returns(fixtureResults.First(r => r.ZipCode.Equals("12345-678")));

            var result = clientMock.Object.Search("12345678");

            Assert.NotNull(result);
            Assert.Equal("Any", result.Unit);
            Assert.Equal("Rua Direita", result.Street);
            Assert.Equal(string.Empty, result.Complement);
            Assert.Equal(1, result.GIACode);
            Assert.Equal(1, result.IBGECode);
            Assert.Equal("Centro", result.Neighborhood);
            Assert.Equal("São Paulo", result.City);
            Assert.Equal("SP", result.StateInitials);
        }