Exemple #1
0
 public void AssignConsoleForMembership(Membership membership, Game game)
 {
     game.MembershipId = membership.MembershipId;
     gameRepository.Add(game);
     membership.AddGame(game);
     membershipRepository.Update(membership);
 }
        public void AssignConsoleForMembership_update_added_game_with_membership_id()
        {
            var membership = new Membership();
            var game = new Game();

            gameService.AssignConsoleForMembership(membership, game);

            game.MembershipId.ShouldEqual(membership.MembershipId);
        }
        public void Returns_Membership_View_with_model_error_if_membership_is_expired()
        {
            var membership = new Membership();
            MembershipRepositoryMock.Setup(repo => repo.FindByMembershipId(membershipId)).Returns(membership);

            var viewResult = MembershipController.Membership(membershipId, CustomUserIdentity);

            viewResult.ViewName.ShouldEqual(string.Empty);
            AssertModelError(MembershipController, "membershipId", "Membership Id is expired. Kindly recharge.");
        }
        public void AssignConsoleForMembership_adds_game_in_game_repository()
        {
            var membership = new Membership();
            var game = new Game();
            gameRepositoryMock.Setup(repo => repo.Add(game)).Verifiable();

            gameService.AssignConsoleForMembership(membership, game);

            gameRepositoryMock.Verify(repo => repo.Add(game));
            game.MembershipId.ShouldEqual(membership.MembershipId);
        }
        public void if_membership_id_exists_Retrieves_GamingConsoles_of_user_branch_from_repository_and_put_them_in_ViewBag()
        {
            var membership = new Membership();
            membership.Recharge(new MembershipReCharge { Hours = 5 });
            MembershipRepositoryMock.Setup(repo => repo.FindByMembershipId(membershipId)).Returns(membership);
            SetUpRepositoryWithGamingConsoles();

            var viewResult = MembershipController.Membership(membershipId, CustomUserIdentity);

            AssertGamingConsolesInViewBag(viewResult);
        }
        public void AssignConsoleForMembership_updates_membership_with_the_game_passed()
        {
            var membership = new Membership();
            var game = new Game();
            membershipRepositoryMock.Setup(repo => repo.Update(membership)).Verifiable();

            gameService.AssignConsoleForMembership(membership, game);

            membership.Games.Count.ShouldEqual(1);
            membership.Games.First().ShouldEqual(game);
            membershipRepositoryMock.Verify(repo => repo.Update(membership));
            game.MembershipId.ShouldEqual(membership.MembershipId);
        }
        public void ForMembershipGame_MarkGameAsInvalid_invalidate_both_game_and_game_in_membership()
        {
            var membership = new Membership();
            var game = new Game {MembershipId = membership.MembershipId};
            membership.AddGame(game);
            membershipRepositoryMock.Setup(repo => repo.FindByMembershipId(membership.MembershipId)).Returns(membership);
            gameRepositoryMock.Setup(repo => repo.GetById(game.Id)).Returns(game);
            gameRepositoryMock.Setup(repo => repo.Update(game)).Verifiable();
            membershipRepositoryMock.Setup(repo => repo.Update(membership)).Verifiable();

            gameService.MarkGameAsInvalid(game.Id);

            gameRepositoryMock.Verify(repo => repo.Update(game));
            membershipRepositoryMock.Verify(repo => repo.Update(membership));
            game.IsValid.ShouldBeFalse();
        }
        public ViewResult Create(Membership membership)
        {
            if (!ModelState.IsValid)
            {
                return View(membership);
            }

            if (membershipRepository.IsCustomer1ContactNumberExists(membership.Customer1ContactNumber))
            {
                ModelState.AddModelError("Customer1ContactNumber", "Customer 1 Contact Number already exists.");
                return View(membership);
            }

            membershipRepository.Add(membership);
            return View("MembershipCreated", membership);
        }
        public void Returns_AssignConsole_view_with_membership_assign_console_ViewModel_if_membership_id_exists()
        {
            var membership = new Membership();
            membership.Recharge(new MembershipReCharge { Hours = 5 });
            MembershipRepositoryMock.Setup(repo => repo.FindByMembershipId(membershipId)).Returns(membership);

            var viewResult = MembershipController.Membership(membershipId, CustomUserIdentity);

            viewResult.ViewName.ShouldEqual("AssignConsole");
            var membershipAssignConsoleViewModel = viewResult.Model as MembershipAssignConsoleViewModel;
            membershipAssignConsoleViewModel.Game.ShouldNotBeNull();
            membershipAssignConsoleViewModel.Game.Price.ShouldEqual(0);
            membershipAssignConsoleViewModel.Game.GamePaymentType.ShouldEqual(GamePaymentType.Membership);
            membershipAssignConsoleViewModel.Game.BranchName.ShouldEqual(CustomUserIdentity.BranchName);
            membershipAssignConsoleViewModel.Membership.ShouldEqual(membership);
        }
        public void If_model_state_is_valid_assign_console_using_game_service_and_redirect_to_game_index()
        {
            var dateTime = DateTime.UtcNow.ToIST();
            membershipAssignConsoleViewModel.Game.InTime = dateTime;
            membershipAssignConsoleViewModel.Game.OutTime = dateTime.AddHours(1.5);
            var membership = new Membership();
            membership.Recharge(new MembershipReCharge { Hours = 2 });
            MembershipRepositoryMock
                .Setup(repo => repo.FindByMembershipId(membershipAssignConsoleViewModel.Membership.MembershipId))
                .Returns(membership);
            GameServiceMock.Setup(service => service.AssignConsoleForMembership(membership, membershipAssignConsoleViewModel.Game)).Verifiable();

            var actionResult = MembershipController.AssignConsole(membershipAssignConsoleViewModel);

            GameServiceMock.Verify(service => service.AssignConsoleForMembership(membership, membershipAssignConsoleViewModel.Game));
            AssertReadirectToAction(actionResult, "Index", "Game");
            MembershipController.TempData["Message"].ShouldEqual("Game assigned to membership successfully");
        }
        public void If_game_hours_is_greater_than_membership_remaining_hours_return_Assign_Console_View_with_model_error()
        {
            var dateTime = DateTime.UtcNow.ToIST();
            membershipAssignConsoleViewModel.Game.InTime = dateTime;
            membershipAssignConsoleViewModel.Game.OutTime = dateTime.AddHours(1.5);
            var membership = new Membership();
            membership.Recharge(new MembershipReCharge { Hours = 1});
            SetUpRepositoryWithGamingConsoles();
            MembershipRepositoryMock
                .Setup(repo => repo.FindByMembershipId(membershipAssignConsoleViewModel.Membership.MembershipId))
                .Returns(membership);

            var viewResult = MembershipController.AssignConsole(membershipAssignConsoleViewModel) as ViewResult;

            AssertGamingConsolesInViewBag(viewResult);
            AssertModelError(MembershipController, "Game", "Membership has only " + membership.RemainingHours + " hours. Please recharge!");
            viewResult.ViewName.ShouldEqual(string.Empty);
        }
 public void SetUp()
 {
     membership = new Membership();
 }
 public void SetUp()
 {
     membershipDetaiRequestViewModel = new MembershipDetaiRequestViewModel();
     membership = new Membership();
 }
 public MembershipAssignConsoleViewModel()
 {
     Game = new Game();
     Membership = new Membership();
 }