Exemple #1
0
        public void ConstructorTest()
        {
            CAESDO.Recruitment.Core.Domain.File f = new CAESDO.Recruitment.Core.Domain.File();

            Assert.IsNotNull(f);
            Assert.IsTrue(f.IsTransient());
        }
Exemple #2
0
        public void SaveDeleteTest()
        {
            CAESDO.Recruitment.Core.Domain.File file = new CAESDO.Recruitment.Core.Domain.File();

            FileType ftype = NHibernateHelper.DaoFactory.GetFileTypeDao().GetById(StaticProperties.ExistingFileTypeID, false);

            file.FileType = ftype;
            file.FileName = StaticProperties.TestString;
            file.Label    = string.Empty;

            //Make sure the file is valid
            Assert.IsTrue(ValidateBO <CAESDO.Recruitment.Core.Domain.File> .isValid(file), "File Not Valid");

            Assert.IsTrue(file.IsTransient()); //file is not saved

            using (var ts = new TransactionScope())
            {
                file = NHibernateHelper.DaoFactory.GetFileDao().SaveOrUpdate(file);

                ts.CommitTransaction();
            }

            Assert.IsFalse(file.IsTransient()); //file should now be saved

            CAESDO.Recruitment.Core.Domain.File fileDB = new CAESDO.Recruitment.Core.Domain.File();

            //Get a new file using the saved file's ID
            fileDB = NHibernateHelper.DaoFactory.GetFileDao().GetById(file.ID, false);

            //Make sure they are the same
            Assert.AreEqual(file, fileDB);

            this.TestContext.WriteLine("File Created had ID = {0}", fileDB.ID);

            //Now delete the file
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetFileDao().Delete(file);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                file = NHibernateHelper.DaoFactory.GetFileDao().GetById(fileDB.ID, false);
                file.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
Exemple #3
0
        public void CascadeFileTypeSaveTest()
        {
            //Grab an existing file out of the database
            CAESDO.Recruitment.Core.Domain.File file = NHibernateHelper.DaoFactory.GetFileDao().GetById(StaticProperties.ExistingFileID, false);

            //Get all possible file types (lookup table)
            List <FileType> fileTypeList = NHibernateHelper.DaoFactory.GetFileTypeDao().GetAll();

            Assert.IsFalse(file.FileType.IsTransient()); //make sure we have a valid filetype

            int originalFileTypeID = file.FileType.ID;

            this.TestContext.WriteLine("Original FileTypeID = {0}", originalFileTypeID);

            //Now find a filetype that doesn't equal the current one
            FileType newType = new FileType();

            foreach (FileType fType in fileTypeList)
            {
                if (fType.ID != originalFileTypeID)
                {
                    newType = fType;
                    break;
                }
            }

            //Make sure we got a different filetype
            Assert.AreNotEqual <int>(file.FileType.ID, newType.ID);

            //Now update the file with the new fileType
            using (var ts = new TransactionScope())
            {
                file.FileType = newType;
                NHibernateHelper.DaoFactory.GetFileDao().SaveOrUpdate(file);

                ts.CommitTransaction();
            }

            this.TestContext.WriteLine("New FileTypeID = {0}", newType.ID);
            //Get the original file back out of the database, and make sure the fileType changed to the new type
            CAESDO.Recruitment.Core.Domain.File fileDB = NHibernateHelper.DaoFactory.GetFileDao().GetById(StaticProperties.ExistingFileID, false);

            Assert.AreEqual <int>(fileDB.FileType.ID, newType.ID);
        }