Ejemplo n.º 1
0
        public void SportType_CheckDataBeforeSave()
        {
            //Create a SportType object with data.
            aSportType.LoadData(-1, "Weird Sport", 0, "any kind of weird sport", 85,1);
            int res = aSportType.CheckData(connString);
            Assert.AreEqual(1, res); //Data are ok because the type of sport isn´t in de BD.

            //Save the data into BD, and check again.
            aSportType = aSportType.SaveData(connString);
            Int64 sportTypeIDUsed = aSportType.SportTypeID;
            Int64 userIDUsed = aSportType.UserID;
            res = aSportType.CheckData(connString);
            Assert.AreEqual(-1, res); //Data are not ok, SportTypeName is in de BD.

            //Create a SportType object with data:
            aSportType.LoadData(-1, "Weird Sport2", -10, "any kind of weird sport", 85,1);
            res = aSportType.CheckData(connString);
            Assert.AreEqual(-2, res); //Data are not ok, parentSportID does not exist on SportTypes

            //Create a SportType object with data:
            aSportType.LoadData(-1, "", 0, "any kind of weird sport", 85,1);
            res = aSportType.CheckData(connString);
            Assert.AreEqual(0, res); //Data are not ok, SportTypeName is empty.

            //Create a SportType object with data:
            aSportType.LoadData(-1, "Weird Sport2", 0, "any kind of weird sport", -100,1);
            res = aSportType.CheckData(connString);
            Assert.AreEqual(-3, res); //Data are not ok, userID not in data base.

            //Deleting object saved first.
            aSportType = aSportType.FindSportTypeByID(connString);
            res = aSportType.Delete(connString);
            Assert.AreEqual(1, res);
        }
Ejemplo n.º 2
0
        public void SportType_FindParent()
        {
            //Create a SportType object to be the parent
            string sportTypeNameUsed = "Deporte Padre";
            Int64 parentSportTypeIDUsed = 0;
            string memoUsed = "Deporte padre";
            Int64 userIDUsed = 85;
            SportTypes aSportTypeParent = new SportTypes();
            aSportTypeParent.LoadData(-1, sportTypeNameUsed, parentSportTypeIDUsed, memoUsed, userIDUsed,1);

            //Save into BD obtaining the sportTypeID
            aSportTypeParent = aSportTypeParent.SaveData(connString);
            Assert.AreNotEqual(0, aSportTypeParent.SportTypeID); //saving correct data

               //Create a SportType object to be the child
            sportTypeNameUsed = "Deporte Hijo";
            parentSportTypeIDUsed = aSportTypeParent.SportTypeID;
            memoUsed = "Deporte Hijo";
            userIDUsed = 85;
            SportTypes aSportTypeChild = new SportTypes();
            aSportTypeChild.LoadData(-1, sportTypeNameUsed, parentSportTypeIDUsed, memoUsed, userIDUsed,1);

            //Save into BD obtaining the sportTypeID
            aSportTypeChild = aSportTypeChild.SaveData(connString);
            Assert.AreNotEqual(0, aSportTypeChild.SportTypeID); //saving correct data

            //Try to find the parent sport type.
            SportTypes parentSportTypeToFind = new SportTypes();
            parentSportTypeToFind = aSportTypeChild.FindParentSportType(connString);
            Assert.AreNotEqual(-1, parentSportTypeToFind.SportTypeID); //Found it!!
            Assert.AreEqual(aSportTypeParent.SportTypeID, parentSportTypeToFind.SportTypeID);
            Assert.AreEqual(aSportTypeParent.SportTypeName, parentSportTypeToFind.SportTypeName);
            Assert.AreEqual(aSportTypeParent.ParentSportTypeID, parentSportTypeToFind.ParentSportTypeID,1);
            Assert.AreEqual(aSportTypeParent.Memo, parentSportTypeToFind.Memo);

            //Deleting object previously saved
            int res = aSportTypeParent.Delete(connString);
            Assert.AreEqual(1, res);

            //Deleting object previously saved
            res = aSportTypeChild.Delete(connString);
            Assert.AreEqual(1, res);
        }
Ejemplo n.º 3
0
        public void SportType_Update()
        {
            //Create a SportType object
            string sportTypeNameUsed = "Bicicleta";
            Int64 parentSportTypeIDUsed = 0;
            string memoUsed = "Deportes de bicicleta";
            Int64 userIDUsed = 85;
            SportTypes aSportType = new SportTypes();
            aSportType.LoadData(-1, sportTypeNameUsed, parentSportTypeIDUsed, memoUsed, userIDUsed,1);

            //Save into BD obtaining the sportTypeID
            aSportType = aSportType.SaveData(connString);
            Assert.AreNotEqual(0, aSportType.SportTypeID);
            Assert.AreNotEqual(0, aSportType.SportTypeID); //saving correct data
            Int64 sportTypeIDUsed = aSportType.SportTypeID;

            //Try to find and check values
            aSportType = aSportType.FindSportTypeByName(connString);
            Assert.AreNotEqual(-1, aSportType.SportTypeID);
            Assert.AreEqual(sportTypeNameUsed, aSportType.SportTypeName);
            Assert.AreEqual(parentSportTypeIDUsed, aSportType.ParentSportTypeID);
            Assert.AreEqual(memoUsed, aSportType.Memo);
            Assert.AreEqual(userIDUsed, aSportType.UserID);

            //Update values
            sportTypeNameUsed = "Bike Updated";
            parentSportTypeIDUsed = 0;
            memoUsed = "Deportes de bicicleta updated";
            userIDUsed = 85;
            aSportType.LoadData(sportTypeIDUsed, sportTypeNameUsed, parentSportTypeIDUsed, memoUsed, userIDUsed,1);
            aSportType.UpdateData(connString);

            //Try to find and check values
            aSportType = aSportType.FindSportTypeByName(connString);
            Assert.AreNotEqual(-1, aSportType.SportTypeID);
            Assert.AreEqual(sportTypeNameUsed, aSportType.SportTypeName);
            Assert.AreEqual(parentSportTypeIDUsed, aSportType.ParentSportTypeID);
            Assert.AreEqual(memoUsed, aSportType.Memo);
            Assert.AreEqual(userIDUsed, aSportType.UserID);

            //Deleting object previously saved
            int res = aSportType.Delete(connString);
            Assert.AreEqual(1, res);

            //Try to find again after deleting
            aSportType = aSportType.FindSportTypeByID(connString);
            Assert.AreEqual(-1, aSportType.SportTypeID);
        }