Пример #1
0
 public RegisterMatchCommand(Roster roster, ParseResult result)
 {
     if (roster == null) throw new ArgumentNullException("roster");
     if (result == null) throw new ArgumentNullException("result");
     this.roster = roster;
     this.result = result;
 }
Пример #2
0
 public MatchResultTest()
 {
     roster = new Roster(2012, 11, 1, "H", "A", "L", "A", new DateTime(2012, 2, 3), false)
     {
         Id = "rosters-1"
     };
 }
 public ResultHeaderReadModel(
     Roster roster,
     string aggregateId,
     int teamScore,
     int opponentScore,
     int bitsMatchId,
     bool isFourPlayer)
 {
     Id = IdFromBitsMatchId(bitsMatchId);
     SetValues(roster, aggregateId, teamScore, opponentScore, bitsMatchId, isFourPlayer);
 }
        public void SetUp()
        {
            // Arrange
            roster = 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"
                }
            };
            matchResult = new MatchResult(roster, 9, 11, 123);

            // Act
            var series = new[]
            {
                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),
                    }),
                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),
                    })
            };

            using (DomainEvent.TestWith(e => ev = (MatchRegisteredEvent)e))
            {
                matchResult.RegisterSeries(series);
            }
        }
Пример #5
0
        public ActionResult Create(CreateRosterViewModel vm)
        {
            if (!ModelState.IsValid) return View(vm);

            var roster = new Roster(
                vm.Season,
                vm.Turn,
                vm.BitsMatchId,
                vm.Team,
                vm.TeamLevel,
                vm.Location,
                vm.Opponent,
                vm.Date,
                vm.IsFourPlayer);
            DocumentSession.Store(roster);
            return RedirectToAction("Index");
        }
Пример #6
0
        public void CanClearAndReAwardMedals()
        {
            // 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);
            matchResult.AwardMedals();

            // Act
            matchResult.ClearMedals();

            // Assert
            Assert.DoesNotThrow(matchResult.AwardMedals);
        }
Пример #7
0
        public void CanClearMedals()
        {
            // 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.ClearMedals();

            // Assert
            var changes = matchResult.GetUncommittedChanges();
            Assert.Equal(2, changes.Length);
            var domainEvent = changes[1];
            Assert.IsAssignableFrom<ClearMedals>(domainEvent);
            Assert.Equal(((ClearMedals)domainEvent).BitsMatchId, 123);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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));
        }
Пример #10
0
        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());
        }
Пример #11
0
        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);
        }
Пример #12
0
        public void MedalFor270OrMore()
        {
            // 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"
                }
            };

            var matchResult = new MatchResult4(validRoster, 9, 11, 123);

            // Act
            var matchSerie = new MatchSerie4(
                new List<MatchGame4>
                {
                    new MatchGame4("p1", 0, 269), new MatchGame4("p2", 0, 270),
                    new MatchGame4("p3", 0, 0), new MatchGame4("p4", 0, 300)
                });
            matchResult.RegisterSerie(matchSerie);

            // Assert
            var changes = matchResult.GetUncommittedChanges();
            Assert.Equal(4, changes.Length);
            var medal1 = changes[2] as AwardedMedal;
            var medal2 = changes[3] as AwardedMedal;
            Assert.NotNull(medal1);
            Assert.NotNull(medal2);
            Assert.Equal("p2", medal1.Player);
            Assert.Equal(MedalType.PinsInSerie, medal1.MedalType);
            Assert.Equal(270, medal1.Value);
            Assert.Equal("p4", medal2.Player);
            Assert.Equal(MedalType.PinsInSerie, medal2.MedalType);
            Assert.Equal(300, medal2.Value);
        }
Пример #13
0
        protected override void OnSetUp(Castle.Windsor.IWindsorContainer container)
        {
            // Arrange
            Transact(session =>
            {
                var players = new[]
                {
                    new Player("Christer Liedholm", "*****@*****.**", Player.Status.Active),
                    new Player("Mathias Ernest", "*****@*****.**", Player.Status.Active),
                    new Player("Torbjörn Jensen", "*****@*****.**", Player.Status.Active),
                    new Player("Alf Kindblom", "*****@*****.**", Player.Status.Active),
                    new Player("Peter Sjöberg", "*****@*****.**", Player.Status.Active),
                    new Player("Lars Öberg", "*****@*****.**", Player.Status.Active),
                    new Player("Mikael Axelsson", "*****@*****.**", Player.Status.Active),
                    new Player("Hans Norbeck", "*****@*****.**", Player.Status.Active),
                    new Player("Lennart Axelsson", "*****@*****.**", Player.Status.Active)
                };

                foreach (var player in players)
                {
                    session.Store(player);
                }

                var roster = new Roster(2012, 1, 3048746, "Fredrikshof IF", "A", "Bowl-O-Rama", "Högdalen BK", new DateTime(2013, 4, 27), false)
                {
                    Players = players.Select(x => x.Id).ToList()
                };
                session.Store(roster);
            });

            var bitsClient = Mock.Of<IBitsClient>(x => x.DownloadMatchResult(3048746) == Resources.Id3048746);
            container.Register(Component.For<IBitsClient>().Instance(bitsClient));
        }
Пример #14
0
        public void CannotAwardMedalsTwice()
        {
            // 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.AwardMedals();

            // Assert
            Assert.Throws<ApplicationException>(() => matchResult.AwardMedals());
        }
Пример #15
0
        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);
        }
Пример #16
0
        private RosterViewModel LoadRoster(Roster roster)
        {
            var vm = roster.MapTo<RosterViewModel>();
            foreach (var player in roster.Players.Where(p => p != null).Select(playerId => DocumentSession.Load<Player>(playerId)))
            {
                vm.Players.Add(Tuple.Create(player.Id, player.Name));
            }

            return vm;
        }
Пример #17
0
 public void SetValues(Roster roster, string aggregateId, int teamScore, int opponentScore, int bitsMatchId, bool isFourPlayer)
 {
     Season = roster.Season;
     Turn = roster.Turn;
     AggregateId = aggregateId;
     RosterId = roster.Id;
     Date = roster.Date;
     Location = roster.Location;
     TeamLevel = roster.TeamLevel;
     Team = roster.Team;
     Opponent = roster.Opponent;
     TeamScore = teamScore;
     OpponentScore = opponentScore;
     BitsMatchId = bitsMatchId;
     IsFourPlayer = isFourPlayer;
 }
 private ActionResult Parse4(
     RegisterBitsVerifyModel model,
     BitsParser parser,
     string content,
     Roster roster,
     IEnumerable<Player> players)
 {
     Parse4Result result = parser.Parse4(content, roster.Team);
     var vm = new RegisterBitsResult4
     {
         BitsMatchId = roster.BitsMatchId,
         TeamScore = result.TeamScore,
         OpponentScore = result.OpponentScore,
         RosterId = model.RosterId,
         Serie1 = result.Series.ElementAtOrDefault(0),
         Serie2 = result.Series.ElementAtOrDefault(1),
         Serie3 = result.Series.ElementAtOrDefault(2),
         Serie4 = result.Series.ElementAtOrDefault(3)
     };
     ViewBag.players = players.Select(x => new PlayerViewModel(x))
         .ToArray();
     return View("RegisterBitsVerify4", vm);
 }
Пример #19
0
        public void CanUpdate()
        {
            // Arrange
            var matchResult = new MatchResult(roster, 9, 11, 123);
            var newRoster = new Roster(2012, 10, 1, "X", "A", "Y", "Z", new DateTime(2012, 1, 1), false)
                                {
                                    Id = "rosters-2"
                                };

            // Act
            matchResult.Update(newRoster, 11, 9, 321);

            // Assert
            var uncommittedChanges = matchResult.GetUncommittedChanges();
            Assert.Equal(3, uncommittedChanges.Length);
            var changed = uncommittedChanges[1] as RosterChanged;
            Assert.NotNull(changed);
            Assert.Equal("rosters-1", changed.OldId);
            Assert.Equal("rosters-2", changed.NewId);

            var updated = uncommittedChanges[2] as MatchResultUpdated;
            Assert.NotNull(updated);
            Assert.Equal("rosters-2", updated.NewRosterId);
            Assert.Equal(11, updated.NewTeamScore);
            Assert.Equal(9, updated.NewOpponentScore);
            Assert.Equal(321, updated.NewBitsMatchId);
        }
Пример #20
0
        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);
        }
Пример #21
0
        public void CanRegisterWithReserve()
        {
            // 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"
                }
            };
            var matchResult = new MatchResult4(validRoster, 9, 11, 123);

            // Act
            var matchSerie = new MatchSerie4(
                new List<MatchGame4>
                {
                    new MatchGame4("p1", 0, 0), new MatchGame4("p2", 0, 0),
                    new MatchGame4("p3", 0, 0), new MatchGame4("p4", 0, 0)
                });

            // Assert
            Assert.DoesNotThrow(() => matchResult.RegisterSerie(matchSerie));
        }