public void CheckIfLeagueAlreadyExists() { var europeanLeague = new League { Id = 1, Caption = "European Championships France 2016", Code = "EC", Year = "2016", FootballDataLeagueId = 424 }; var leagueOne = new League { Id = 2, Caption = "League One 2016/17", Code = "EL1", Year = "2016", FootballDataLeagueId = 428 }; // Create new league var leagues = new List <League> { europeanLeague, leagueOne }.AsQueryable(); try { // Setup League DbSet _mockLeagueSet.Setup(m => m.Find(It.IsAny <object[]>())).Returns <object[]>(id => leagues.FirstOrDefault(d => d.Id == (long)id[0])); // Setup Context _mockContext.Setup(m => m.Set <League>()).Returns(_mockLeagueSet.Object); _leagueService = new LeagueService(new GenericRepository <League>(_mockContext.Object)); // Get league from mock var mockLeague = _leagueService.Get(leagueOne.Id); // Check that league already exists Assert.IsNotNull(mockLeague); Assert.AreEqual(leagueOne.Id, mockLeague.Id); Assert.AreEqual(leagueOne.Caption, mockLeague.Caption); Assert.AreEqual(leagueOne.Code, mockLeague.Code); Assert.AreEqual(leagueOne.Year, mockLeague.Year); } catch (Exception ex) { Assert.Fail(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { _id = Convert.ToInt32(Request.QueryString["id"]); } if (!Page.IsPostBack) { league_user_panel.Visible = (_id > 0); league_tournament_panel.Visible = (_id > 0); if (_id > 0) { League league = LeagueService.Get(_id); name_textbox.Text = league.Name; tour_list.SelectedValue = league.TourId.ToString(); season_textbox.Text = league.Season.ToString(); } else { season_textbox.Text = DateTime.Now.Year.ToString(); } using (var db = new FantasyGolfContext()) { var tours = from x in db.Tour where x.IsActive == true orderby x.Name select x; tour_list.DataSource = tours.ToList(); tour_list.DataBind(); tour_list.Items.Insert(0, ""); tour_list.SelectedIndex = 0; } } }