public void RosterCannotHaveSevenPlayers() { // Arrange var invalidRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7" } }; var matchResult = new MatchResult(invalidRoster, 9, 11, 123); // Act var matchSerie = new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 0, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 0, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 0, 0, 0), new MatchGame("p8", 0, 0, 0), 0), }); // Assert var ex = Assert.Throws<MatchException>(() => matchResult.RegisterSerie(matchSerie)); Assert.Equal("Roster must have 8, 9, or 10 players when registering results", ex.Message); }
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 RosterCanHaveTenPlayers() { // Arrange var validRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10" } }; var matchResult = new MatchResult(validRoster, 9, 11, 123); // Act var matchSerie = new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 0, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 0, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 0, 0, 0), new MatchGame("p8", 0, 0, 0), 0) }); // Assert Assert.DoesNotThrow(() => matchResult.RegisterSerie(matchSerie)); }
public void RosterCanHaveEightPlayers() { // Arrange var validRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8" } }; var matchResult = new MatchResult(validRoster, 9, 11, 123); // Act var matchSerie = new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 0, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 0, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 0, 0, 0), new MatchGame("p8", 0, 0, 0), 0), }); // Assert Assert.DoesNotThrow(() => matchResult.RegisterSerie(matchSerie)); Assert.Equal(typeof(SerieRegistered), matchResult.GetUncommittedChanges()[1].GetType()); }
public void OnlyAwardMedalsOnce() { // Arrange var validRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8" } }; var matchResult = new MatchResult(validRoster, 9, 11, 123); // Act matchResult.RegisterSerie(new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 269, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 270, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 300, 0, 0), new MatchGame("p8", 0, 0, 0), 0), })); matchResult.RegisterSerie(new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 169, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 170, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 200, 0, 0), new MatchGame("p8", 0, 0, 0), 0), })); // Assert var changes = matchResult.GetUncommittedChanges(); Assert.Equal(5, changes.Length); var medal1 = changes[2] as AwardedMedal; var medal2 = changes[3] as AwardedMedal; Assert.NotNull(medal1); Assert.NotNull(medal2); Assert.Equal("p4", medal1.Player); Assert.Equal(MedalType.PinsInSerie, medal1.MedalType); Assert.Equal(270, medal1.Value); Assert.Equal("p7", medal2.Player); Assert.Equal(MedalType.PinsInSerie, medal2.MedalType); Assert.Equal(300, medal2.Value); }
public void MedalFor4Score() { // Arrange var validRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8" } }; var matchResult = new MatchResult(validRoster, 9, 11, 123); // Act for (var i = 0; i < 4; i++) { var matchSerie = new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 0, 0, 0), new MatchGame("p2", 0, 0, 0), 1), new MatchTable(new MatchGame("p3", 0, 0, 0), new MatchGame("p4", 0, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 0, 0, 0), new MatchGame("p8", 0, 0, 0), 0), }); matchResult.RegisterSerie(matchSerie); } // Assert var changes = matchResult.GetUncommittedChanges(); Assert.Equal(7, changes.Length); var medal1 = changes[5] as AwardedMedal; var medal2 = changes[6] as AwardedMedal; Assert.NotNull(medal1); Assert.NotNull(medal2); Assert.Equal("p1", medal1.Player); Assert.Equal(MedalType.TotalScore, medal1.MedalType); Assert.Equal(4, medal1.Value); Assert.Equal("p2", medal2.Player); Assert.Equal(MedalType.TotalScore, medal2.MedalType); Assert.Equal(4, medal2.Value); }
public void CanNotRegisterInvalidPlayer() { // Arrange var validRoster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false) { Id = "rosters-1", Players = new List<string> { "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8" } }; var matchResult = new MatchResult(validRoster, 9, 11, 123); // Act var matchSerie = new MatchSerie( new List<MatchTable> { new MatchTable(new MatchGame("p1", 0, 0, 0), new MatchGame("p2", 0, 0, 0), 0), new MatchTable(new MatchGame("invalid-id", 0, 0, 0), new MatchGame("p4", 0, 0, 0), 0), new MatchTable(new MatchGame("p5", 0, 0, 0), new MatchGame("p6", 0, 0, 0), 0), new MatchTable(new MatchGame("p7", 0, 0, 0), new MatchGame("p8", 0, 0, 0), 0) }); // Assert var ex = Assert.Throws<MatchException>(() => matchResult.RegisterSerie(matchSerie)); Assert.Equal("Can only register players from roster", ex.Message); }