public void CanEditDetails()
        {
            // Arrange
            var then = DateTime.Now.AddDays(-1);
            var originalMatch = new Match8x4("Place", then, 1, new Team8x4("Home", 13), new Team8x4("Away", 6));
            Session.Store(originalMatch);
            Session.SaveChanges();

            // Act
            var controller = new MatchController { DocumentSession = Session };
            var now = DateTimeOffset.Now;
            var result = controller.EditDetails8x4(new Match8x4ViewModel.MatchDetails
            {
                Id = originalMatch.Id,
                Location = "NewPlace",
                Date = now,
                BitsMatchId = 2
            });

            // Assert
            result.AssertActionRedirect().ToAction("Details8x4").WithParameter("id", originalMatch.Id);
            var match = Session.Load<Match8x4>(originalMatch.Id);
            Assert.Equal("NewPlace", match.Location);
            Assert.Equal(now, match.Date);
            Assert.Equal(2, match.BitsMatchId);
        }
        public void ShouldViewMatch()
        {
            // Arrange
            Session.Store(new Match8x4("P1", DateTime.Now, 1, new Team8x4("Home1", 4), new Team8x4("Away1", 7)) { Id = 1 });
            Session.Store(new Match8x4("P2", DateTime.Now, 2, new Team8x4("Home2", 5), new Team8x4("Away2", 8)) { Id = 2 });
            Session.Store(new Match8x4("P3", DateTime.Now, 3, new Team8x4("Home3", 6), new Team8x4("Away3", 9)) { Id = 3 });
            var controller = new MatchController { DocumentSession = Session };

            // Act
            var view1 = controller.Details8x4(1) as ViewResult;
            Assert.NotNull(view1);
            Debug.Assert(view1 != null, "view1 != null");
            var model1 = view1.Model as Match8x4ViewModel;
            Debug.Assert(model1 != null, "model1 != null");
            Assert.Equal(1, model1.Match.Id);

            var view2 = controller.Details8x4(2) as ViewResult;
            Assert.NotNull(view2);
            Debug.Assert(view2 != null, "view2 != null");
            var model2 = view2.Model as Match8x4ViewModel;
            Debug.Assert(model2 != null, "model2 != null");
            Assert.Equal(2, model2.Match.Id);

            var view3 = controller.Details8x4(3) as ViewResult;
            Assert.NotNull(view3);
            Debug.Assert(view3 != null, "view3 != null");
            var model3 = view3.Model as Match8x4ViewModel;
            Debug.Assert(model3 != null, "model3 != null");
            Assert.Equal(3, model3.Match.Id);
        }
        public void ViewIsCreate()
        {
            // Arrange
            var controller = new MatchController { DocumentSession = Session };

            // Act
            var now = DateTimeOffset.Now;
            controller.Register8x4(new Register8x4MatchViewModel
                {
                    Location = "Somewhere",
                    Date = now,
                    BitsMatchId = 1,
                    HomeTeam = new Team8x4ViewModel
                        {
                            Name = "HomeTeam",
                            Score = 13
                        },
                    AwayTeam = new Team8x4ViewModel
                        {
                            Name = "AwayTeam",
                            Score = 6
                        }
                });
            Session.SaveChanges();

            // Assert
            var match = Session.Query<Match8x4>().Single();
            Assert.Equal("Somewhere", match.Location);
            Assert.Equal(1, match.BitsMatchId);
            Assert.Equal(now, match.Date);
            Assert.Equal("HomeTeam", match.HomeTeam.Name);
            Assert.Equal(13, match.HomeTeam.Score);
            Assert.Equal(6, match.AwayTeam.Score);
        }
        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);
        }
        public void ShouldViewIndex()
        {
            // Arrange
            var controller = new MatchController { DocumentSession = Session };

            // Act
            var result = controller.Index();

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
        public void WhenErrorReturnView()
        {
            // Arrange
            var controller = new MatchController { DocumentSession = Session };
            controller.ModelState.AddModelError("key", "error");

            // Act
            var result = controller.Register4x4(new Register4x4MatchViewModel());

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
 public void CannotViewNonExistingMatch()
 {
     var controller = new MatchController { DocumentSession = Session };
     try
     {
         controller.Details8x4(1);
         Assert.False(true, "Should throw");
     }
     catch (HttpException ex)
     {
         Assert.Equal(404, ex.GetHttpCode());
     }
 }
        public void CorrectView()
        {
            // Arrange
            var match = DbSeed.Create4x4Match();
            Session.Store(match);

            // Act
            var controller = new MatchController { DocumentSession = Session };
            var result = controller.EditTeam4x4(id: match.Id, isHomeTeam: true);

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
 public void CannotPostNonExistingMatch()
 {
     var controller = new MatchController { DocumentSession = Session };
     try
     {
         controller.EditTeam4x4(new EditTeam4x4ViewModel { Id = 1 });
         Assert.False(true, "Should throw");
     }
     catch (HttpException ex)
     {
         Assert.Equal(404, ex.GetHttpCode());
     }
 }
        public void CorrectView()
        {
            // Arrange
            var match = DbSeed.Create8x4Match();
            Session.Store(match);

            // Act
            var controller = new MatchController { DocumentSession = Session };
            var result = controller.EditDetails8x4(match.Id);

            // Assert
            result.AssertViewRendered().ForView(string.Empty);
        }
        public void ViewIsCreate()
        {
            // Arrange
            var controller = new MatchController { DocumentSession = Session };

            // Act
            var now = DateTimeOffset.Now;
            controller.Register4x4(new Register4x4MatchViewModel
                {
                    Location = "Somewhere",
                    Date = now,
                    HomeTeam = new Team4x4ViewModel
                        {
                            Name = "HomeTeam",
                            Score = 13,
                            Player1 = new Team4x4ViewModel.Player
                                {
                                    Game1 = new Team4x4ViewModel.Game
                                        {
                                            Player = "Lennart Axelsson",
                                            Pins = 155,
                                            Score = 1
                                        }
                                }
                        },
                    AwayTeam = new Team4x4ViewModel
                        {
                            Name = "AwayTeam",
                            Score = 6
                        }
                });
            Session.SaveChanges();

            // Assert
            var match = Session.Query<Match4x4>().Single();
            Assert.Equal("Somewhere", match.Location);
            Assert.Equal(now, match.Date);
            Assert.Equal("HomeTeam", match.HomeTeam.Name);
            Assert.Equal(13, match.HomeTeam.Score);
            var game = match.HomeTeam.Series.ElementAt(0).Games.ElementAt(0);
            Assert.Equal(155, game.Pins);
            Assert.Equal("Lennart Axelsson", game.Player);
            Assert.Equal(1, game.Score);
            Assert.Equal(6, match.AwayTeam.Score);
        }
Exemplo n.º 12
0
        public void ShouldListMatches()
        {
            // Arrange
            var now = DateTime.Now;
            Session.Store(new Match8x4("P1", now, 1, new Team8x4("Home", 1), new Team8x4("Away", 2)));
            Session.Store(new Match8x4("P2", now.AddDays(1), 2, new Team8x4("Home2", 3), new Team8x4("Away2", 4)));
            Session.Store(new Match4x4("P3", now.AddDays(2), new Team4x4("Home3", 6), new Team4x4("Away3", 14)));
            Session.SaveChanges();

            // Act
            var controller = new MatchController { DocumentSession = Session };
            var result = controller.Index().Model as IEnumerable<Match_ByDate.Result>;

            // Assert
            Assert.NotNull(result);
            Debug.Assert(result != null, "result != null");
            var matches = result.ToArray();
            Assert.Equal(3, matches.Length);
            Assert.Equal("P3", matches[0].Location);
            Assert.NotNull(matches[0].HomeTeamName);
            Assert.Equal("Home3", matches[0].HomeTeamName);
            Assert.Equal(6, matches[0].HomeTeamScore);
            Assert.NotNull(matches[0].AwayTeamName);
            Assert.Equal("Away3", matches[0].AwayTeamName);
            Assert.Equal(14, matches[0].AwayTeamScore);
            Assert.Equal("4x4", matches[0].Type);
            Assert.Equal("P2", matches[1].Location);
            Assert.NotNull(matches[1].HomeTeamName);
            Assert.Equal("Home2", matches[1].HomeTeamName);
            Assert.Equal(3, matches[1].HomeTeamScore);
            Assert.NotNull(matches[1].AwayTeamName);
            Assert.Equal("Away2", matches[1].AwayTeamName);
            Assert.Equal(4, matches[1].AwayTeamScore);
            Assert.Equal("8x4", matches[1].Type);
            Assert.Equal("P1", matches[2].Location);
            Assert.NotNull(matches[2].HomeTeamName);
            Assert.Equal("Home", matches[2].HomeTeamName);
            Assert.Equal(1, matches[2].HomeTeamScore);
            Assert.NotNull(matches[2].AwayTeamName);
            Assert.Equal("Away", matches[2].AwayTeamName);
            Assert.Equal(2, matches[2].AwayTeamScore);
            Assert.Equal("8x4", matches[2].Type);
        }
        public void CanEditTeam()
        {
            // Arrange
            var originalMatch = new Match4x4("Place", DateTime.Now, new Team4x4("Home", 13), new Team4x4("Away", 6));
            Session.Store(originalMatch);
            Session.SaveChanges();

            // Act
            var controller = new MatchController { DocumentSession = Session };
            var result = controller.EditTeam4x4(new EditTeam4x4ViewModel
            {
                Id = originalMatch.Id,
                IsHomeTeam = false,
                Team = DbSeed.Create4x4Match().HomeTeam.MapTo<Team4x4ViewModel>()
            });
            Session.SaveChanges();

            // Assert
            result.AssertActionRedirect().ToAction("Details4x4").WithParameter("id", originalMatch.Id);
            var match = Session.Load<Match4x4>(originalMatch.Id);
            TestData.VerifyTeam(match.AwayTeam);
        }