Exemplo n.º 1
0
        public void HydrateIndexModel(
            IndexModel indexModel)
        {
            indexModel.MembershipOptions = GetMembershipOptionModels();

            indexModel.CreditCardTypes = GetCreditCardTypes();
        }
        public void HydrateIndexModelShouldSetTheCreditCardTypesAndMembershipOptions()
        {
            var indexModel = new IndexModel();

            var membershipOffers = new MembershipOffer[0];

            _mockOrderRepository.Setup(
                repos => repos.GetAllActiveMembershipOffers())
                .Returns(membershipOffers);

            var membershipOptionModels = new MembershipOptionModel[0];

            _mockIndexModelMapper.Setup(
                mapper => mapper.MapDomainToModels(
                    membershipOffers))
                .Returns(membershipOptionModels);

            var selectListItems = new SelectListItem[0];

            _mockCreditCardListItemMapper.Setup(
                mapper => mapper.MapCreditCardsToListItems(
                    It.IsAny<CreditCardType[]>()))
                .Returns(selectListItems);

            _indexModelRepository.HydrateIndexModel(
                indexModel);

            Assert.That(indexModel.MembershipOptions, Is.EqualTo(membershipOptionModels));
            Assert.That(indexModel.CreditCardTypes, Is.EqualTo(selectListItems));
        }
Exemplo n.º 3
0
        public void SaveIndexModel(
            IndexModel indexModel)
        {
            var membershipOrder = _indexModelMapper.GetMembershipOrderForIndexModel(
                indexModel,
                _orderRepository);

            _orderRepository.SaveMembershipOrder(membershipOrder);
        }
Exemplo n.º 4
0
        public void IndexShouldRedirectToTheOrderSavedViewWhenModelIsValid()
        {
            var indexModel = new IndexModel();

            var actionResult = _homeController.Index(indexModel);

            var redirectResult = (RedirectToRouteResult)actionResult;

            Assert.That(redirectResult.RouteValues["action"],
                Is.EqualTo("OrderSaved"));
        }
        public void SaveIndexModelShouldSaveNewOrder()
        {
            var indexModel = new IndexModel();
            var membershipOrder = new MembershipOrder();

            _mockIndexModelMapper.Setup(
                mapper => mapper.GetMembershipOrderForIndexModel(
                    indexModel,
                    _mockOrderRepository.Object))
                .Returns(membershipOrder);

            _indexModelRepository.SaveIndexModel(
                indexModel);

            _mockOrderRepository.Verify(
                repos => repos.SaveMembershipOrder(
                    membershipOrder));
        }
Exemplo n.º 6
0
        public MembershipOrder GetMembershipOrderForIndexModel(
            IndexModel indexModel,
            IOrderRepository orderRepository)
        {
            var membershipOrderFactory = new MembershipOrderFactory();

            var membershipOrder = membershipOrderFactory.CreateMembershipOrder();

            membershipOrder.FirstName = indexModel.FirstName;
            membershipOrder.LastName = indexModel.LastName;
            membershipOrder.EmailAddress = indexModel.EmailAddress;

            if (indexModel.DateOfBirth.HasValue)
                membershipOrder.DateOfBirth = (DateTime)indexModel.DateOfBirth;

            membershipOrder.CreditCardNumber = indexModel.CreditCardNumber;
            membershipOrder.CreditCardType = CreditCardType.FromCode(indexModel.SelectedCreditCardType);
            membershipOrder.MembershipOffer =
                orderRepository.GetMembershipOfferById(indexModel.SelectedMembershipOption);

            return membershipOrder;
        }
Exemplo n.º 7
0
        public void GetMembershipOrderForIndexModelShouldReturnValidOrder()
        {
            var indexModel = new IndexModel();

            indexModel.FirstName = "firstname";
            indexModel.LastName = "lastname";
            indexModel.EmailAddress = "*****@*****.**";
            indexModel.DateOfBirth = new DateTime(2000, 1, 10);
            indexModel.CreditCardNumber = "9999999999";
            indexModel.SelectedCreditCardType = "VISA";
            indexModel.SelectedMembershipOption = 1;

            var membershipOrder = _indexModelMapper.GetMembershipOrderForIndexModel(
                indexModel,
                _orderRepositoryFake);

            Assert.That(indexModel.FirstName, Is.EqualTo(membershipOrder.FirstName));
            Assert.That(indexModel.LastName, Is.EqualTo(membershipOrder.LastName));
            Assert.That(indexModel.EmailAddress, Is.EqualTo(membershipOrder.EmailAddress));
            Assert.That(indexModel.DateOfBirth, Is.EqualTo(membershipOrder.DateOfBirth));
            Assert.That(indexModel.CreditCardNumber, Is.EqualTo(membershipOrder.CreditCardNumber));
            Assert.That(indexModel.SelectedCreditCardType, Is.EqualTo(membershipOrder.CreditCardType.Code));
            Assert.That(indexModel.SelectedMembershipOption, Is.EqualTo(membershipOrder.MembershipOffer.Id));
        }
Exemplo n.º 8
0
        public ActionResult Index(
            IndexModel indexModel)
        {
            if (!ModelState.IsValid)
            {
                _indexModelRepository.HydrateIndexModel(indexModel);

                return View(indexModel);
            }

            _indexModelRepository.SaveIndexModel(indexModel);

            return RedirectToAction("OrderSaved");
        }
Exemplo n.º 9
0
        public ViewResult Index()
        {
            var indexModel = new IndexModel();

            _indexModelRepository.HydrateIndexModel(indexModel);

            return View(indexModel);
        }
Exemplo n.º 10
0
        public void IndexShouldReturnTheSaveViewWhenModelIsInValid()
        {
            var indexModel = new IndexModel();

            SetModelStateOfContorllerAsInvalid();

            var actionResult = _homeController.Index(indexModel);

            _mockIndexModelRepository.Verify(
                repos => repos.HydrateIndexModel(
                    indexModel));

            Assert.That(actionResult, Is.TypeOf(typeof(ViewResult)));

            var viewResult = (ViewResult)actionResult;

            Assert.That(viewResult.ViewName, Is.EqualTo(""));
        }
Exemplo n.º 11
0
        public void IndexShouldSaveTheOrderWhenTheModelIsValid()
        {
            var indexModel = new IndexModel();

            _homeController.Index(indexModel);

            _mockIndexModelRepository.Verify(
                repos => repos.SaveIndexModel(
                    indexModel));
        }