示例#1
0
        public async Task When_GetCountryPhoneCodesAsync_Called_Expect_FilteredAndOrderedResult()
        {
            //Arrange
            var dbResult = new List <CountryPhoneCode>
            {
                new CountryPhoneCode
                {
                    Id          = 1,
                    Order       = 1,
                    IsAvailable = true,
                    Code        = "en",
                    CountryName = "England",
                    IsoCode     = "iso"
                },
                new CountryPhoneCode
                {
                    Id          = 2,
                    Order       = 2,
                    IsAvailable = false,
                    Code        = "gb",
                    CountryName = "Albion",
                    IsoCode     = "iso2"
                },
                new CountryPhoneCode
                {
                    Id          = 3,
                    Order       = 3,
                    IsAvailable = true,
                    Code        = "bg",
                    CountryName = "Bulgaria",
                    IsoCode     = "iso3"
                },
            };

            _countryPhoneCodeRepositoryMock.Setup(x => x.GetAllAsync())
            .ReturnsAsync(dbResult);

            //Act
            var response = await _service.GetCountryPhoneCodesAsync();

            //Assert
            var expectedResult = dbResult
                                 .Where(o => o.IsAvailable)
                                 .OrderBy(o => o.Order)
                                 .ToList();

            _countryPhoneCodeRepositoryMock.Verify(x => x.GetAllAsync(), Times.Once);
            Assert.Equal(expectedResult.Count, response.Count);
            Assert.Equal(expectedResult[0].Order, response[0].Order);
        }