예제 #1
0
        public void ReadCardThirdAttemptWrongPinTest()
        {
            var connection = EntityConnectionFactory.CreateTransient("name=Entities");

            using (var context = new Entities(connection))
            {
                CardReaderService cardReaderService = new CardReaderService(context);

                context.Cards.Add(new Card {
                    Id = 1, UserId = 1, CardNumber = "12345", Pin = 1234, Status = (int)CardStatus.Active
                });
                context.Users.Add(new User {
                    Id = 1, UserName = "******", LoginAttempt = 2, IsLoggedIn = false
                });
                context.AccountTypes.Add(new AccountType {
                    Id = 1, Name = AccounType.Current.ToString()
                });
                context.Accounts.Add(new Account {
                    Id = 1, AccountNumber = "1234", CardId = 1, AccountTypeId = 1, AmountAvailable = 500
                });
                context.SaveChanges();

                var getCard = cardReaderService.ReadCard("12345", 4564);

                Assert.AreEqual(Message.WrongPasswordRetainCard, getCard.UserMessage);
            }
        }
예제 #2
0
        public void ReadCardGoodPinTest()
        {
            var connection = EntityConnectionFactory.CreateTransient("name=Entities");

            using (var context = new Entities(connection))
            {
                CardReaderService cardReaderService = new CardReaderService(context);

                context.Cards.Add(new Card {
                    Id = 1, UserId = 1, CardNumber = "12345", Pin = 1234, Status = (int)CardStatus.Active
                });
                context.Users.Add(new User {
                    Id = 1, UserName = "******", LoginAttempt = 0, IsLoggedIn = false
                });
                context.AccountTypes.Add(new AccountType {
                    Id = 1, Name = AccounType.Current.ToString()
                });
                context.Accounts.Add(new Account {
                    Id = 1, AccountNumber = "1234", CardId = 1, AccountTypeId = 1, AmountAvailable = 500
                });
                context.SaveChanges();

                var getCard = cardReaderService.ReadCard("12345", 1234);
                var user    = context.Users.FirstOrDefault(x => x.Id == 1);

                Assert.AreEqual(Message.LoginSuccessful, getCard.UserMessage);
                Assert.AreEqual(true, getCard.IsLoggedIn);
                Assert.AreEqual(0, user.LoginAttempt);
            }
        }
예제 #3
0
        public void ReadCardFullWrongPinTest()
        {
            var connection = EntityConnectionFactory.CreateTransient("name=Entities");

            using (var context = new Entities(connection))
            {
                CardReaderService cardReaderService = new CardReaderService(context);

                context.Cards.Add(new Card {
                    Id = 1, UserId = 1, CardNumber = "12345", Pin = 1234, Status = (int)CardStatus.Active
                });
                context.Users.Add(new User {
                    Id = 1, UserName = "******", LoginAttempt = 0, IsLoggedIn = false
                });
                context.AccountTypes.Add(new AccountType {
                    Id = 1, Name = AccounType.Current.ToString()
                });
                context.Accounts.Add(new Account {
                    Id = 1, AccountNumber = "1234", CardId = 1, AccountTypeId = 1, AmountAvailable = 500
                });
                context.SaveChanges();

                var getCard = cardReaderService.ReadCard("12345", 4564);

                Assert.AreEqual(Message.WrongPasswordFirstAttempt, getCard.UserMessage);

                var getCard1 = cardReaderService.ReadCard("12345", 4564);

                Assert.AreEqual(Message.WrongPasswordSecondAttempt, getCard1.UserMessage);

                var getCard2 = cardReaderService.ReadCard("12345", 4564);

                Assert.AreEqual(Message.WrongPasswordRetainCard, getCard2.UserMessage);

                //Check card status after 3rd attempt
                var card = context.Cards.FirstOrDefault(x => x.CardNumber == "12345");

                Assert.AreEqual((int)CardStatus.Inactive, card.Status);

                var user = context.Users.FirstOrDefault(x => x.Id == 1);

                Assert.AreEqual(3, user.LoginAttempt);
            }
        }
예제 #4
0
        public ActionResult Login(CardViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Try to login
                CardReaderService cardReaderService = new CardReaderService();

                var cardViewModel = cardReaderService.ReadCard(model.CardNumber, model.Pin.Value);

                if (cardViewModel.IsLoggedIn)
                {
                    //Created a session and put the view model in it
                    Session["LogIn"]    = cardViewModel;
                    Session["UserName"] = cardViewModel.UserName;

                    return(RedirectToAction("Index", "Home"));
                }

                return(View(cardViewModel));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }