public void AddingUsersToAListThroughUseOfObjectAccessorsShouldReturnStringValueOfUser()
        {
            // Arrange
            Mock <IUser> mockUser = new Mock <IUser>();

            mockUser.Setup(r => r.UserName).Returns("Chillin");
            IUserAdministration sut = new UserAdministration(mockUser.Object, database);

            // Act
            List <string> test = (List <String>)sut.GetValues();

            // Assert
            Assert.AreEqual("Chillin", test[0]);
        }
        public void MethodAddUserShouldReturnTrueIfPasswordAndConfirmPasswordMatch()
        {
            // Arrange
            Mock <IUserTable> mockDatabase = new Mock <IUserTable>();

            mockDatabase.Setup(r => r.TableName).Returns("Table Name");
            mockDatabase.Setup(r => r.InsertRowIntoTable("Table Name", It.IsAny <IDataEntry>()));
            IUserAdministration sut = new UserAdministration(user, mockDatabase.Object);

            // Act
            Boolean test = sut.AddUser("Bob", "*****@*****.**", "password", "password", "score");

            // Assert
            Assert.AreEqual(true, test);
        }
Пример #3
0
        /// <summary>
        /// writes/updates/saves the users score to the database
        /// </summary>
        public void SaveScoreToDatabase()
        {
            IUserAdministration admin = new UserAdministration();

            for (int i = 0; i < database.RetrieveNumberOfRowsInTable(); i++)
            {
                string   tableRow = database.RetrieveTableRow(database.TableName, i);
                string[] split    = tableRow.Split(separator: '\n');

                if (user.UserName.Equals(split[0]))
                {
                    admin.DeleteUser(i);
                    admin.AddUser(user.UserName, user.Email, user.Password, user.Password, user.Score);
                }
            }
        }
        public void ListingTheUsersInTheDatabaseShouldListThemAllAndShouldListTheirProperValuesInOrderFromAnIUserList()
        {
            // Arrange
            Mock <IUserTable> mockDatabase = new Mock <IUserTable>();

            mockDatabase.Setup(r => r.RetrieveNumberOfRowsInTable()).Returns(4);
            mockDatabase.Setup(r => r.TableName).Returns("Table Name");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 1)).Returns("Billy \ntest\ntest\ntest");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 2)).Returns("TomTom \ntest\ntest\ntest");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 3)).Returns("Eernest \ntest\ntest\ntest");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 4)).Returns("Thor\ntest\ntest\ntest");
            IUserAdministration sut = new UserAdministration(user, mockDatabase.Object);

            // Act
            List <IUser> test = (List <IUser>)sut.ListUsers();

            // Assert
            Assert.AreEqual("Billy TomTom Eernest Thor", test[0].UserName + test[1].UserName + test[2].UserName + test[3].UserName);
        }
        public void MethodForDeletingAUserShouldFirstRetrieveARowFromDatabaseThenAccessOnlyTheUserColumnStringInOrderToEnterItAsTheArgumentForMethodDeleteRowFromTable()
        {
            // Arrange
            string            query        = null;
            Mock <IUserTable> mockDatabase = new Mock <IUserTable>();

            mockDatabase.Setup(r => r.TableName).Returns("Table Name");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 1)).Returns("Huey \n [email protected]\nred\n35");
            mockDatabase.Setup(r => r.DeleteRowFromTable(It.IsAny <string>())).Callback <string>((s1) =>
            {
                query = s1;
            });
            IUserAdministration sut = new UserAdministration(user, mockDatabase.Object);

            // Act
            sut.DeleteUser(1);

            //Assert
            Assert.AreEqual("Huey ", query);
        }
        public void MethodAddUserShouldModifyTheFieldsOfTheClassItIsInAndThenPassItsOwnClassObjectAsAnArgumentToMethodInsertRowIntoTable()
        {
            // Arrange
            IDataEntry        test         = null;
            Mock <IUserTable> mockDatabase = new Mock <IUserTable>();

            mockDatabase.Setup(r => r.TableName).Returns("Table Name");
            mockDatabase.Setup(r => r.InsertRowIntoTable("Table Name", It.IsAny <IDataEntry>())).Callback <string, IDataEntry>((s1, s2) =>
            {
                test = s2;
            });
            IUserAdministration sut = new UserAdministration(user, mockDatabase.Object);

            // Act
            sut.AddUser("Bob", "*****@*****.**", "password", "password", "score");

            // Assert
            Assert.AreSame(sut, test);
            Assert.AreEqual(sut, test);
        }