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
 //dbReader
 private static Submission createSubmission(IDataReader dbReader)
 {
     Submission submission = new Submission();
     submission.submissionId = Convert.ToInt32(dbReader["SubmissionId"]);
     submission.dateSubmitted = (DateTimeOffset)dbReader["DateSubmitted"];
     submission.isAwarded = Convert.ToBoolean(dbReader["IsAwarded"]);
     submission.user = new User();
     submission.user.userId = Convert.ToInt32(dbReader["UserId"]);
     submission.upload = new Upload();
     submission.upload.uploadId = Convert.ToInt32(dbReader["UploadId"]);
     submission.job = new Job();
     submission.job.jobId = Convert.ToInt32(dbReader["JobId"]);
     return submission;
 }
 public ReturnedObject insertSubmissionFile(string publicKey, string privateKey, Submission submission)
 {
     ReturnedObject returnedObject = new ReturnedObject();
     if (Security.authorizeClient(publicKey, privateKey))
     {
         CtrSubmission _CtrSubmission = new CtrSubmission();
         returnedObject.code = _CtrSubmission.insertSubmissionFile(submission);
     }
     else
     {
         returnedObject.code = (int)CODE.CLIENT_NOT_AUTHORIZED;
     }
     return returnedObject;
 }
Ejemplo n.º 4
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.º 5
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        public int insertSubmission(Submission submission)
        {
            int returnCode = (int)CODE.ZERO;

            string sqlQuery = "INSERT INTO Submissions OUTPUT INSERTED.SubmissionId VALUES (" +
                "@DateSubmitted, " +
                "@IsAwarded, " +
                "@UserId, " +
                "@UploadId, " +
                "@JobId" +
            ")";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                try
                {
                    regenSqlParams();
                    using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        param_dateSubmitted.Value = submission.dateSubmitted;
                        sqlCommand.Parameters.Add(param_dateSubmitted);

                        param_isAwarded.Value = submission.isAwarded;
                        sqlCommand.Parameters.Add(param_isAwarded);

                        param_userId.Value = submission.user.userId;
                        sqlCommand.Parameters.Add(param_userId);

                        param_uploadId.Value = submission.upload.uploadId;
                        sqlCommand.Parameters.Add(param_uploadId);

                        param_jobId.Value = submission.job.jobId;
                        sqlCommand.Parameters.Add(param_jobId);

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

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    returnCode = (int)CODE.DBSUBMISSIONS_INSERTSUBMISSION_EXCEPTION;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    returnCode = (int)CODE.DBSUBMISSIONS_INSERTSUBMISSION_EXCEPTION;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    returnCode = (int)CODE.DBSUBMISSIONS_INSERTSUBMISSION_EXCEPTION;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.DBSUBMISSIONS_INSERTSUBMISSION_EXCEPTION;
                    Log.Add(ex.ToString());
                }
                return returnCode;
            }
        }
Ejemplo n.º 6
0
        //returns "MODEL.Submission" object if successful
        //returns "null" if not
        public Submission findSubmissionByUploadId(int uploadId)
        {
            string sqlQuery = "SELECT * FROM Submissions WHERE " +
                "UploadId = @UploadId";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                Submission submission = new Submission();
                IDataReader dbReader;

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

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

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    submission = null;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    submission = null;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    submission = null;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    submission = null;
                    Log.Add(ex.ToString());
                }
                return submission;
            }
        }
Ejemplo n.º 7
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        private int insertSubmission(Submission submission, bool isText, bool isFile)
        {
            if ((isText && isFile) || (!isText && !isFile)) return (int)CODE.CTRSUBMISSION_INSERTSUBMISSION_ISBOTHORNEITHER;//means the functions was called wrong

            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate dateSubmitted
            if (
                 result == (int)CODE.ZERO ||
                 returnCode != (int)CODE.ZERO
                //nothing to validate here at this point
                )
            {
                if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_INVALID_DATESUBMITTED; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_INVALID_DATESUBMITTED; result = (int)CODE.ZERO;
            }
            //validate isAwarded
            if (
                 result == (int)CODE.ZERO ||
                 returnCode != (int)CODE.ZERO
                //nothing to validate here at this point
                )
            {
                if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_INVALID_ISAWARDED; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_INVALID_ISAWARDED; result = (int)CODE.ZERO;
            }
            //validate user
            //has to exist
            CtrUser _CtrUser = new CtrUser();
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                submission.user.Equals(null) ||
                _CtrUser.findUserByUserId(submission.user.userId) == null
               )
            {
                if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_INVALID_USER; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_INVALID_USER; result = (int)CODE.ZERO;
            }
            //validate upload
            //does not have to exist; will be created
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                submission.upload.Equals(null)
               )
            {
                if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_INVALID_UPLOAD; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_INVALID_UPLOAD; result = (int)CODE.ZERO;

            }
            //validate job
            //has to exist
            CtrJob _CtrJob = new CtrJob();
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                submission.job.Equals(null) ||
                _CtrJob.findJobByJobId(submission.job.jobId) == null
               )
            {
                if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_INVALID_JOB; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_INVALID_JOB; result = (int)CODE.ZERO;
            }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                submission.dateSubmitted = DateTimeOffset.Now;
                submission.isAwarded = false;
                submission.user = submission.user;
                submission.upload = submission.upload;
                submission.job = submission.job;

                CtrUpload _CtrUpload = new CtrUpload();
                ISubmissions _DbSubmissions = new DbSubmissions();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        if (isText) returnCode = _CtrUpload.insertUploadText(submission.upload);
                        if (isFile) returnCode = _CtrUpload.insertUploadFile(submission.upload);
                        if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means upload was inserted successfully
                        {
                            submission.upload.uploadId = returnCode;
                            returnCode = _DbSubmissions.insertSubmission(submission);
                        }
                        else
                        {//means upload failed to be inserted
                            trScope.Dispose();
                        }

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    if (isText) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRSUBMISSION_INSERTSUBMISSIONFILE_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else { }
            return returnCode;
        }
Ejemplo n.º 8
0
 //returns [int >= TRANSLATO_DATABASE_SEED] if successful
 //returns [int < TRANSLATO_DATABASE_SEED] if not
 internal int insertSubmissionFile(Submission submission)
 {
     return insertSubmission(submission, false, true);
 }
Ejemplo n.º 9
0
 //returns [int >= TRANSLATO_DATABASE_SEED] if successful
 //returns [int < TRANSLATO_DATABASE_SEED] if not
 internal int insertSubmissionText(Submission submission)
 {
     return insertSubmission(submission, true, false);
 }