public void CannotRegisterSameBitsIdTwice()
        {
            // Arrange
            var controller = new MatchController { DocumentSession = Session };
            var now = DateTime.Now;
            var vm = new Register8x4MatchViewModel
            {
                Location = "Somewhere",
                Date = now,
                BitsMatchId = 1,
                HomeTeam = new Team8x4ViewModel
                {
                    Name = "HomeTeam",
                    Score = 13
                },
                AwayTeam = new Team8x4ViewModel
                {
                    Name = "AwayTeam",
                    Score = 6
                }
            };
            controller.Register8x4(vm);
            Session.SaveChanges();

            // Act
            var result = controller.Register8x4(vm);

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
예제 #2
0
        public ActionResult Register8x4(Register8x4MatchViewModel model)
        {
            if (DocumentSession.BitsIdExists(model.BitsMatchId))
                ModelState.AddModelError("BitsMatchId", "Matchen redan registrerad");

            if (!ModelState.IsValid)
                return View(model);

            var match = new Match8x4(
                model.Location,
                model.Date,
                model.BitsMatchId,
                model.HomeTeam.MapTo<HomeTeamFactory>().CreateTeam(),
                model.AwayTeam.MapTo<AwayTeamFactory>().CreateTeam());
            DocumentSession.Store(match);

            return RedirectToAction("Details8x4", new { id = match.Id });
        }