public async void Given_CountriesExist_When_GetCountries_Then_ReturnOrderedList()
        {
            // Arrange
            var countries = new List <Country> {
                new Country {
                    Name = "Mexico"
                },
                new Country {
                    Name = "England"
                },
                new Country {
                    Name = "Spain"
                }
            };
            var contextMock = MockDbContext(countries.AsQueryable());
            var handler     = new GetCountriesQueryHandler(contextMock.Object);

            //Act
            var result = await handler.Handle(new GetCountriesQuery(), CancellationToken.None);

            //Assert
            var orderedList = countries
                              .OrderBy(t => t.Name)
                              .Select(t => new CountryDto {
                Name = t.Name
            });

            result.Count().Should().Be(3);
            result.SequenceEqual(orderedList);
        }
        public async void Given_NoCountriesExist_When_GetCountriesIsCalled_Then_ReturnEmptyList()
        {
            // Arrange
            var countries   = new List <Country>();
            var contextMock = MockDbContext(countries.AsQueryable());
            var handler     = new GetCountriesQueryHandler(contextMock.Object);

            //Act
            var result = await handler.Handle(new GetCountriesQuery(), CancellationToken.None);

            //Assert
            result.Count().Should().Be(0);
        }
        public void Handle_NoCountriesExists_ThrowException(
            [Frozen] Mock <IRepository <Entities.CountryRegion> > countryRegionRepoMock,
            GetCountriesQueryHandler sut,
            GetCountriesQuery query
            )
        {
            //Arrange
            countryRegionRepoMock.Setup(x => x.ListAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync((List <Entities.CountryRegion>)null);

            //Act
            Func <Task> func = async() => await sut.Handle(query, CancellationToken.None);

            //Assert
            func.Should().ThrowAsync <ArgumentNullException>();
            countryRegionRepoMock.Verify(x => x.ListAsync(It.IsAny <CancellationToken>()));
        }
        public async Task Handle_CountriesExists_ReturnCountries(
            List <Entities.CountryRegion> countries,
            [Frozen] Mock <IRepository <Entities.CountryRegion> > countryRegionRepoMock,
            GetCountriesQueryHandler sut,
            GetCountriesQuery query
            )
        {
            //Arrange
            countryRegionRepoMock.Setup(x => x.ListAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(countries);

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            countryRegionRepoMock.Verify(x => x.ListAsync(It.IsAny <CancellationToken>()));

            for (int i = 0; i < result.Count; i++)
            {
                result[i].Name.Should().Be(countries[i].Name);
            }
        }