public async Task DeleteNotExistingTeamPosition() { var clubsList = new List <Club> { new Club { Id = 1, Name = "Manchester United" } }; var seasonsList = new List <Season> { new Season { Id = 1, Name = "2020/21" } }; var teamPositionsList = new List <TeamPosition>(); var mockClubRepo = new Mock <IRepository <Club> >(); var mockSeasonRepo = new Mock <IRepository <Season> >(); var mockTeamPositionRepo = new Mock <IRepository <TeamPosition> >(); mockTeamPositionRepo.Setup(r => r.All()).Returns(teamPositionsList.AsQueryable()); var teamPositionService = new TeamPositionService(mockTeamPositionRepo.Object, mockSeasonRepo.Object, mockClubRepo.Object); await Assert.ThrowsAsync <Exception>(() => teamPositionService.DeleteAsync(1)); }
public async Task SaveAndDeleteTeamPosition() { var clubsList = new List <Club> { new Club { Id = 1, Name = "Manchester United" } }; var seasonsList = new List <Season> { new Season { Id = 1, Name = "2020/21" } }; var teamPositionsList = new List <TeamPosition>(); var mockClubRepo = new Mock <IRepository <Club> >(); mockClubRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => clubsList.FirstOrDefault(c => c.Id == id)); var mockSeasonRepo = new Mock <IRepository <Season> >(); mockSeasonRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => seasonsList.FirstOrDefault(c => c.Id == id)); var mockTeamPositionRepo = new Mock <IRepository <TeamPosition> >(); mockTeamPositionRepo.Setup(r => r.All()).Returns(teamPositionsList.AsQueryable()); mockTeamPositionRepo.Setup(r => r.AddAsync(It.IsAny <TeamPosition>())).Callback <TeamPosition>(teamPosition => teamPositionsList.Add(new TeamPosition { Id = 1, Season = teamPosition.Season, Club = teamPosition.Club })); mockTeamPositionRepo.Setup(r => r.Delete(It.IsAny <TeamPosition>())).Callback <TeamPosition>(teamPosition => teamPositionsList.Remove(teamPosition)); var teamPositionService = new TeamPositionService(mockTeamPositionRepo.Object, mockSeasonRepo.Object, mockClubRepo.Object); var teamPositionViewModel = new TeamPositionViewModel { SeasonId = 1, ClubId = 1 }; await teamPositionService.CreateAsync(teamPositionViewModel); await teamPositionService.DeleteAsync(1); Assert.Empty(teamPositionService.GetAll(false)); }