public async Task DeleteNotExistingClub()
        {
            var stadiumsList = new List <Stadium>
            {
                new Stadium {
                    Id = 1, Name = "Old Trafford", Capacity = 76000
                }
            };
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "England", Code = "EN"
                }
            };
            var clubsList = new List <Club>();

            var mockStadiumRepo = new Mock <IRepository <Stadium> >();
            var mockCountryRepo = new Mock <IRepository <Country> >();
            var mockClubRepo    = new Mock <IRepository <Club> >();

            mockClubRepo.Setup(r => r.All()).Returns(clubsList.AsQueryable());

            var clubService = new ClubService(mockClubRepo.Object, mockCountryRepo.Object, mockStadiumRepo.Object);

            await Assert.ThrowsAsync <Exception>(() => clubService.DeleteAsync(1));
        }
        public async Task DeleteAsync_WhenCalled_DeleteSeasonFromDb()
        {
            var club = new Club
            {
                Id = 1
            };

            await _clubService.DeleteAsync(club);

            _clubRepository.Verify(c => c.Remove(club), Times.Once);
            _unitOfWork.Verify(u => u.CompleteAsync(), Times.Once);
        }
        public async Task SaveAndDeleteClub()
        {
            var stadiumsList = new List <Stadium>
            {
                new Stadium {
                    Id = 1, Name = "Old Trafford", Capacity = 76000
                }
            };
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "England", Code = "EN"
                }
            };
            var clubsList = new List <Club>();

            var mockStadiumRepo = new Mock <IRepository <Stadium> >();

            mockStadiumRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => stadiumsList.FirstOrDefault(c => c.Id == id));

            var mockCountryRepo = new Mock <IRepository <Country> >();

            mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id));

            var mockClubRepo = new Mock <IRepository <Club> >();

            mockClubRepo.Setup(r => r.All()).Returns(clubsList.AsQueryable());
            mockClubRepo.Setup(r => r.AddAsync(It.IsAny <Club>())).Callback <Club>(club => clubsList.Add(new Club
            {
                Id          = 1,
                Name        = club.Name,
                Country     = club.Country,
                HomeStadium = club.HomeStadium
            }));
            mockClubRepo.Setup(r => r.Delete(It.IsAny <Club>())).Callback <Club>(club => clubsList.Remove(club));

            var clubService = new ClubService(mockClubRepo.Object, mockCountryRepo.Object, mockStadiumRepo.Object);

            var clubViewModel = new ClubViewModel
            {
                Name          = "Manchester United",
                CountryId     = 1,
                HomeStadiumId = 1
            };

            await clubService.CreateAsync(clubViewModel);

            await clubService.DeleteAsync(1);

            Assert.Empty(clubService.GetAll(false));
        }