Ejemplo n.º 1
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Submission_FullConstructor_CreateSubmission_SubmissionIsCreated()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int submissionId = 7;
            DateTimeOffset dateSubmitted = initDTO;
            bool isAwarded = false;
            User user = new User();
            Upload upload = new Upload();
            Job job = new Job();

            //act
            Submission submission_m1 = new Submission(
                submissionId,
                dateSubmitted,
                isAwarded,
                user,
                upload,
                job
                );

            //assert
            Assert.IsNotNull(submission_m1, "submission object is null");
            Assert.AreEqual(7, submission_m1.submissionId, "wrong submissionId");
            Assert.AreEqual(initDTO, submission_m1.dateSubmitted, "wrong dateSubmitted");
            Assert.IsTrue(!submission_m1.isAwarded, "wrong isAwarded");
            Assert.IsNotNull(submission_m1.user, "submission.user is null");
            Assert.IsNotNull(submission_m1.upload, "submission.upload is null");
            Assert.IsNotNull(submission_m1.job, "submission.job is null");
        }
Ejemplo n.º 2
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Upload_FullConstructor_CreateFileUpload_FileUploadIsCreated()
        {
            //arrange
            int uploadId = 6;

            Text text = null;

            File file = new File();
            file.fileId = 2;

            //act
            Upload upload_m2 = new Upload(
                uploadId,
                text,
                file
                );

            //assert
            Assert.IsNotNull(upload_m2, "upload object is null");
            Assert.AreEqual(6, upload_m2.uploadId, "wrong uploadId");

            Assert.IsNull(upload_m2.text, "upload.text is NOT null");

            Assert.IsNotNull(upload_m2.file, "upload.file object is null");
            Assert.AreEqual(2, upload_m2.file.fileId, "wrong upload.file.fileId");            
        }
Ejemplo n.º 3
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Upload_FullConstructor_CreateTextUpload_TextUploadIsCreated()
        {
            //arrange
            int uploadId = 5;

            Text text = new Text();
            text.textId = 3;
            text.textData = "'morning";

            File file = null;

            //act
            Upload upload_m1 = new Upload(
                uploadId,
                text,
                file
                );

            //assert
            Assert.IsNotNull(upload_m1, "upload object is null");
            Assert.AreEqual(5, upload_m1.uploadId, "wrong uploadId");

            Assert.IsNotNull(upload_m1.text, "upload.text object is null");
            Assert.AreEqual(3, upload_m1.text.textId, "wrong upload.text.textId");
            Assert.AreEqual("'morning", upload_m1.text.textData, "wrong upload.text.textData");

            Assert.IsNull(upload_m1.file, "upload.file is NOT null");
        }
Ejemplo n.º 4
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Job_SetAndGetMethods_ModifyAllFieldsValues_AllValuesAreModified()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int jobId = 1;
            string jobName = "Project1";
            DateTimeOffset dateCreated = initDTO;
            int durationInDays = 3;
            decimal reward = 100.99m;
            DateTimeOffset dateAwarded = initDTO.AddDays(3);
            Language languageFrom = new Language();
            Language languageTo = new Language();
            User user = new User();
            Upload upload = new Upload();
            Job job_m2 = new Job(
                jobId,
                jobName,
                dateCreated,
                durationInDays,
                reward,
                dateAwarded,
                languageFrom,
                languageTo,
                user,
                upload
                );

            //act
            Language languageFrom2 = new Language();
            Language languageTo2 = new Language();
            User user2 = new User();
            Upload upload2 = new Upload();

            job_m2.jobId = 2;
            job_m2.jobName = "Project2";
            job_m2.dateCreated = initDTO.AddMinutes(32);
            job_m2.durationInDays = 4;
            job_m2.reward = 150;
            job_m2.dateAwarded = initDTO.AddDays(1);
            job_m2.languageFrom = languageFrom2;
            job_m2.languageTo = languageTo2;
            job_m2.user = user2;
            job_m2.upload = upload2;

            //assert
            Assert.IsNotNull(job_m2, "job object is null");
            Assert.AreEqual(2, job_m2.jobId, "jobId not changed");
            Assert.AreEqual("Project2", job_m2.jobName, "jobName not changed");
            Assert.AreEqual(initDTO.AddMinutes(32), job_m2.dateCreated, "dateCreated not changed");
            Assert.AreEqual(4, job_m2.durationInDays, "durationInDays not changed");
            Assert.AreEqual(150, job_m2.reward, "reward not changed");
            Assert.AreEqual(initDTO.AddDays(1), job_m2.dateAwarded, "dateRewarded not changed");
            Assert.AreNotEqual(languageFrom, job_m2.languageFrom, "job.languageFrom not changed");
            Assert.AreNotEqual(languageTo, job_m2.languageTo, "job.languageTo not changed");
            Assert.AreNotEqual(user, job_m2.user, "job.user not changed");
            Assert.AreNotEqual(upload, job_m2.upload, "job.upload not changed");
        }
Ejemplo n.º 5
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertUploadFile(Upload upload)
        {
            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate only file
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                upload.text != null ||
                upload.file == null
               ) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_FAILED_ONLYFILE; result = (int)CODE.ZERO; }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                upload.text = null;
                upload.file = upload.file;

                CtrFile _CtrFile = new CtrFile();
                IUploads _DbUploads = new DbUploads();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _CtrFile.insertFile(upload.file);
                        if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means file was inserted successfully
                        {
                            upload.file.fileId = returnCode;
                            returnCode = _DbUploads.insertUploadFile(upload);
                        }
                        else
                        {//means file failed to be inserted
                            trScope.Dispose();
                        }

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else { }
            return returnCode;
        }
 public ReturnedObject insertUploadFile(string publicKey, string privateKey, Upload upload)
 {
     ReturnedObject returnedObject = new ReturnedObject();
     if (Security.authorizeClient(publicKey, privateKey))
     {
         CtrUpload _CtrUpload = new CtrUpload();
         returnedObject.code = _CtrUpload.insertUploadFile(upload);
     }
     else
     {
         returnedObject.code = (int)CODE.CLIENT_NOT_AUTHORIZED;
     }
     return returnedObject;
 }
Ejemplo n.º 7
0
        //author: adrian
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        public int insertUploadText(Upload upload)
        {                                    
            int returnCode = (int)CODE.ZERO;

            string sqlQuery = "INSERT INTO Uploads OUTPUT INSERTED.UploadId VALUES (" +
                "@TextId, " +
                "NULL" +
            ")";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                try
                {
                    regenSqlParams();
                    using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        param_textId.Value = upload.text.textId;
                        sqlCommand.Parameters.Add(param_textId);

                        sqlCommand.Connection.Open();
                        returnCode = (int)sqlCommand.ExecuteScalar();
                        sqlCommand.Connection.Close();

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    returnCode = (int)CODE.DBUPLOADS_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    returnCode = (int)CODE.DBUPLOADS_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    returnCode = (int)CODE.DBUPLOADS_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.DBUPLOADS_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(ex.ToString());
                }
                return returnCode;
            }
        }
Ejemplo n.º 8
0
 //full constructor
 internal Submission(
     int submissionId,
     DateTimeOffset dateSubmitted,
     bool isAwarded,
     User user,
     Upload upload,
     Job job
     )
 {
     this.submissionId = submissionId;
     this.dateSubmitted = dateSubmitted;
     this.isAwarded = isAwarded;
     this.user = user;
     this.upload = upload;
     this.job = job;
 }
Ejemplo n.º 9
0
 //full constructor
 internal Submission(
     int submissionId,
     DateTimeOffset dateSubmitted,
     bool isAwarded,
     User user,
     Upload upload,
     Job job
     )
 {
     this.submissionId  = submissionId;
     this.dateSubmitted = dateSubmitted;
     this.isAwarded     = isAwarded;
     this.user          = user;
     this.upload        = upload;
     this.job           = job;
 }
Ejemplo n.º 10
0
 //dbReader
 private static Upload createUpload(IDataReader dbReader)
 {
     Upload upload = new Upload();
     upload.uploadId = Convert.ToInt32(dbReader["UploadId"]);
     if (dbReader["TextId"] != null && dbReader["TextId"] != DBNull.Value)
     {
         upload.text = new Text();
         upload.text.textId = Convert.ToInt32(dbReader["TextId"]);
     }
     else { upload.text = null; }
     if (dbReader["FileId"] != null && dbReader["FileId"] != DBNull.Value)
     {
         upload.file = new File();
         upload.file.fileId = Convert.ToInt32(dbReader["FileId"]);
     }
     else { upload.file = null; }
     return upload;
 }
Ejemplo n.º 11
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Job_FullConstructor_CreateJob_JobIsCreated()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int jobId = 1;
            string jobName = "Project1";
            DateTimeOffset dateCreated = initDTO;
            int durationInDays = 3;
            decimal reward = 100.99m;
            DateTimeOffset dateAwarded = initDTO.AddDays(3);
            Language languageFrom = new Language();
            Language languageTo = new Language();
            User user = new User();
            Upload upload = new Upload();

            //act
            Job job_m1 = new Job(
               jobId,
               jobName,
               dateCreated,
               durationInDays,
               reward,
               dateAwarded,
               languageFrom,
               languageTo,
               user,
               upload
               );

            //assert
            Assert.IsNotNull(job_m1, "job object is null");
            Assert.AreEqual(1, job_m1.jobId, "wrong jobId");
            Assert.AreEqual("Project1", job_m1.jobName, "wrong jobName");
            Assert.AreEqual(initDTO, job_m1.dateCreated, "wrong dateCreated");
            Assert.AreEqual(3, job_m1.durationInDays, "wrong durationInDays");
            Assert.AreEqual(100.99m, job_m1.reward, "wrong reward");
            Assert.AreEqual(initDTO.AddDays(3), job_m1.dateAwarded, "wrong dateAwarded");
            Assert.IsNotNull(job_m1.languageFrom, "job.languageFrom is null");
            Assert.IsNotNull(job_m1.languageTo, "job.languageTo is null");
            Assert.IsNotNull(job_m1.user, "job.user is null");
            Assert.IsNotNull(job_m1.upload, "job.upload is null");
        }
Ejemplo n.º 12
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_Submission_SetAndGetMethods_ModifyAllFieldsValues_AllValuesAreModified()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int submissionId = 7;
            DateTimeOffset dateSubmitted = initDTO;
            bool isAwarded = false;
            User user = new User();
            Upload upload = new Upload();
            Job job = new Job();
            Submission submission_m2 = new Submission(
                submissionId,
                dateSubmitted,
                isAwarded,
                user,
                upload,
                job
                );

            //act
            User user2 = new User();
            Upload upload2 = new Upload();
            Job job2 = new Job();

            submission_m2.submissionId = 9;
            submission_m2.dateSubmitted = initDTO.AddMinutes(32);
            submission_m2.isAwarded = true;
            submission_m2.user = user2;
            submission_m2.upload = upload2;
            submission_m2.job = job2; ;

            //assert
            Assert.IsNotNull(submission_m2, "submission object is null");
            Assert.AreEqual(9, submission_m2.submissionId, "subbmissionId not changed");
            Assert.AreEqual(initDTO.AddMinutes(32), submission_m2.dateSubmitted, "dateSubmitted not changed");
            Assert.IsTrue(submission_m2.isAwarded, "isAwarded not changed");
            Assert.AreNotEqual(user, submission_m2.user, "submission.user not changed");
            Assert.AreNotEqual(upload, submission_m2.upload, "submission.upload not canged");
            Assert.AreNotEqual(job, submission_m2.job, "submission.job not changed");
        }
Ejemplo n.º 13
0
 //full constructor
 internal Job(
     int jobId,
     string jobName,
     DateTimeOffset dateCreated,
     int durationInDays,
     decimal reward,
     DateTimeOffset dateAwarded,
     Language languageFrom,
     Language languageTo,
     User user,
     Upload upload
     )
 {
     this.jobId = jobId;
     this.jobName = jobName;
     this.dateCreated = dateCreated;
     this.durationInDays = durationInDays;
     this.reward = reward;
     this.dateAwarded = dateAwarded;
     this.languageFrom = languageFrom;
     this.languageTo = languageTo;
     this.user = user;
     this.upload = upload;
 }
Ejemplo n.º 14
0
 //full constructor
 internal Job(
     int jobId,
     string jobName,
     DateTimeOffset dateCreated,
     int durationInDays,
     decimal reward,
     DateTimeOffset dateAwarded,
     Language languageFrom,
     Language languageTo,
     User user,
     Upload upload
     )
 {
     this.jobId          = jobId;
     this.jobName        = jobName;
     this.dateCreated    = dateCreated;
     this.durationInDays = durationInDays;
     this.reward         = reward;
     this.dateAwarded    = dateAwarded;
     this.languageFrom   = languageFrom;
     this.languageTo     = languageTo;
     this.user           = user;
     this.upload         = upload;
 }
Ejemplo n.º 15
0
        //author: futz
        //returns "Model.Upload" object if successful
        //returns "null if not"
        public Upload findUploadByFileId(int fileId)
        {
            string sqlQuery = "SELECT * FROM Uploads WHERE " +
                "FileId = @FileId";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                Upload upload = new Upload();
                IDataReader dbReader;

                try
                {
                    regenSqlParams();
                    using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        param_fileId.Value = fileId;
                        sqlCommand.Parameters.Add(param_fileId);

                        sqlCommand.Connection.Open();
                        dbReader = sqlCommand.ExecuteReader();
                        if (dbReader.Read()) { upload = createUpload(dbReader); }
                        else { upload = null; }
                        sqlCommand.Connection.Close();

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    upload = null;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    upload = null;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    upload = null;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    upload = null;
                    Log.Add(ex.ToString());
                }
                return upload;
            }
        }