//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");
        }
 //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;
 }
        //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");
        }
        //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");
        }
Exemple #5
0
 //dbReader
 private static Job createJob(IDataReader dbReader)
 {
     Job job = new Job();
     job.jobId = Convert.ToInt32(dbReader["JobId"]);
     job.jobName = Convert.ToString(dbReader["JobName"]);
     job.dateCreated = (DateTimeOffset)dbReader["DateCreated"];
     job.durationInDays = Convert.ToInt32(dbReader["DurationInDays"]);
     job.reward = Convert.ToDecimal(dbReader["Reward"]);
     if (dbReader["DateAwarded"] != null && dbReader["DateAwarded"] != DBNull.Value)
     {
         job.dateAwarded = (DateTimeOffset)dbReader["DateAwarded"];
     }
     else { job.dateAwarded = null; }
     job.languageFrom = new Language();
     job.languageFrom.languageId = Convert.ToInt32(dbReader["LanguageFrom"]);
     job.languageTo = new Language();
     job.languageTo.languageId = Convert.ToInt32(dbReader["LanguageTo"]);
     job.user = new User();
     job.user.userId = Convert.ToInt32(dbReader["UserId"]);
     job.upload = new Upload();
     job.upload.uploadId = Convert.ToInt32(dbReader["UploadId"]);
     return job;
 }
        //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");
        }
Exemple #7
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        private int insertJob(Job job, bool isText, bool isFile)
        {
            if ((isText && isFile) || (!isText && !isFile)) return (int)CODE.CTRJOB_INSERTJOB_ISBOTHORNEITHER;//means the functions was called wrong
            
            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate jobName
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(job.jobName) ||
                !Validate.isAlphaNumericWithUnderscoreAndSpaceAndDash(job.jobName) ||
                !Validate.hasMaxLength(job.jobName, 50) ||
                !Validate.hasMinLength(job.jobName, 1)
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_JOBNAME; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_JOBNAME; result = (int)CODE.ZERO;
            }
            //validate dateCreated
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO
                //nothing to validate here at this point
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_DATECREATED; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_DATECREATED; result = (int)CODE.ZERO;
            }
            //validate durationInDays
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                job.durationInDays.Equals(null) ||
                !Validate.integerIsBiggerThan(job.durationInDays, 0) ||
                !Validate.integerIsSmallerThan(job.durationInDays, 32)
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_DURATIONINDAYS; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_DURATIONINDAYS; result = (int)CODE.ZERO;
            }
            //validate reward
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                job.reward.Equals(null) ||
                !Validate.decimalIsBiggerThan(job.reward, 0)
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_REWARD; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_REWARD; result = (int)CODE.ZERO;
            }
            //validate dateAwarded
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO
                //nothing to validate here at this point
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_DATEAWARDED; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_DATEAWARDED; result = (int)CODE.ZERO;

            }
            //validate languageFrom
            //has to exist
            CtrLanguage _CtrLanguageFrom = new CtrLanguage();
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                job.languageFrom.Equals(null) ||
                _CtrLanguageFrom.findLanguageByLanguageId(job.languageFrom.languageId) == null
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_LANGUAGEFROM; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_LANGUAGEFROM; result = (int)CODE.ZERO;
            }
            //validate languageTo
            //has to exist
            CtrLanguage _CtrLanguageTo = new CtrLanguage();
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                job.languageTo.Equals(null) ||
                _CtrLanguageTo.findLanguageByLanguageId(job.languageTo.languageId) == null
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_LANGUAGETO; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_LANGUAGETO; result = (int)CODE.ZERO;
            }
            //validate user
            //has to exist
            CtrUser _CtrUser = new CtrUser();
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                job.user.Equals(null) ||
                _CtrUser.findUserByUserId(job.user.userId) == null
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_USER; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_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 ||
                job.upload.Equals(null)
               )
            {
                if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_INVALID_UPLOAD; result = (int)CODE.ZERO;
                if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_INVALID_UPLOAD; result = (int)CODE.ZERO;

            }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                job.jobName = job.jobName;
                job.dateCreated = DateTimeOffset.Now;
                job.durationInDays = job.durationInDays;
                job.reward = job.reward;
                job.dateAwarded = null;
                job.languageFrom = job.languageFrom;
                job.languageTo = job.languageTo;
                job.user = job.user;
                job.upload = job.upload;

                CtrUpload _CtrUpload = new CtrUpload();
                IJobs _DbJobs = new DbJobs();

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

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    if (isText) returnCode = (int)CODE.CTRJOB_INSERTJOBTEXT_EXCEPTION;
                    if (isFile) returnCode = (int)CODE.CTRJOB_INSERTJOBFILE_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else { }
            return returnCode;
        }
Exemple #8
0
 //returns [int >= TRANSLATO_DATABASE_SEED] if successful
 //returns [int < TRANSLATO_DATABASE_SEED] if not
 internal int insertJobFile(Job job)
 {
     return insertJob(job, false, true);
 }
Exemple #9
0
 //returns [int >= TRANSLATO_DATABASE_SEED] if successful
 //returns [int < TRANSLATO_DATABASE_SEED] if not
 internal int insertJobText(Job job)
 {
     return insertJob(job, true, false);
 }
Exemple #10
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        public int insertJob(Job job)
        {
            int returnCode = (int)CODE.ZERO;

            string sqlQuery = "INSERT INTO Jobs OUTPUT INSERTED.JobId VALUES (" +
                "@JobName, " +
                "@DateCreated, " +
                "@DurationInDays, " +
                "@Reward, " +
                "NULL, " +
                "@LanguageFrom, " +
                "@LanguageTo, " +
                "@UserId, " +
                "@UploadId" +
            ")";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                try
                {
                    regenSqlParams();
                    using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        param_jobName.Value = job.jobName;
                        sqlCommand.Parameters.Add(param_jobName);

                        param_dateCreated.Value = job.dateCreated;
                        sqlCommand.Parameters.Add(param_dateCreated);

                        param_durationInDays.Value = job.durationInDays;
                        sqlCommand.Parameters.Add(param_durationInDays);

                        param_reward.Value = job.reward;
                        sqlCommand.Parameters.Add(param_reward);

                        param_languageFrom.Value = job.languageFrom.languageId;
                        sqlCommand.Parameters.Add(param_languageFrom);

                        param_languageTo.Value = job.languageTo.languageId;
                        sqlCommand.Parameters.Add(param_languageTo);

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

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

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

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    returnCode = (int)CODE.DBJOBS_INSERTJOB_EXCEPTION;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    returnCode = (int)CODE.DBJOBS_INSERTJOB_EXCEPTION;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    returnCode = (int)CODE.DBJOBS_INSERTJOB_EXCEPTION;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.DBJOBS_INSERTJOB_EXCEPTION;
                    Log.Add(ex.ToString());
                }
                return returnCode;
            }
        }
Exemple #11
0
        //returns "MODEL.Job" object if successful
        //returns "null" if not
        public Job findJobByJobId(int jobId)
        {
            string sqlQuery = "SELECT * FROM Jobs WHERE " +
                "JobId = @JobId";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                Job job = new Job();
                IDataReader dbReader;

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

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

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