public void SetUp() { var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/player"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "player" } }); playerController = new PlayerController(); UrlHelper urlHelper = new UrlHelper(request); playerController.ControllerContext = new HttpControllerContext(config, routeData, request); playerController.Request = request; playerController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; playerController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData; playerController.Url = urlHelper; var response = teamController.Get(1); var contentResult = response as OkNegotiatedContentResult<DTOTeam>; DTOTeam DtoTeam = contentResult.Content; Team teamFromDb = new Team(); teamFromDb.Name = DtoTeam.Name; teamFromDb.Id = DtoTeam.Id; List<Team> teams = new List<Team>() { teamFromDb }; player = new Player() { Name = "Integration Test Player", Teams = teams }; }
public List<Team> FillTeams(Team homeTeam, Team awayTeam) { List<Team> teams = new List<Team>(); teams.Add(homeTeam); teams.Add(awayTeam); return teams; }
// POST: api/Team public HttpResponseMessage Post(Team team) { team = teamRepository.Create(team); var response = Request.CreateResponse<DTOTeam>(HttpStatusCode.Created, DtoTeamConverter.Convert(team)); //string uri = Url.Link("DefaultApi", new { id = team.Id }); //response.Headers.Location = new Uri(uri); return response; }
public Team Add(Team team) { const string sqlQuery = "INSERT INTO Team (Name) " + "VALUES (@Name) " + "SELECT Id FROM Team WHERE Id = scope_identity()"; var teamId = _dbConnection.QueryWithRetry<Team>(sqlQuery, new { team.Name}).Single(); team.Id = teamId.Id; return team; }
public Team Update(Team team) { const string sqlQuery = "UPDATE Team " + "SET Name = @Name " + "WHERE Id = @Id " + "SELECT * FROM Team " + "WHERE Id = @Id"; var newTeam = _dbConnection.QueryWithRetry<Team>(sqlQuery, team).Single(); return newTeam; }
public Team CreateTeam(Team team) { try { var newTeam = _teamRepository.Add(team); return newTeam; } catch (Exception e) { throw new Exception(e.Message); } }
public void Test_if_Team_can_be_converted_to_DTO_with_Players() { DTOTeam dtoTeam = new DTOTeam(); Team team = new Team() { Id = 1, Draw = 0, Loss = 0, Win = 1, Name = "Team Awesome", Players = new List<Player>() { new Player() { Id = 1, Name = "Ole" }, new Player() { Id = 2, Name = "Ulla" } }, }; DTOTeamConverter dtoTeamConverter = new DTOTeamConverter(); dtoTeam = dtoTeamConverter.Convert(team); Assert.AreEqual(team.Id, dtoTeam.Id); Assert.NotNull(dtoTeam.DtoPlayers); }
public void Test_if_Group_with_team_and_tournaments_can_be_converted_to_DTO() { Player player = new Player() { Id = 1, Name = "Søren" }; Player player2 = new Player() { Id = 2, Name = "Lars" }; Player player3 = new Player() { Id = 3, Name = "Peter" }; Player player4 = new Player() { Id = 4, Name = "Poul" }; List<Player> PlayersForTeam1 = new List<Player>() { player, player2 }; List<Player> PlayersForTeam2 = new List<Player>() { player3, player4 }; Team Team1 = new Team() { Id = 1, Name = "Awesome", Players = PlayersForTeam1 }; Team Team2 = new Team() { Id = 1, Name = "More Awesome", Players = PlayersForTeam2 }; Tournament tournament1 = new Tournament() { Id = 1, Name = "Warhammer", Game = new Game() { Id = 1, Name = "Wars", Genre = new Genre() { Id = 1, Name = "role" } }, StartDate = DateTime.Today, TournamentType = new TournamentType() { Id = 1, Type = "2vs2" } }; List<Team> teams = new List<Team> { Team1, Team2 }; Group group = new Group() { Id = 1, Name = "A", Teams = teams, Tournament = tournament1 }; DTOGroupConverter dtogroupConverter = new DTOGroupConverter(); DTOGroup dtoGroup = dtogroupConverter.Convert(group); Assert.IsNotNull(teams); Assert.AreEqual(dtoGroup.Id, 1); Assert.AreSame(Team1.Name, dtoGroup.DtoTeams[0].Name); Assert.Greater(dtoGroup.DtoTeams.Count, 0); Assert.AreEqual(dtoGroup.DtoTeams[0].Id, group.Teams[0].Id); Assert.AreEqual(dtoGroup.DtoTeams[1].Id, group.Teams[1].Id); Assert.AreEqual(dtoGroup.DtoTeams[0].Name, group.Teams[0].Name); Assert.AreEqual(dtoGroup.DtoTeams[1].Name, group.Teams[1].Name); Assert.AreEqual(dtoGroup.DtoTournament.Id, tournament1.Id); Assert.AreEqual(dtoGroup.DtoTournament.Name, tournament1.Name); Assert.AreEqual(dtoGroup.DtoTournament.StartDate, tournament1.StartDate); }
public void Test_if_three_teams_can_be_added_to_one_group() { int id = 1; string name = "Team One"; int win = 1; int loss = 2; int draw = 3; Team team = new Team() { Id = id, Name = name, Draw = draw, Loss = loss, Win = win }; Team team2 = new Team() { Id = id, Name = name, Draw = draw, Loss = loss, Win = win }; Team team3 = new Team() { Id = id, Name = name, Draw = draw, Loss = loss, Win = win }; group.Teams = new List<Team> { team, team2, team3 }; Assert.NotNull(group.Teams); Assert.Greater(group.Teams.Count, 0); Assert.AreEqual(team, group.Teams[0]); Assert.AreEqual(team2, group.Teams[1]); Assert.AreEqual(team3, group.Teams[2]); }
public void Test_if_Player_can_be_converted_to_DTO_with_teams() { List<Team> teams = new List<Team>(); Team team1 = new Team() { Id = 1, Name = "team one", Draw = 1, Loss = 2, Win = 2 }; Team team2 = new Team() { Id = 2, Name = "team two", Draw = 1, Loss = 2, Win = 2 }; teams.Add(team1); teams.Add(team2); Player player = new Player() { Id = 1, Name = "Ole", Teams = teams }; DTOPlayerConverter dtoPlayerConverter = new DTOPlayerConverter(); DTOPlayer dtoPlayer = dtoPlayerConverter.Convert(player); Assert.NotNull(teams); Assert.NotNull(dtoPlayer.DtoTeams); Assert.NotNull(dtoPlayer); Assert.AreEqual(dtoPlayer.Id, player.Id); Assert.Greater(dtoPlayer.DtoTeams.Count, 0); Assert.Greater(teams.Count, 0); Assert.LessOrEqual(dtoPlayer.DtoTeams.Count, 2); Assert.LessOrEqual(teams.Count, 2); }
public void Test_if_player_can_be_added_to_a_team() { int id = 1; string name = "Team One"; int win = 1; int loss = 2; int draw = 3; Team team = new Team() { Id = id, Name = name, Win = win, Loss = loss, Draw = draw, Players = new List<Player>() { player } }; Team team2 = new Team() { Id = 2, Name = name, Win = win, Loss = loss, Draw = draw, Players = new List<Player>() { player } }; player.Teams = new List<Team>() { team, team2 }; Assert.NotNull(player.Teams); Assert.Greater(player.Teams.Count, 0); Assert.NotNull(team.Players[0]); Assert.AreEqual(player, team.Players[0]); Assert.NotNull(team2.Players[0]); Assert.AreEqual(player, team2.Players[0]); }
public void Test_if_tournament_can_be_converted_with_groups_and_type_and_a_game() { DTOTournament dtoTournament = new DTOTournament(); TournamentType tournamentType = new TournamentType() { Id = 1, Type = "2vs2" }; Genre genre = new Genre() { Id = 1, Name = "wars"}; Player player1 = new Player() { Id = 1, Name = "Hans"}; Player player2 = new Player() {Id = 2, Name = "Ole"}; Player player3 = new Player() { Id = 3, Name = "Lars" }; Player player4 = new Player() { Id = 4, Name = "Peter" }; List<Player> players1 = new List<Player>() {player1, player2}; List<Player> players2 = new List<Player>() { player3, player4 }; Team team1 = new Team() {Id = 1, Name = "team1", Players = players1, Win = 2, Draw = 2, Loss = 1}; Team team2 = new Team() { Id = 1, Name = "team2", Players = players2, Win = 3, Draw = 0, Loss = 1 }; List<Team> teams1 = new List<Team>() {team1, team2}; Group group1 = new Group() { Id = 1, Name = "Hans og Ole", Teams = teams1}; Group group2 = new Group() { Id = 1, Name = "Lars og Peter", Teams = teams1}; List<Group> groups = new List<Group>() {group1, group2}; Game game = new Game() { Id = 1, Name = "Warhammer", Genre = genre}; Match match = new Match() {Id = 1, AwayTeam = team1, HomeTeam = team2, Round = "blabla"}; DTOTournamentConverter dtoTournamentConverter = new DTOTournamentConverter(); Tournament tournament = new Tournament() { Id = 1, Name = "Tournament One", StartDate = DateTime.Today, TournamentType = tournamentType, Groups = groups, Game = game, Matches = new List<Match>() { match} }; dtoTournament = dtoTournamentConverter.Convert(tournament); Assert.IsNotNull(tournament.TournamentType); Assert.AreEqual(tournament.Id, dtoTournament.Id); Assert.AreEqual(tournamentType.Id, dtoTournament.DTOTournamentType.Id); Assert.IsNotNull(groups); Assert.IsNotNull(dtoTournament.DtoGroups); Assert.AreEqual(groups.Count, dtoTournament.DtoGroups.Count); Assert.IsNotNull(dtoTournament.DtoGame); Assert.AreEqual(dtoTournament.DtoGame.Id, game.Id); }
public void SetUp() { var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/team"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "team" } }); teamController = new TeamController(); UrlHelper urlHelper = new UrlHelper(request); teamController.ControllerContext = new HttpControllerContext(config, routeData, request); teamController.Request = request; teamController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; teamController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData; teamController.Url = urlHelper; var response = playerController.Get(1); var contentResult = response as OkNegotiatedContentResult<DTOPlayer>; var groupResponse = groupController.Get(1); var groupContentResult = groupResponse as OkNegotiatedContentResult<DTOGroup>; DTOGroup DtoGroup = groupContentResult.Content; Group groupFromDb = new Group(); groupFromDb.Name = DtoGroup.Name; groupFromDb.Id = DtoGroup.Id; List<Group> groups = new List<Group>() { groupFromDb }; DTOPlayer Dtoplayer = contentResult.Content; playerFromDb = new Player(); playerFromDb.Name = Dtoplayer.Name; playerFromDb.Id = Dtoplayer.Id; List<Player> players = new List<Player>() {playerFromDb}; team = new Team() { Name = "Integration Test Team", Players = players, Groups = groups, Draw = 0, Win = 0, Loss = 0}; }
public void TearDown() { teamController = null; team = null; testList = null; }
// PUT: api/Team/5 public void Put(int id, Team team) { team.Id = id; if (!teamRepository.Update(team)) throw new HttpResponseException(HttpStatusCode.NotFound); }
public void Test_if_argument_exception_if_players_is_null() { DTOTeamConverter dtoTeamConverter = new DTOTeamConverter(); Team team = new Team() { Id = 1, Draw = 0, Loss = 0, Win = 1, Name = "Team Awesome" }; DTOTeam dtoTeam = dtoTeamConverter.Convert(team); }
public async void Test_if_a_team_can_be_added_to_a_player() { Player player1 = new Player() {Name = "TestPlayer1"}; Player player2 = new Player() {Name = "Testplayer2"}; WebApiService apiService = new WebApiService(); await playerController.Create(player1); await playerController.Create(player2); var players = await apiService.GetAsync<List<Player>>("api/player/"); var player1WithOutTeam = players.FirstOrDefault(a => a.Name == player1.Name); var player2WithOutTeam = players.FirstOrDefault(a => a.Name == player2.Name); List<Player> testList1 = new List<Player>() { player1WithOutTeam }; List<Player> testList2 = new List<Player>() { player2WithOutTeam }; Team teamOne = new Team() { Name = "TestTeam1", Draw = 0, Loss = 0, Win = 0, Players = testList1 }; Team teamTwo = new Team() { Name = "TestTeam2", Draw = 0, Loss = 0, Win = 0, Players = testList2 }; await apiService.PostAsync("api/team/", teamOne); await apiService.PostAsync("api/team/", teamTwo); var playerlist = await apiService.GetAsync<List<Player>>("api/player/"); var createdePlayer1 = playerlist.FirstOrDefault(a => a.Name == player1.Name); var createdePlayer2 = playerlist.FirstOrDefault(a => a.Name == player2.Name); Assert.IsNotNull(createdePlayer1); Assert.IsNotNull(createdePlayer2); int teamSizeBefore = createdePlayer1.Teams.Count; int teamId1ToRemove = createdePlayer1.Teams[0].Id; int teamId2ToRemove = createdePlayer2.Teams[0].Id; Team teamToAdd = await apiService.GetAsync<Team>("api/team/" + createdePlayer2.Teams[0].Id); await playerController.Add(teamToAdd.Id, createdePlayer1.Id); Player playerAfter = await apiService.GetAsync<Player>("api/player/" + createdePlayer1.Id); int teamSizeAfter = playerAfter.Teams.Count; Assert.AreNotEqual(teamSizeAfter, teamSizeBefore); await apiService.DeleteAsync<Team>("api/team/" + teamId1ToRemove); await apiService.DeleteAsync<Team>("api/team/" + teamId2ToRemove); await playerController.DeleteConfirmed(createdePlayer1.Id); await playerController.DeleteConfirmed(createdePlayer2.Id); }
public async void Test_if_a_team_can_be_removed_from_a_player() { WebApiService apiService = new WebApiService(); await playerController.Create(player); var players = await apiService.GetAsync<List<Player>>("api/player/"); var playerWithOutTeam = players.FirstOrDefault(a => a.Name == player.Name); List<Player> testList = new List<Player>() { playerWithOutTeam }; Team team = new Team() { Name = "TestTeam", Draw = 0, Loss = 0, Win = 0, Players = testList }; await apiService.PostAsync("api/team/", team); Assert.IsNotNull(player); Assert.IsNotNull(players); var playerlist = await apiService.GetAsync<List<Player>>("api/player/"); var createdePlayer = playerlist.FirstOrDefault(a => a.Name == player.Name); Assert.IsNotNull(createdePlayer); int teamSizeBefore = createdePlayer.Teams.Count; int teamIdToRemove = createdePlayer.Teams[0].Id; await playerController.Remove(createdePlayer.Teams[0].Id, createdePlayer.Id); Player playerAfter = await apiService.GetAsync<Player>("api/player/" + createdePlayer.Id); int teamSizeAfter = playerAfter.Teams.Count; Assert.AreNotEqual(teamSizeAfter, teamSizeBefore); await apiService.DeleteAsync<Team>("api/team/" + teamIdToRemove); await playerController.DeleteConfirmed(createdePlayer.Id); }
public void SetUp() { team = new Team() { Id = id, Name = name, Draw = draw, Loss = loss, Win = win }; }
public void Test_if_group_can_be_created_if_tournaments_is_null() { Team Team1 = new Team() { Id = 1, Name = "Awesome" }; Team Team2 = new Team() { Id = 1, Name = "More Awesome" }; List<Team> teams = new List<Team> { Team1, Team2 }; Group group = new Group() { Id = 1, Name = "A", Teams = teams }; DTOGroupConverter dtogroupConverter = new DTOGroupConverter(); DTOGroup dtoGroup = dtogroupConverter.Convert(group); Assert.IsNotNull(dtoGroup); Assert.AreEqual(dtoGroup.Id, group.Id); Assert.AreEqual(dtoGroup.Name, group.Name); Assert.AreEqual(dtoGroup.DtoTeams[0].Id, group.Teams[0].Id); Assert.AreEqual(dtoGroup.DtoTeams[1].Id, group.Teams[1].Id); Assert.AreEqual(dtoGroup.DtoTeams[0].Name, group.Teams[0].Name); Assert.AreEqual(dtoGroup.DtoTeams[1].Name, group.Teams[1].Name); }
public void TearDown() { team = null; }
public void Test_if_group_can_be_created_with_a_tournaments() { Team Team1 = new Team() { Id = 1, Name = "Awesome" }; Team Team2 = new Team() { Id = 1, Name = "More Awesome" }; List<Team> teams = new List<Team> { Team1, Team2 }; Tournament tournament = new Tournament() { Id = 1, Name = "tour1", Game = new Game() { Id = 1, Name = "war", Genre = new Genre() { Id = 1, Name = "role" } }, StartDate = DateTime.Today, TournamentType = new TournamentType() { Id = 1, Type = "2vs2" } }; Group group = new Group() { Id = 1, Name = "A", Teams = teams, Tournament = tournament }; DTOGroupConverter dtogroupConverter = new DTOGroupConverter(); DTOGroup dtoGroup = dtogroupConverter.Convert(group); Assert.IsNotNull(dtoGroup); Assert.AreEqual(dtoGroup.Id, group.Id); Assert.AreEqual(dtoGroup.Name, group.Name); Assert.AreEqual(dtoGroup.DtoTeams[0].Id, group.Teams[0].Id); Assert.AreEqual(dtoGroup.DtoTeams[1].Id, group.Teams[1].Id); Assert.AreEqual(dtoGroup.DtoTeams[0].Name, group.Teams[0].Name); Assert.AreEqual(dtoGroup.DtoTeams[1].Name, group.Teams[1].Name); Assert.AreEqual(dtoGroup.DtoTournament.Id, tournament.Id); Assert.AreEqual(dtoGroup.DtoTournament.Name, tournament.Name); Assert.AreEqual(dtoGroup.DtoTournament.StartDate, tournament.StartDate); }