Beispiel #1
0
        public async Task FindAsync_Returns_Sorted_FoundByIsoCode()
        {
            var data = new List <Country>
            {
                new Country {
                    IsoCode = "CC", Name = "UUU"
                },
                new Country {
                    IsoCode = "BB", Name = "XXX"
                },
                new Country {
                    IsoCode = "DD", Name = "YYY"
                },
                new Country {
                    IsoCode = "AA", Name = "YYY"
                },
            };

            var mockSet     = new Mock <DbSet <Country> >().SetupData(data);
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Countries).Returns(mockSet.Object);

            var service = new CountryRepository(mockContext.Object);

            // Act
            var items = (await service.FindAsync(new string[] { "BB", "CC" })).ToList();

            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, 2);
            Assert.AreEqual(items[0].IsoCode, "BB");
            Assert.AreEqual(items[1].IsoCode, "CC");
        }
 /// <summary>
 /// Gets the <see cref="Country"/> by country ISO 3 code.
 /// </summary>
 /// <param name="countryIsoCode">Country code consisting of 3 letters.</param>
 /// <returns>Instance of <see cref="Country"/> or null if country does not exist.</returns>
 public async Task <Country> GetCountryByIsoCodeAsync(string countryIsoCode)
 {
     return((await CountryRepository.FindAsync(c => c.CountryIsoCode3 == countryIsoCode)).FirstOrDefault());
 }