public void SelectWinner_ShouldReturnWinnerWithGreaterRating() { //Arrange var movie1 = new Movie() { id = "tt4881806", titulo = "Jurassic World: Reino Ameaçado", ano = 2018, nota = 6.7f }; var movie2 = new Movie() { id = "tt3606756", titulo = "Os Incríveis 2", ano = 2018, nota = 8.5f }; //Act var result = championshipService.SelectWinner(movie1, movie2); //Assert result.Should().Be(movie2); }
public IActionResult Post([FromBody] List <Movie> listMovies) { List <Movie> listWinners = new List <Movie>(); int rounds = (listMovies.Count / 2) - 1; Movie secondPlace = null; listMovies.OrderBy(m => m.titulo); for (var i = rounds; i > 0; i--) { if (listWinners.Count > 0) { listMovies.AddRange(listWinners); listWinners.Clear(); } while (listMovies.Count > 0) { var firstMovie = listMovies.First(); var lastMovie = listMovies.Last(); var movieWinner = _championshipService.SelectWinner(firstMovie, lastMovie); secondPlace = movieWinner != firstMovie ? firstMovie : lastMovie; listMovies.Remove(firstMovie); listMovies.Remove(lastMovie); listWinners.Add(movieWinner); } } listWinners.Add(secondPlace); return(Ok(listWinners)); }