Exemplo n.º 1
0
        public void BetShouldReturnViewWIthValidModel()
        {
            //Arrange
            var userManager = UserManagerMock.New;

            userManager.Setup(u => u.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(userId);

            var predictionService = new Mock <IPredictionService>();

            predictionService.Setup(p => p.GetActiveMatches(userId))
            .Returns(new List <MatchServiceModel>()
            {
                firstMatch, secondMatch
            }.AsQueryable());

            predictionService.Setup(r => r.GetActiveRoundNumber()).
            Returns(RoundNumber);

            predictionService.Setup(p => p.IsCurrentRoundPredicted(userId))
            .Returns(false);

            var controller = new PredictionController(predictionService.Object, userManager.Object);

            Mapper.Initialize();

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

            //Assert
            result.Should().BeOfType <ViewResult>();

            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <ActiveRoundViewModel>();

            var formModel = model.As <ActiveRoundViewModel>();

            formModel.AlreadyPredicted.Should().Be(false);
            formModel.Matches.Count.Should().Be(1);
            formModel.StartedMatches.Count.Should().Be(1);
            formModel.Matches.First().HomeTeam.Should().Be(firstMatch.HomeTeam);
            formModel.Matches.First().AwayTeam.Should().Be(firstMatch.AwayTeam);
            formModel.StartedMatches.First().HomeTeam.Should().Be(secondMatch.HomeTeam);
            formModel.StartedMatches.First().AwayTeam.Should().Be(secondMatch.AwayTeam);
            formModel.RoundNumber.Should().Be(RoundNumber);
        }
Exemplo n.º 2
0
        public void BetPostSuccessfulySavedScoreAndRedirectToGetBet()
        {
            // Arrange
            ActiveRoundViewModel model = GetActiveRoundViewModel(ResultEnum.DRAW);
            string successMessage      = null;
            var    tempData            = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            var userManager = UserManagerMock.New;

            userManager.Setup(u => u.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(userId);

            var predictionService = new Mock <IPredictionService>();

            predictionService.Setup(p => p.GetCurrentActiveMatchesIds())
            .Returns(new List <int>()
            {
                firstMatch.Id, secondMatch.Id
            });

            predictionService.Setup(p => p.AddPrediction(null, null));
            var controller = new PredictionController(predictionService.Object, userManager.Object);

            controller.TempData = tempData.Object;

            // Act
            var result = controller.Bet(model);

            // Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            redirectToActionResult.ControllerName.Should().Be(null);
            redirectToActionResult.ActionName.Should().BeEquivalentTo("Bet");
            successMessage.Should().Be(MessageResources.msgSuccessfulPredictions);
        }
Exemplo n.º 3
0
        public void BetPostReturnViewWithModelWhenAnyNonPredictedMatch()
        {
            // Arrange
            string errorMessage        = null;
            ActiveRoundViewModel model = GetActiveRoundViewModel();
            var tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);


            var controller = new PredictionController(null, null);

            controller.TempData = tempData.Object;
            // Act
            var result = controller.Bet(model);

            // Assert
            result.Should().BeOfType <ViewResult>();

            var viewModel = result.As <ViewResult>().Model;

            viewModel.Should().BeOfType <ActiveRoundViewModel>();

            var formModel = viewModel.As <ActiveRoundViewModel>();

            formModel.AlreadyPredicted.Should().Be(false);
            formModel.Matches.Count.Should().Be(2);
            formModel.Matches.First().HomeTeam.Should().Be(firstMatch.HomeTeam);
            formModel.Matches.First().AwayTeam.Should().Be(firstMatch.AwayTeam);
            formModel.Matches.Last().HomeTeam.Should().Be(secondMatch.HomeTeam);
            formModel.Matches.Last().AwayTeam.Should().Be(secondMatch.AwayTeam);
            formModel.RoundNumber.Should().Be(RoundNumber);

            errorMessage.Should().Be(MessageResources.msgBetAllMatches);
        }