public async Task DeleteNotExistingManager()
        {
            var clubsList = new List <Club>
            {
                new Club {
                    Id = 1, Name = "Real Madrid"
                }
            };
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "Spain", Code = "SP"
                }
            };
            var managersList = new List <Manager>();

            var mockClubRepo    = new Mock <IRepository <Club> >();
            var mockCountryRepo = new Mock <IRepository <Country> >();
            var mockManagerRepo = new Mock <IRepository <Manager> >();

            mockManagerRepo.Setup(r => r.All()).Returns(managersList.AsQueryable());

            var managerService = new ManagerService(mockManagerRepo.Object, mockCountryRepo.Object, mockClubRepo.Object);

            await Assert.ThrowsAsync <Exception>(() => managerService.DeleteAsync(1));
        }
        public async Task DeleteAsync_WhenCalled_DeleteManagerFromDb()
        {
            var manager = new Manager
            {
                Id = 1
            };

            await _managerService.DeleteAsync(manager);

            _managerRepository.Verify(m => m.Remove(manager), Times.Once);
            _unitOfWork.Verify(u => u.CompleteAsync(), Times.Once);
        }
        public async Task SaveAndDeleteManager()
        {
            var clubsList = new List <Club>
            {
                new Club {
                    Id = 1, Name = "Real Madrid"
                }
            };
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "Spain", Code = "SP"
                }
            };
            var managersList = new List <Manager>();

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

            mockClubRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => clubsList.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 mockManagerRepo = new Mock <IRepository <Manager> >();

            mockManagerRepo.Setup(r => r.All()).Returns(managersList.AsQueryable());
            mockManagerRepo.Setup(r => r.AddAsync(It.IsAny <Manager>())).Callback <Manager>(manager => managersList.Add(new Manager
            {
                Id      = 1,
                Name    = manager.Name,
                Country = manager.Country,
                Club    = manager.Club
            }));
            mockManagerRepo.Setup(r => r.Delete(It.IsAny <Manager>())).Callback <Manager>(manager => managersList.Remove(manager));

            var managerService = new ManagerService(mockManagerRepo.Object, mockCountryRepo.Object, mockClubRepo.Object);

            var managerViewModel = new ManagerViewModel
            {
                Name      = "Zinedin Zidan",
                CountryId = 1,
                ClubId    = 1
            };

            await managerService.CreateAsync(managerViewModel);

            await managerService.DeleteAsync(1);

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