public void ValidScore() { // Arrange var game1 = new MatchGame("p1", 0, 0, 0); var game2 = new MatchGame("p2", 0, 0, 0); // Act & Assert Assert.DoesNotThrow(() => new MatchTable(game1, game2, 0)); Assert.DoesNotThrow(() => new MatchTable(game1, game2, 1)); }
public void MustHaveDifferentPlayers() { // Arrange var game1 = new MatchGame("p1", 0, 0, 0); var game2 = new MatchGame("p1", 0, 0, 0); // Act & Assert var ex = Assert.Throws<MatchException>(() => new MatchTable(game1, game2, 0)); Assert.Equal("Table must have different players", ex.Message); }
public void InvalidScore() { // Arrange var game1 = new MatchGame("p1", 0, 0, 0); var game2 = new MatchGame("p2", 0, 0, 0); // Act & Assert Assert.Throws<ArgumentOutOfRangeException>(() => new MatchTable(game1, game2, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => new MatchTable(game1, game2, 2)); }
public MatchTable(MatchGame game1, MatchGame game2, int score) { if (game1 == null) throw new ArgumentNullException("game1"); if (game2 == null) throw new ArgumentNullException("game2"); if (score != 0 && score != 1) throw new ArgumentOutOfRangeException("score", score, "Score out of range"); if (game1.Player == game2.Player) throw new MatchException("Table must have different players"); Score = score; Game1 = game1; Game2 = game2; }
public void Execute(IDocumentSession session, IEventStoreSession eventStoreSession) { var matchResult = new MatchResult( roster, result.TeamScore, result.OpponentScore, roster.BitsMatchId); var series = new[] { result.Series.ElementAtOrDefault(0), result.Series.ElementAtOrDefault(1), result.Series.ElementAtOrDefault(2), result.Series.ElementAtOrDefault(3) }; var matchSeries = new List<MatchSerie>(); foreach (var serie in series.Where(x => x != null)) { var tables = new List<MatchTable>(); for (var i = 0; i < 4; i++) { var game1 = new MatchGame( serie.Tables[i].Game1.Player, serie.Tables[i].Game1.Pins, serie.Tables[i].Game1.Strikes, serie.Tables[i].Game1.Spares); var game2 = new MatchGame( serie.Tables[i].Game2.Player, serie.Tables[i].Game2.Pins, serie.Tables[i].Game2.Strikes, serie.Tables[i].Game2.Spares); tables.Add(new MatchTable(game1, game2, serie.Tables[i].Score)); } matchSeries.Add(new MatchSerie(tables)); } matchResult.RegisterSeries(matchSeries); eventStoreSession.Store(matchResult); }
public ActionResult RegisterSerie( string aggregateId, int bitsMatchId, ResultSeriesReadModel.Serie serie) { var matchResult = EventStoreSession.Load<MatchResult>(aggregateId); if (matchResult == null) throw new HttpException(404, "Match result not found"); var tables = new List<MatchTable>(); for (var i = 0; i < 4; i++) { var game1 = new MatchGame( serie.Tables[i].Game1.Player, serie.Tables[i].Game1.Pins, serie.Tables[i].Game1.Strikes, serie.Tables[i].Game1.Spares); var game2 = new MatchGame( serie.Tables[i].Game2.Player, serie.Tables[i].Game2.Pins, serie.Tables[i].Game2.Strikes, serie.Tables[i].Game2.Spares); tables.Add(new MatchTable(game1, game2, serie.Tables[i].Score)); } matchResult.RegisterSerie(new MatchSerie(tables)); return RedirectToAction( "Details", "MatchResult", new { id = bitsMatchId }); }
public ActionResult RegisterBitsVerifyConfirmed(RegisterBitsResult vm) { if (ModelState.IsValid == false) return View(vm); var roster = DocumentSession.Load<Roster>(vm.RosterId); if (roster == null) throw new HttpException(404, "Roster not found"); var matchResult = new MatchResult( roster, vm.TeamScore, vm.OpponentScore, vm.BitsMatchId); foreach (var serie in new[] { vm.Serie1, vm.Serie2, vm.Serie3, vm.Serie4 }.Where(x => x != null)) { var tables = new List<MatchTable>(); for (var i = 0; i < 4; i++) { var game1 = new MatchGame( serie.Tables[i].Game1.Player, serie.Tables[i].Game1.Pins, serie.Tables[i].Game1.Strikes, serie.Tables[i].Game1.Spares); var game2 = new MatchGame( serie.Tables[i].Game2.Player, serie.Tables[i].Game2.Pins, serie.Tables[i].Game2.Strikes, serie.Tables[i].Game2.Spares); tables.Add(new MatchTable(game1, game2, serie.Tables[i].Score)); } matchResult.RegisterSerie(new MatchSerie(tables)); } EventStoreSession.Store(matchResult); return RedirectToAction("Index", "MatchResult"); }
public void AddGame(MatchGame game) { TotalSeries++; TotalPins += game.Pins; }