コード例 #1
0
        public async Task Handle_CountryLoaded_MapsToViewModel()
        {
            // Arrange
            var query = new CountryQuery
            {
                Iso2Code = "br"
            };

            var country = new Models.WorldBank.Country
            {
                Iso2Code    = "br",
                CapitalCity = "capital city",
                Name        = "My city",
                Longitude   = 34.4545d,
                Latitude    = -3.5658787d,
                AdminRegion = "Admin region"
            };

            var expectedCountryViewModel = new CountryViewModel
            {
                Iso2Code    = country.Iso2Code,
                CapitalCity = country.CapitalCity,
                AdminRegion = country.AdminRegion,
                Longitude   = country.Longitude,
                Latitude    = country.Latitude,
                Name        = country.Name
            };


            var worldBankDataServiceMock = new Mock <IWorldBankDataService>();

            worldBankDataServiceMock.Setup(x => x.LoadCountry(query.Iso2Code)).ReturnsAsync(country);

            var handler = new CountryHandler(worldBankDataServiceMock.Object);

            // Act
            var actualCountryViewModel = await handler.Handle(query);

            // Assert
            Assert.IsTrue(expectedCountryViewModel.IsDeepEqual(actualCountryViewModel));
        }