public void DeleteHand(CGUserModel userModel)
 {
     using (SqlConnection connection = new SqlConnection(conString)) {
         var sql = "DELETE FROM CardUser WHERE cguser_id = @id";
         connection.Execute(sql, userModel);
     }
 }
示例#2
0
        public void GetCardsByUserIdTest()
        {
            cardDB = new CardDB();
            var testCard1 = new CardModel(CardModel.CardType.DEFENSE, "Attack UpdateTest card", "It can attack", 2);
            var testCard2 = new CardModel(CardModel.CardType.DEFENSE, "Attack UpdateTest card", "It can attack", 2);
            var testCard3 = new CardModel(CardModel.CardType.DEFENSE, "Attack UpdateTest card", "It can attack", 2);
            var testCard4 = new CardModel(CardModel.CardType.DEFENSE, "Attack UpdateTest card", "It can attack", 2);
            var testCard5 = new CardModel(CardModel.CardType.DEFENSE, "Attack UpdateTest card", "It can attack", 2);

            testCard1.Id = cardDB.InsertWithIdentity(testCard1);
            testCard2.Id = cardDB.InsertWithIdentity(testCard2);
            testCard3.Id = cardDB.InsertWithIdentity(testCard3);
            testCard4.Id = cardDB.InsertWithIdentity(testCard4);
            testCard5.Id = cardDB.InsertWithIdentity(testCard5);
            List <CardModel> cards = new List <CardModel>()
            {
                testCard1, testCard2, testCard3, testCard4, testCard5
            };
            ICGUserDBIF userDB = new CGUserDB();
            CGUserModel user   = userDB.GetById("Test");

            userDB.InsertHand(cards, user);
            List <CardModel> cardList = (List <CardModel>)cardDB.GetCardsByUserId("Test");

            Assert.IsTrue(cardList.Count > 0);
            userDB.DeleteHand(user);
            cardDB.Delete(testCard1);
            cardDB.Delete(testCard2);
            cardDB.Delete(testCard3);
            cardDB.Delete(testCard4);
            cardDB.Delete(testCard5);
        }
 public void Update(CGUserModel user)
 {
     using (SqlConnection connection = new SqlConnection(conString)) {
         var sql = "UPDATE CGUser SET userName = @userName, email = @email, userType = @userType, userStatus = @userStatus WHERE id = @id;";
         connection.Execute(sql, user);
     }
 }
 public void Insert(CGUserModel user)
 {
     using (SqlConnection connection = new SqlConnection(conString)) {
         var sql = "INSERT INTO CGUser (id, userName, email, userType, userStatus) VALUES (@id, @userName, @email, @userType, @userStatus);";
         connection.Execute(sql, user);
     }
 }
        public void GetUserByEmailTest()
        {
            cgUserDB = new CGUserDB();
            CGUserModel test = cgUserDB.GetUserByEmail("*****@*****.**");

            Assert.AreEqual("*****@*****.**", test.Email);
        }
 public void UpdateUserTableId(CGUserModel user, int tableId)
 {
     using (SqlConnection connection = new SqlConnection(conString)) {
         var sql = "UPDATE CGUser SET tableId = @tableId WHERE id = @id;";
         connection.Execute(sql, new { id = user.Id, tableId });
     }
 }
        public void GetByIdTest()
        {
            cgUserDB = new CGUserDB();
            CGUserModel test = cgUserDB.GetById("Test");

            Assert.AreEqual("Test", test.Id);
        }
        public void DeleteTest()
        {
            //Arrange
            CGUserManagementServiceAccess cGUserServiceAccess = new CGUserManagementServiceAccess();
            CGUserModel userModel = new CGUserModel {
                Id       = "Test2",
                Email    = "*****@*****.**",
                UserName = "******"
            };

            cGUserServiceAccess.CreateUser("Test2", "*****@*****.**", "TestUser");
            List <CGUserModel> users = cGUserServiceAccess.GetAll();

            foreach (var user in users)
            {
                if (user.UserName == "TestUser")
                {
                    userModel = user;
                }
            }
            bool res = false;

            //Act
            res = cGUserServiceAccess.DeleteCGUser(userModel);

            //Assert
            Assert.IsTrue(res);
        }
        public void InsertHandTest()
        {
            //Arrange
            cgUserDB = new CGUserDB();
            CardDB cardDB = new CardDB();
            //Act
            var userModel = cgUserDB.GetById("Test");
            List <CardModel> cardsOnHand         = cardDB.GetCardsByDeckId(2);
            List <CardModel> filteredCardsOnHand = new List <CardModel>();

            for (int i = 0; i < 5; i++)
            {
                CardModel card = cardsOnHand[i];
                filteredCardsOnHand.Add(card);
            }
            cgUserDB.InsertHand(filteredCardsOnHand, userModel);
            CGUser user = CGUserConverter.convertFromCGUserModelToCGUser(cgUserDB.GetById("Test"));

            //Assert
            Assert.IsTrue(user.cards.Count > 0);
            //CleanUp
            CGUserModel revertedUser = CGUserConverter.ConvertFromCGUserToCGUserModel(user);

            cgUserDB.DeleteHand(revertedUser);
        }
        public void GetByUserNameTest()
        {
            cgUserDB = new CGUserDB();
            CGUserModel testUser = cgUserDB.GetByUserName("Test");

            Assert.AreEqual("Test", testUser.UserName);
        }
        public void DeleteTest()
        {
            //Arrange
            GameTableServiceAccess gameTableServiceAccess = new GameTableServiceAccess();
            CGUserModel            userModel = new CGUserModel {
                Id       = "Test",
                Email    = "*****@*****.**",
                UserName = "******"
            };
            GameTableModel tableModel = null;

            gameTableServiceAccess.CreateGameTable(userModel, "TestTable");
            List <GameTableModel> tables = gameTableServiceAccess.GetAll();

            foreach (var table in tables)
            {
                if (table.TableName == "TestTable")
                {
                    tableModel = table;
                }
            }
            bool res = false;

            //Act
            res = gameTableServiceAccess.Delete(tableModel.Id);


            //Assert
            Assert.IsTrue(res);
        }
示例#12
0
 public bool DeleteCGUser(CGUserModel user)
 {
     using (UserManagementServiceClient proxy = new UserManagementServiceClient()) {
         CGUser cgU = CGUserModelConverter.ConvertFromClientUserToServiceUser(user);
         proxy.DeleteHand(cgU);
         return(proxy.DeleteCGUser(cgU));
     }
 }
        public void GetUserTableIdTest()
        {
            cgUserDB = new CGUserDB();
            CGUserModel testUser = cgUserDB.GetById("Test");
            var         attempt  = cgUserDB.GetUserTableId("Test");

            Assert.AreEqual(attempt, testUser.TableID);
        }
示例#14
0
 public GameTableModel CreateGameTable(CGUserModel userModel, string tableName)
 {
     using (GameTableManagementServiceClient proxy = new GameTableManagementServiceClient()) {
         GameTableModel tableModel = null;
         CGUser         user       = GameTableModelConverter.ConvertFromClientUserToServiceUser(userModel);
         tableModel = GameTableModelConverter.ConvertFromServiceGameTableToClientGameTable(proxy.CreateGameTable(user, tableName));
         return(tableModel);
     }
 }
        public void UpdateTableSeats(CGUserModel user, int amount)
        {
            IGameTableDBIF gameTableDB = new GameTableDB();
            GameTableModel gameTable   = gameTableDB.GetById(user.TableID);

            if (gameTable != null)
            {
                gameTableDB.UpdateGameTableSeats(gameTable, amount);
            }
        }
 public void InsertHand(List <CardModel> cards, CGUserModel user)
 {
     using (SqlConnection connection = new SqlConnection(conString)) {
         var sql = "Insert into CardUser (cgUser_id , card_id) VALUES (@id, @cardId)";
         foreach (var card in cards)
         {
             connection.Execute(sql, new { id = user.Id, cardId = card.Id });
         }
     }
 }
        public void DeleteTest()
        {
            cgUserDB = new CGUserDB();
            var bob = new CGUserModel("bob", "*****@*****.**", CGUserModel.UserType.PLAYER, CGUserModel.UserStatus.INGAME);

            bob.Id = "asdfg09876";
            cgUserDB.Insert(bob);
            cgUserDB.Delete(bob);
            bob = cgUserDB.GetById("asdfg09876");
            Assert.IsNull(bob);
        }
示例#18
0
 public CGUser GetCGUserByUserName(string userName)
 {
     if (userName == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel userModel = cGUserDB.GetByUserName(userName);
         return(CGUserConverter.convertFromCGUserModelToCGUser(userModel));
     }
 }
示例#19
0
 public void UpdateUserTableId(CGUser user, int tableId)
 {
     if (user == null || tableId == 0)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel userModel = CGUserConverter.ConvertFromCGUserToCGUserModel(user);
         cGUserDB.UpdateUserTableId(userModel, tableId);
     }
 }
示例#20
0
 public void UpdateUser(CGUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel userModel = CGUserConverter.ConvertFromCGUserToCGUserModel(user);
         cGUserDB.Update(userModel);
     }
 }
示例#21
0
 public CGUser GetUserByUserId(string id)
 {
     if (id == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel userModel = cGUserDB.GetById(id);
         return(CGUserConverter.convertFromCGUserModelToCGUser(userModel));
     }
 }
        /* This method is called when a user want to join a GameTable.
         * It checks wether or notthe table is already full and if it is the user cannot join the table.
         * if a user is successfull in joining a table, a seat is subtracted from the seat count,
         * such that the it can keep track of how many users have joined the table
         */
        public GameTable JoinGameTable(CGUser user, GameTable chosenTable)
        {
            if (user == null || chosenTable == null)
            {
                throw new ArgumentNullException();
            }
            else
            {
                GameTable      databaseTable = null;
                GameTableModel modelTable    = null;
                CGUserModel    userModel     = CGUserConverter.ConvertFromCGUserToCGUserModel(user);
                //Checking if the user is already sitting at the table and returning it without modifying if so.
                for (int i = 0; i < chosenTable.Users.Count; i++)
                {
                    if (userModel.UserName == chosenTable.Users[i].UserName)
                    {
                        return(chosenTable);
                    }
                }
                TransactionOptions transOptions = new TransactionOptions();
                transOptions.IsolationLevel = IsolationLevel.ReadUncommitted;
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transOptions)) {
                    //Checking if the user is sitting at another table.
                    if (userModel.TableID != 0 && userModel.TableID != chosenTable.Id)
                    {
                        modelTable = gameTableDB.GetById(userModel.TableID);
                    }
                    //Getting the table from the database for later comparison.
                    databaseTable = GameTableConverter.ConvertFromGameTableModelToGameTable(gameTableDB.GetById(chosenTable.Id));
                    //Optimistically handling concurrency by checking if the seats available at the chosen table
                    //are the same as the seats available in the database, if not we throw an exception.
                    if (chosenTable.seats == databaseTable.seats && databaseTable.seats > 0)
                    {
                        userManagement.UpdateUserTableId(user, databaseTable.Id);
                        databaseTable.Users.Add(user);
                        UpdateGameTableSeats(databaseTable, 1);
                        //If the user was sitting at another table we free up the seat.
                        if (modelTable != null)
                        {
                            gameTableDB.UpdateGameTableSeats(modelTable, -1);
                        }
                    }
                    else
                    {
                        throw new Exception("Table busy");
                    }
                    Thread.Sleep(2000);
                    scope.Complete();
                }

                return(databaseTable);
            }
        }
示例#23
0
 public void DeleteHand(CGUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel userModel = CGUserConverter.ConvertFromCGUserToCGUserModel(user);
         cGUserDB.DeleteHand(userModel);
     }
 }
        public void InsertTest()
        {
            cgUserDB = new CGUserDB();
            var bob = new CGUserModel("bob", "*****@*****.**", CGUserModel.UserType.PLAYER, CGUserModel.UserStatus.STUNNED);

            bob.Id = "qwerty12345678";
            cgUserDB.Insert(bob);
            var anders2 = cgUserDB.GetById("qwerty12345678");

            Assert.AreEqual(bob.UserName, anders2.UserName);
            cgUserDB.Delete(bob);
        }
示例#25
0
 public void SaveHand(List <Card> cards, CGUser user)
 {
     if (cards == null || user == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         List <CardModel> cardModels = CardConverter.ConvertFromListOfCardToListOfCardModel(cards);
         CGUserModel      userModel  = CGUserConverter.ConvertFromCGUserToCGUserModel(user);
         cGUserDB.InsertHand(cardModels, userModel);
     }
 }
示例#26
0
 public void CreateUser(string id, string email, string userName)
 {
     if (id == null || email == null || userName == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         CGUserModel user = new CGUserModel();
         user.Email    = email;
         user.Id       = id;
         user.UserName = userName;
         cGUserDB.Insert(user);
     }
 }
        public void Delete(CGUserModel user)
        {
            using (TransactionScope scope = new TransactionScope()) {
                using (SqlConnection connection1 = new SqlConnection(conString)) {
                    var sql = "DELETE FROM CGUser WHERE id = @id;";
                    connection1.Execute(sql, user);

                    using (SqlConnection connection2 = new SqlConnection(clientConString)) {
                        var sqlClient = "Delete FROM AspNetUsers WHERE id = @id;";
                        connection2.Execute(sqlClient, user);
                    }
                }
                scope.Complete();
            }
        }
示例#28
0
        private void listBoxCGUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            DeleteUserlabel.Text = "";
            string userName = listBoxCGUsers.Text;

            //string userId = cGUserText.Substring(0, 40);
            CGUserNameTextBox.Text = userName;
            CGUserModel cgu = cGUserController.GetUserByUserName(userName);

            if (cgu != null)
            {
                CGUserIdTextBox.Text    = cgu.Id;
                CGUserEmailTextBox.Text = cgu.Email;
            }
        }
        public void UpdateUserTableIdTest()
        {
            ICGUserDBIF cgUserDB = new CGUserDB();
            CGUserModel user     = cgUserDB.GetById("Test");

            if (user.TableID == 999)
            {
                cgUserDB.UpdateUserTableId(user, 998);
            }
            else
            {
                cgUserDB.UpdateUserTableId(user, 999);
            }
            CGUserModel user2 = cgUserDB.GetById("Test");

            Assert.AreNotEqual(user.TableID, user2.TableID);
        }
        public static CGUser convertFromCGUserModelToCGUser(CGUserModel cGUserModel)
        {
            ICardDBIF        cardDB    = new CardDB();
            List <CardModel> userCards = cardDB.GetCardsByUserId(cGUserModel.Id);
            CGUser           cGUser    = new CGUser()
            {
                Id         = cGUserModel.Id,
                UserName   = cGUserModel.UserName,
                Email      = cGUserModel.Email,
                userType   = (CGUser.UserType)cGUserModel.userType,
                userStatus = (CGUser.UserStatus)cGUserModel.userStatus,
                Health     = cGUserModel.Health,
                cards      = CardConverter.ConvertFromListOfCardModelToListOfCard(userCards)
            };

            return(cGUser);
        }