Esempio n. 1
0
        public void TestUserMethods()
        {
            PasswordHelper passHelper = new PasswordHelper("Abcd!234");
            StockGameDAL   _dal       = new StockGameDAL(_connectionString);

            // Test add user
            UserItem item = new UserItem();

            item.FirstName = "Chris";
            item.LastName  = "Rupp";
            item.Username  = "******";
            item.Hash      = passHelper.Hash;
            item.Salt      = passHelper.Salt;
            item.Email     = "*****@*****.**";
            item.RoleId    = (int)RoleManager.eRole.Player;
            int id = _dal.AddUserItem(item);

            Assert.AreNotEqual(0, id);

            UserItem itemGet = _dal.GetUserItem(id);

            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.FirstName, itemGet.FirstName);
            Assert.AreEqual(item.LastName, itemGet.LastName);
            Assert.AreEqual(item.Username, itemGet.Username);
            Assert.AreEqual(item.Hash, itemGet.Hash);
            Assert.AreEqual(item.Salt, itemGet.Salt);
            Assert.AreEqual(item.Email, itemGet.Email);

            // Test update user
            item.FirstName = "What";
            item.LastName  = "What";
            item.Username  = "******";
            item.Email     = "What";
            item.Hash      = "What";
            item.Salt      = "What";
            Assert.IsTrue(_dal.UpdateUserItem(item));

            itemGet = _dal.GetUserItem(id);
            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.FirstName, itemGet.FirstName);
            Assert.AreEqual(item.LastName, itemGet.LastName);
            Assert.AreEqual(item.Username, itemGet.Username);
            Assert.AreEqual(item.Hash, itemGet.Hash);
            Assert.AreEqual(item.Salt, itemGet.Salt);
            Assert.AreEqual(item.Email, itemGet.Email);

            // Test delete user
            _dal.DeleteUserItem(id);
            var users = _dal.GetUserItems();

            foreach (var user in users)
            {
                Assert.AreNotEqual(id, user.Id);
            }
        }
Esempio n. 2
0
        public void UpdateStocks()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);

            //Act
            bool test = _dal.UpdateStocks();

            //Assert
            Assert.IsTrue(test);
        }
Esempio n. 3
0
        public void AvailableStocks()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);

            //Act
            List <Stock> test = _dal.AvailableStocks();

            //Assert
            Assert.IsNotNull(test);
        }
Esempio n. 4
0
        public void GetCashAmounts()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);


            //Act
            List <UserCash> test = _dal.GetCashAmounts();

            //Assert
            Assert.IsNotNull(test);
        }
Esempio n. 5
0
        public void GetUserIdByUsername()
        {
            //Arrange
            StockGameDAL _dal     = new StockGameDAL(_connectionString);
            string       username = "******";

            //Act
            int test = _dal.GetUserIdByUsername(username);

            //Assert
            Assert.AreEqual(_userId2, test);
        }
Esempio n. 6
0
        public void UsersPlaying()
        {
            //Arrange
            StockGameDAL _dal   = new StockGameDAL(_connectionString);
            int          gameId = 3;

            //Act
            List <UserItem> test = _dal.UsersPlaying(gameId);

            //Assert
            Assert.IsNotNull(test);
        }
Esempio n. 7
0
        public void UserStocks()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);
            //int userId = 1;
            int userId = _userId2;

            //Act
            List <UserStockItem> test = _dal.UserStocks(userId);

            //Assert
            Assert.IsNotNull(test);
        }
Esempio n. 8
0
        public void SellStock()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);
            //int userId = 1;
            int userId  = _userId2;
            int stockId = 1;
            int shares  = 1;

            //Act
            bool test = _dal.SellStock(userId, stockId, shares);

            //Assert
            Assert.IsTrue(test);
        }
Esempio n. 9
0
        public void NewGame()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);
            Game         game = new Game()
            {
                TimeStarted = DateTime.Now,
                Duration    = 10
            };

            //Act
            int test = _dal.NewGame(game);

            //Assert
            Assert.IsNotNull(test);
        }
Esempio n. 10
0
        public void Initialize()
        {
            _tran = new TransactionScope();
            StockGameDAL   _dal       = new StockGameDAL(_connectionString);
            PasswordHelper passHelper = new PasswordHelper("Abcd!234");

            if (_userId1 == -1)
            {
                var temp = new UserItem()
                {
                    Id = -1
                };
                temp.FirstName = "Amy";
                temp.LastName  = "Rupp";
                temp.Username  = "******";
                temp.Hash      = passHelper.Hash;
                temp.Salt      = passHelper.Salt;
                temp.Email     = "*****@*****.**";
                temp.RoleId    = (int)RoleManager.eRole.Player;

                // Add user item
                _userId1 = _dal.AddUserItem(temp);
                Assert.AreNotEqual(0, _userId1);
            }

            if (_userId2 == -1)
            {
                var temp = new UserItem()
                {
                    Id = -1
                };
                temp.FirstName = "Chloe";
                temp.LastName  = "Rupp";
                temp.Username  = "******";
                temp.Hash      = passHelper.Hash;
                temp.Salt      = passHelper.Salt;
                temp.Email     = "*****@*****.**";
                temp.RoleId    = (int)RoleManager.eRole.Player;

                // Add user item
                _userId2 = _dal.AddUserItem(temp);
                Assert.AreNotEqual(0, _userId2);
            }
        }
Esempio n. 11
0
        public void AddUserGame()
        {
            //Arrange
            StockGameDAL _dal = new StockGameDAL(_connectionString);
            Game         game = new Game()
            {
                TimeStarted = DateTime.Now,
                Duration    = 10
            };

            int _gameId = _dal.NewGame(game);

            //int userId = 9;
            int userId = _userId2;
            //int gameId = 2;
            int gameId = _gameId;

            //Act
            bool test = _dal.AddUserGame(userId);

            //Assert
            Assert.IsTrue(test);
        }
Esempio n. 12
0
        public void WipeUserGame()
        {
            //Lucas - works if data is in database


            //Arrange
            StockGameDAL _dal   = new StockGameDAL(_connectionString);
            int          userId = _userId2;
            Game         game   = new Game()
            {
                TimeStarted = DateTime.Now,
                Duration    = 10
            };
            int _gameId = _dal.NewGame(game);

            _dal.AddUserGame(userId);
            //int gameId = 2;

            //Act
            bool test = _dal.WipeUserGame(_gameId);

            //Assert
            Assert.IsTrue(test);
        }