Exemplo n.º 1
0
        public async Task Returns_Ok_Given_ExistingCode()
        {
            // Arrange
            const string code    = "Existing Code";
            var          country = Mocked.Country(code);

            _countryRepositoryMock
            .Setup(x => x.SearchByCodeAsync(code))
            .Returns(Task.FromResult <Country>(country));

            // Act
            var response = await Client.GetAsync($"/country/{code}");

            // Assert
            response.StatusCode.Should().Be(StatusCodes.Status200OK);

            var responseString = await response.Content.ReadAsStringAsync();

            var responseObject = JsonConvert.DeserializeObject <VmCountryDetails>(responseString);

            responseObject.Flag.Should().Be(country.Flag);
            responseObject.Region.Should().Be(country.Region);
            responseObject.Name.Should().Be(country.Name);
            responseObject.Population.Should().Be(country.Population);
            responseObject.Alpha3Code.Should().Be(country.Alpha3Code);
            responseObject.CapitalCity.Should().Be(country.Capital);
            responseObject.Languages.Should().BeEquivalentTo(country.Languages);
            responseObject.Currencies.Should().BeEquivalentTo(country.Currencies);
            responseObject.Timezones.Should().BeEquivalentTo(country.Timezones);
            responseObject.BorderingCountries.Should().BeEquivalentTo(country.Borders);
        }
Exemplo n.º 2
0
        public async Task Returns_OkResult()
        {
            // Arrange
            const string code = "Country code";

            var country = Mocked.Country(code);

            GetMock <ICountryDetailsService>()
            .Setup(x => x.Get(code))
            .Returns(Task.FromResult(country));

            // Act
            var result = await ClassUnderTest.Details(code);

            // Assert
            var okResult    = Assert.IsType <OkObjectResult>(result.Result);
            var returnValue = Assert.IsType <VmCountryDetails>(okResult.Value);

            returnValue.Flag.Should().Be(country.Flag);
            returnValue.Region.Should().Be(country.Region);
            returnValue.Name.Should().Be(country.Name);
            returnValue.Population.Should().Be(country.Population);
            returnValue.Alpha3Code.Should().Be(country.Alpha3Code);
            returnValue.CapitalCity.Should().Be(country.Capital);
            returnValue.Languages.Should().BeEquivalentTo(country.Languages);
            returnValue.Currencies.Should().BeEquivalentTo(country.Currencies);
            returnValue.Timezones.Should().BeEquivalentTo(country.Timezones);
            returnValue.BorderingCountries.Should().BeEquivalentTo(country.Borders);
        }