public void RetrieveFailureASeasonInTheRepo() { List <Season> seasons = CreateSeasonList(); Season season = new Season(); season.Id = 1; var mock = new Mock <ISeasonRepository>(MockBehavior.Strict); // Filling mock with data mock.As <ICRUDRepository <Season, int, SeasonFilter> >().Setup(m => m.Get(It.IsAny <int>())) .Returns <int>(id => Task.FromResult((Season)null)); var mockLeagueRepo = new Mock <ILeagueRepository>(MockBehavior.Strict); // Creating the controller which we want to create SeasonViewController controller = new SeasonViewController(mock.Object, mockLeagueRepo.Object); // configuring the context for the controler fakeContext(controller); HttpResponseMessage response = controller.Get(1).Result; Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound); }
public void RetrieveASeasonViewInTheRepo() { List <Season> seasons = CreateSeasonList(); List <SeasonViewModel> seasonView = CreateSeasonViewListFromSeasonList(seasons); var mock = new Mock <ISeasonRepository>(MockBehavior.Strict); // Filling mock with data mock.As <ICRUDRepository <Season, int, SeasonFilter> >().Setup(m => m.Get(It.IsAny <int>())) .Returns <int>(id => Task.FromResult(seasons.FirstOrDefault(s => s.Id == id))); var mockLeagueRepo = new Mock <ILeagueRepository>(MockBehavior.Strict); mockLeagueRepo.As <ILeagueRepository>().Setup(m => m.GetAllWithFilter(It.IsAny <LeagueFilter>())) .Returns <LeagueFilter>(l => Task.FromResult((IEnumerable <League>)seasons.FirstOrDefault(s => s.Id == l.SeasonId).Leagues)); // We get the leagues from the league list mockLeagueRepo.As <ILeagueRepository>().Setup(m => m.GetViewModel(It.IsAny <int>())) .Returns <int>(id => Task.FromResult(seasonView[0].LeagueViewModels.FirstOrDefault(l => l.Id == id))); // Creating the controller which we want to create SeasonViewController controller = new SeasonViewController(mock.Object, mockLeagueRepo.Object); // configuring the context for the controler fakeContext(controller); HttpResponseMessage response = controller.Get(1).Result; Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); var objectContent = response.Content as ObjectContent; // we should retrieve the season view 0 Assert.AreEqual(seasonView[0].Name, ((SeasonViewModel)objectContent.Value).Name); Assert.AreEqual(seasonView[0].LeagueViewModels.Count(), ((SeasonViewModel)objectContent.Value).LeagueViewModels.Count()); }