public ActionResult Create(DeckViewModel deckVM)
        {
            if (ModelState.IsValid)
            {
                repo.Add(ToModel(deckVM));
                repo.Save();
                return(RedirectToAction("Index"));
            }

            return(View(deckVM));
        }
        public void UserCanChangePassword()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var cardRepository = new CardRepository(Session);
            var deckRepository = new DeckRepository(Session);

            var card = new Card("A", "B", "C", CardRarity.Special, "D", "E");
            var deck = new Deck("F");
            var user = new User("*****@*****.**", "Appie", userRepository);

            deck.Cards.Add(card);
            deck.Cards.Add(card);
            user.Decks.Add(deck);
            user.Cards.Add(card);

            Session.BeginTransaction();

            userRepository.CreateNewUser(user, "test123");
            cardRepository.Save(card);
            deckRepository.Save(deck);

            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Evict(user);
            Session.Clear();

            var userFromRepository = userRepository.Get(user.Id);

            var message = userRepository.ChangePassword(userFromRepository.Email, "test123", "etende", "etende");

            Assert.AreEqual(message, ChangePassswordMessage.PasswordChanged);
        }
예제 #3
0
        public void CanCreateDeck()
        {
            var deckRepository = new DeckRepository(Session);
            var cardRepository = new CardRepository(Session);
            var card           = new Card("A", "type", "m14", CardRarity.Special, "Barry", "nowhere");
            var deck           = new Deck("DeckName");

            deck.Cards.Add(card);

            Session.BeginTransaction();
            cardRepository.Save(card);
            deckRepository.Save(deck);
            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Clear();

            var deckFromRepository = deckRepository.Get(deck.Id);

            Assert.AreEqual("DeckName", deckFromRepository.Name);
            Assert.AreEqual(1, deckFromRepository.Cards.Count);
        }
        public void CanAddDeckToMultipleUsers()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var deckRepository = new DeckRepository(Session);

            var deck = new Deck("DeckName");

            var user1 = new User("*****@*****.**", "Robin van der Knaap", userRepository);

            user1.Decks.Add(deck);

            var user2 = new User("*****@*****.**", "Erwin Bonnet", userRepository);

            user2.Decks.Add(deck);

            Session.BeginTransaction();

            deckRepository.Save(deck);

            userRepository.CreateNewUser(user1, "test123");
            userRepository.CreateNewUser(user2, "test123");

            Session.Transaction.Commit();

            Session.Evict(deck);
            Session.Evict(user1);
            Session.Evict(user2);
            Session.Clear();

            var userFromDatabase1 = userRepository.Get(user1.Id);
            var userFromDatabase2 = userRepository.Get(user2.Id);

            Assert.AreEqual(1, userFromDatabase1.Decks.Count);
            Assert.AreEqual(1, userFromDatabase2.Decks.Count);
            Assert.AreEqual(deck, userFromDatabase1.Decks.First());
            Assert.AreEqual(deck, userFromDatabase2.Decks.First());
        }
        public void CanRegisterUser()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var cardRepository = new CardRepository(Session);
            var deckRepository = new DeckRepository(Session);

            var card = new Card("A", "B", "C", CardRarity.Special, "D", "E");
            var deck = new Deck("F");
            var user = new User("*****@*****.**", "Appie", userRepository);

            deck.Cards.Add(card);
            deck.Cards.Add(card);
            user.Decks.Add(deck);
            user.Cards.Add(card);

            Session.BeginTransaction();

            userRepository.CreateNewUser(user, "test123");
            cardRepository.Save(card);
            deckRepository.Save(deck);

            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Evict(user);
            Session.Clear();

            var userFromRepository = userRepository.Get(user.Id);

            Assert.AreEqual(user.DisplayName, userFromRepository.DisplayName);
            Assert.AreEqual(userFromRepository.Decks[0].Cards.Count, deck.Cards.Count);
            Assert.AreEqual(userFromRepository.Cards.Count, 1);
            Assert.AreEqual(userRepository.AuthenticateUser(userFromRepository.Email, "test123"), AuthenticateMessages.AuthenticationSuccessfull);
            Assert.AreEqual(userRepository.AuthenticateUser("*****@*****.**", "blaat"), AuthenticateMessages.UsernameDoesNotExist);
            Assert.AreEqual(userRepository.AuthenticateUser(userFromRepository.Email, "tester"), AuthenticateMessages.WrongEmailOrPassword);
        }