public void ThrowInvalidOperationException_WhenLeagueForTheProvidedSeasonAlreadyExists() { // arrange var leaguesRepo = new Mock <IEfRepository <League> >(); var countriesRepo = new Mock <IEfRepository <Country> >(); var leagueService = new LeagueService(leaguesRepo.Object, countriesRepo.Object); var country = new Country() { Name = "someName" }; var league = new League() { Country = country, Season = 2017 }; countriesRepo.Setup(cr => cr.All).Returns(new List <Country>() { country }.AsQueryable()); leaguesRepo.Setup(l => l.All).Returns(new List <League>() { league }.AsQueryable()); // act & assert Assert.Throws <InvalidOperationException>(() => leagueService.Add(league)); }
public void ThrowArgumentNullException_WhenPassedLeagueNameIsNull() { // arrange var leaguesRepo = new Mock <IEfRepository <League> >(); var countriesRepo = new Mock <IEfRepository <Country> >(); var leagueService = new LeagueService(leaguesRepo.Object, countriesRepo.Object); var league = new League(); // act & assert Assert.Throws <ArgumentNullException>(() => leagueService.Add(league)); }
private void AddLeague_Click(object sender, RoutedEventArgs e) { var teamIds = Teams.Select(x => x.Id).ToList(); League = new League(LeagueName, teamIds); var newSerie = new CreateSeriesSchedule().GetFullSeries(Teams.ToList()); League.MatchWeeks = newSerie; MainPage.Leagues.Add(League); _leagueService.Add(League); new PersonService().Save(); new TeamService().Save(); NavigationService?.GoBack(); }
public void CallLeaguesRepoAddMethodWithValidLeagueObject_WhenLeaguePassedIsValidToBeAdded() { // arrange var leaguesRepo = new Mock <IEfRepository <League> >(); var countriesRepo = new Mock <IEfRepository <Country> >(); var leagueService = new LeagueService(leaguesRepo.Object, countriesRepo.Object); var country = new Country() { Name = "someName" }; var league = new League() { Country = country, Season = 2015, Name = "someName" }; countriesRepo.Setup(cr => cr.All).Returns(new List <Country>() { country }.AsQueryable()); var existingLeague = new League() { Name = "someName", Country = new Country() { Name = "someName" } }; leaguesRepo.Setup(l => l.All).Returns(new List <League>() { existingLeague }.AsQueryable()); leaguesRepo.Setup(lr => lr.Add(It.Is <League>(l => l.Country == country))); // act leagueService.Add(league); // assert leaguesRepo.Verify(lr => lr.Add(It.Is <League>(l => l.Country == country)), Times.Once); }
public void ThrowArgumentNullException_WhenTargetCountryIsNotFound() { // arrange var leaguesRepo = new Mock <IEfRepository <League> >(); var countriesRepo = new Mock <IEfRepository <Country> >(); var leagueService = new LeagueService(leaguesRepo.Object, countriesRepo.Object); var country = new Country() { Name = "someName" }; var league = new League() { Country = country }; countriesRepo.Setup(cr => cr.All).Returns(new List <Country>().AsQueryable()); // act & assert Assert.Throws <ArgumentNullException>(() => leagueService.Add(league)); }
public void ThrowInvalidOperationException_WhenTryingToAddExistingLeagueButWithDifferentCountry() { // arrange var leaguesRepo = new Mock <IEfRepository <League> >(); var countriesRepo = new Mock <IEfRepository <Country> >(); var leagueService = new LeagueService(leaguesRepo.Object, countriesRepo.Object); var country = new Country() { Name = "someName" }; var league = new League() { Country = country, Season = 2015, Name = "someName" }; countriesRepo.Setup(cr => cr.All).Returns(new List <Country>() { country }.AsQueryable()); var existingLeague = new League() { Name = "someName", Country = new Country() { Name = "OtherCountryName" } }; leaguesRepo.Setup(l => l.All).Returns(new List <League>() { existingLeague }.AsQueryable()); // act & assert Assert.Throws <InvalidOperationException>(() => leagueService.Add(league)); }