public async Task <ActionResult> Create(TournamentDto inputTournament) { inputTournament.Id = Guid.NewGuid(); await tournamentService.AddNewTournament(inputTournament); return(this.CreatedAtAction(nameof(GetById), new { id = inputTournament.Id }, inputTournament)); }
public void CallingPostWithValidDataShouldReturnOkAndObject() { var model = new TournamentDto { Name = "Test tournament", Date = DateTimeOffset.Now.AddDays(2) }; var mockRepository = new Mock <ITournamentRepository>(); mockRepository.Setup(r => r.Add(It.IsAny <TournamentDto>())) .Returns <TournamentDto>((data) => new Tournament { Name = data.Name, Date = data.Date.Value }); var ctrl = new TournamentController(mockRepository.Object, null, null, null); var result = ctrl.CreateTournament(model); Assert.IsAssignableFrom <OkObjectResult>(result); var tournament = (result as OkObjectResult).Value as TournamentDto; Assert.Equal(model.Name, tournament.Name); Assert.Equal(model.Date.Value, tournament.Date); }
public TournamentDto GetTournament() { var tournament = new TournamentDto(); var game1 = new GameDto(); game1.Players.Add(GetPlayer("Armando", GameConstants.Paper)); game1.Players.Add(GetPlayer("Dave", GameConstants.Scissor)); tournament.Games.Add(game1); var game2 = new GameDto(); game2.Players.Add(GetPlayer("Richard", GameConstants.Rock)); game2.Players.Add(GetPlayer("Michael", GameConstants.Scissor)); tournament.Games.Add(game2); var game3 = new GameDto(); game3.Players.Add(GetPlayer("Allen", GameConstants.Scissor)); game3.Players.Add(GetPlayer("Omer", GameConstants.Paper)); tournament.Games.Add(game3); var game4 = new GameDto(); game4.Players.Add(GetPlayer("David E.", GameConstants.Rock)); game4.Players.Add(GetPlayer("Richard X.", GameConstants.Paper)); tournament.Games.Add(game4); return(tournament); }
public IActionResult Delete(TournamentDto log) { var model = _mapper.Map <TournamentDto, Tournament>(log); _repository.Delete(model); return(new NoContentResult()); }
private void ValidateNumberOfGames(TournamentDto tournament) { if (tournament.Games.Count % 2 != 0) { throw new Exception(ERROR_MESSAGE_NUMBER_GAMES_INCORRECT); } }
public bool AddTournament(Tournament tournament) { var tournamentDto = new TournamentDto(); tournamentDto = convert.ToTournamentDto(tournament); var model = new bool(); using (var client = new ToteService.TournamentServiceClient()) { try { client.Open(); model = client.AddTournament(tournamentDto); client.Close(); } catch (FaultException <CustomException> customEx) { log.Error(customEx.Message); return(false); } catch (CommunicationException commEx) { log.Error(commEx.Message); return(false); } } return(model); }
public TournamentDto GetTournamentById(int tournamentId) { var model = new TournamentDto(); using (var client = new ToteService.TournamentServiceClient()) { try { client.Open(); model = client.GetTournamentById(tournamentId); client.Close(); if (model == null) { throw new NullReferenceException(); } } catch (FaultException <CustomException> customEx) { log.Error(customEx.Message); return(null); } catch (CommunicationException commEx) { log.Error(commEx.Message); return(null); } catch (NullReferenceException nullEx) { log.Error(nullEx.Message); return(null); } } return(model); }
static void Main(string[] args) { Console.WriteLine("Insert the game like this:"); Console.WriteLine("[[[[\"Armando\",\"P\"],[\"Dave\",\"S\"]],[[\"Richard\",\"R\"],[\"Michael\",\"S\"]],]," + "[[[\"Allen\",\"S\"],[\"Omer\",\"P\"]],[[\"David E.\",\"R\"],[\"Richard X.\",\"P\"]]]]"); Console.WriteLine("Input must have no spaces and must be on the same line.\n"); string input = Console.ReadLine(); var gamesList = new List <GameDto>(); gamesList.AddRange(extract_games(input)); var tournament = new TournamentDto { Games = gamesList }; try { var winner = new Tournament().rps_tournament_winner(tournament); Console.WriteLine("[\"" + winner.Name + "\",\"" + winner.Move + "\"]"); } catch (Exception e) { Console.WriteLine(e); } Console.ReadKey(); }
public IHttpActionResult PostTournamentByLanCenter(int lancenterid, [FromBody] TournamentDto tournamentdto) { dynamic Response = new ExpandoObject(); try { if (!ModelState.IsValid) { Response.Status = ConstantValues.ResponseStatus.ERROR; Response.Message = ConstantValues.ErrorMessage.BAD_REQUEST; return(Content(HttpStatusCode.BadRequest, Response)); } var tournament = Mapper.Map <TournamentDto, Tournament>(tournamentdto); tournament.lanCenterId = lancenterid; tournament.status = ConstantValues.EntityStatus.ACTIVE; _context.Tournaments.Add(tournament); _context.SaveChanges(); tournamentdto.id = tournament.id; Response.Status = ConstantValues.ResponseStatus.OK; Response.Tournament = tournamentdto; return(Created(new Uri(Request.RequestUri + "/" + tournament.id), Response)); } catch (Exception e) { Response.Status = ConstantValues.ResponseStatus.ERROR; Response.Message = ConstantValues.ErrorMessage.INTERNAL_SERVER_ERROR; return(Content(HttpStatusCode.InternalServerError, Response)); } }
public bool AddTournament(TournamentDto tournamentDto) { if (tournamentDto == null || tournamentDto.Name == String.Empty) { GenerateFaultException("AddTournament", "ArgumentException"); } var parameters = new List <Parameter>(); parameters.Add(new Parameter { Type = DbType.String, Name = "@Name", Value = tournamentDto.Name }); parameters.Add(new Parameter { Type = DbType.Int32, Name = "@SportId", Value = tournamentDto.SportId }); var connection = new Connection <TournamentDto>(); try { return(connection.GetConnectionUpdate(CommandType.StoredProcedure, "AddTournament", parameters)); } catch (SqlException sqlEx) { var exception = new CustomException(); exception.Title = "AddTournament"; log.Error(sqlEx.Message); throw new FaultException <CustomException>(exception, sqlEx.Message); } }
public void SetUp() { _tournament = new TournamentDto() { Id = 1, Caption = "New Tournament", Description = "First added tournament", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(3), TournamentTime = 20 }; _tournaments = new List <TournamentDto>() { _tournament, new TournamentDto() { Id = 2, Caption = "Absolute New Tournament", Description = "Second added tournament", StartDate = DateTime.Now.AddDays(-3), EndDate = DateTime.Now.AddDays(-1), TournamentTime = 20 } }; _exercises = new List <ExerciseDto>() { new ExerciseDto() { Id = 1, Text = "1+1", Answer = "2", OrderNumber = 1, Tournament = _tournament }, new ExerciseDto() { Id = 2, Text = "3+5", Answer = "8", OrderNumber = 2, Tournament = _tournament }, new ExerciseDto() { Id = 3, Text = "First three letters of alphabet", Answer = "a,b,c", OrderNumber = 3, Tournament = _tournament } }; //Initialize repositories _tournamentRepositoryMock = new Mock <ITournamentRepository>(); _exerciseRepositoryMock = new Mock <IExerciseRepository>(); _tournamentsUsersRepositoryMock = new Mock <ITournamentsUsersRepository>(); }
public static TournamentDto GetTournamentWithWrongNumberOfPlayers() { var tournament = new TournamentDto(); tournament.Games.Add(GameDtoFake.GetGameWithWrongNumberOfPlayers()); return(tournament); }
public async Task AddNewTournament(TournamentDto inputTournament) { var model = this.mapper.Map <Tournament>(inputTournament); await this.unitOfWork.Tournaments.AddAsync(model); await this.unitOfWork.CompleteAsync(); }
public static TournamentDto GetTournamentWithWrongMove() { var tournament = new TournamentDto(); tournament.Games.Add(GameDtoFake.GetGame1()); tournament.Games.Add(GameDtoFake.GetGameWithWrongMove()); return(tournament); }
public static TournamentDto GetValidTournament() { var tournament = new TournamentDto(); tournament.Games.Add(GameDtoFake.GetGame1()); tournament.Games.Add(GameDtoFake.GetGame2()); return(tournament); }
public Tournament Add(TournamentDto data) { var arguments = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("Name", data.Name), new KeyValuePair <string, object>("Date", data.Date.Value.ToString()) }; return(dbHelper.Insert("Tournament", arguments, UnpackTournament, "Id, Name, Date")); }
public static Tournament ConvertToEntity(this TournamentDto tournament) { return(new Tournament { Id = tournament.Id, Date = tournament.Date, TotalTeam = tournament.TotalTeam, MaxPlayerPerTeam = tournament.MaxPlayerPerTeam }); }
public static Tournaments ConvertToDb(this TournamentDto tournament) { return(new Tournaments { Id = Guid.Parse(tournament.Id), Date = tournament.Date, TotalTeam = tournament.TotalTeam, MaxPlayerPerTeam = tournament.MaxPlayerPerTeam }); }
public TournamentDto Update(TournamentDto tournament) { var tournamentEntity = mapper.Map <Tournament>(tournament); tournamentRepository.Update(tournamentEntity); tournamentRepository.SaveChanges(); var tournamentToReturn = mapper.Map <TournamentDto>(tournamentEntity); return(tournamentToReturn); }
public IEnumerable <TournamentDto> GetAllTournaments() { List <TournamentDto> result = new List <TournamentDto>(); foreach (ITournament tournament in TournamentManager.GetTournaments()) { result.Add(TournamentDto.FromTournament(tournament)); } return(result); }
public IActionResult Put(int id, [FromBody] TournamentDto tournament) { var model = _mapper.Map <TournamentDto, Tournament>(tournament); if (tournament == null || tournament.Id != id) { return(BadRequest()); } _repository.Update(model); return(new NoContentResult()); }
public TournamentDto ToTournamentDto(Tournament tournament) { var tournamentDto = new TournamentDto { TournamentId = tournament.TournamentId, SportId = tournament.SportId, Name = tournament.Name }; return(tournamentDto); }
public IActionResult CreateTournament([FromBody] TournamentDto value) { if (!ModelState.IsValid) { return(BadRequest()); } var tournament = tournamentRepository.Add(value); return(Ok(tournament.ToTournamentDto())); }
public IActionResult Create([FromBody] TournamentDto item) { var model = _mapper.Map <TournamentDto, Tournament>(item); if (model == null) { return(BadRequest()); } _repository.Insert(model); return(CreatedAtRoute("GetByTournament", new { id = model.Id }, item)); }
public async Task HandleAsync(AddTournament command) { var newTournament = new TournamentDto() { Caption = command.Caption, Description = command.Description, EndDate = command.EndDate, StartDate = command.StartDate }; await _tournamentRepository.Add(newTournament); await _tournamentRepository.SaveChanges(); }
public void AddTournament_ValidTournament_SavedTournament() { var tournament = new TournamentDto { Date = new DateTime(2015, 2, 1), MaxPlayerPerTeam = 6, TotalTeam = 4 }; tournament.Id = tournamentGuid.ToString(); tournamentRepository.Add(tournament); }
public void Setup() { _tournamentRepository = new TournamentRepository(Context); _baseTournament = new TournamentDto() { Id = 1, Caption = "New Tournament", Description = "First added tournament", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(3), TournamentTime = 20 }; }
public Tournament ToTournament(TournamentDto tournamentDto) { var tournament = new Tournament { TournamentId = tournamentDto.TournamentId, Name = tournamentDto.Name, SportId = tournamentDto.SportId, Sport = new Sport { SportId = tournamentDto.SportId, Name = tournamentDto.Sport } }; return(tournament); }
public void ModelValidatesCorrectly(string name, string eventDateString, bool shouldBeValid) { DateTimeOffset eventDate; var model = new TournamentDto { Name = name, Date = DateTimeOffset.TryParse(eventDateString, out eventDate) ? new DateTimeOffset?(eventDate) : null }; var context = new ValidationContext(model, null, null); var result = new List <ValidationResult>(); var valid = Validator.TryValidateObject(model, context, result, true); Assert.Equal(shouldBeValid, valid); }
public string RpsGameWinner(TournamentDto tournament) { while (tournament.Games.Count > 1) { ValidateNumberOfGames(tournament); var winnersList = new List <PlayerDto>(); foreach (var game in tournament.Games) { var winPlayer = RunGame(game); winnersList.Add(winPlayer); } tournament = GenerateNewTurn(winnersList); } var winningPlayer = RunGame(tournament.Games[0]); return(winningPlayer.OutPutNameMove); }