Exemplo n.º 1
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void DAL_IUser_InsertUser_InsertUser_UserIsInserted()
        {
            //arrange
            int userId = 1;
            string userName = "******";
            string hashedPassword = "******";
            string firstName = "Adrian";
            string lastName = "Frunza";
            string email = "*****@*****.**";
            bool newsletterOptOut = false;
            DateTimeOffset createdOn = DateTimeOffset.Now;
            User user_m1 = new User(
                userId,
                userName,
                hashedPassword,
                firstName,
                lastName,
                email,
                newsletterOptOut,
                createdOn
                );
            IUsers _DbUsers = new DbUsers();

            //act
            int result = _DbUsers.insertUser(user_m1);

            //assert
            
            Assert.IsTrue(result >= (int)ENUM.CODE.TRANSLATO_DATABASE_SEED);
        }
Exemplo n.º 2
0
        //LAYER_Class_nameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void BLL_CtrUser_insertUser_InsertUser_UserIsInserted()
        {
            //arrange
            int userId = 1;
            string userName = "******";
            string hashedPassword = "******";
            string firstName = "Adrian";
            string lastName = "Frunza";
            string email = "*****@*****.**";
            bool newsletterOptOut = false;
            DateTimeOffset createdOn = DateTimeOffset.Now;
            User user_m1 = new User(
                userId,
                userName,
                hashedPassword,
                firstName,
                lastName,
                email,
                newsletterOptOut,
                createdOn
                );
            CtrUser _CtrUser = new CtrUser();

            //act
            int result = _CtrUser.insertUser(user_m1);

            //assert
         //   Assert.AreEqual(1, result, "user not inserted");
            Assert.IsTrue(result>=(int)ENUM.CODE.TRANSLATO_DATABASE_SEED);
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
 //full constructor
 internal LiveTranslation(
     int liveTranslationId,
     DateTimeOffset dateCreated,
     User provider,
     decimal pricePerHour,
     Language language1,
     Language language2,
     Language language3,
     Language language4,
     Language language5,
     DateTimeOffset? dateStarted,
     User requester,
     DateTimeOffset? dateEnded
     )
 {
     this.liveTranslationId = liveTranslationId;
     this.dateCreated = dateCreated;
     this.provider = provider;
     this.pricePerHour = pricePerHour;
     this.language1 = language1;
     this.language2 = language2;
     this.language3 = language3;
     this.language4 = language4;
     this.language5 = language5;
     this.dateStarted = dateStarted;
     this.requester = requester;
     this.dateEnded = dateEnded;
 }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
0
 //dbReader
 private static User createUser(IDataReader dbReader)
 {
     User user = new User();
     user.userId = Convert.ToInt32(dbReader["UserId"]);
     user.userName = Convert.ToString(dbReader["UserName"]);
     user.hashedPassword = Convert.ToString(dbReader["HashedPassword"]);
     user.firstName = Convert.ToString(dbReader["Firstname"]);
     user.lastName = Convert.ToString(dbReader["LastName"]);
     user.email = Convert.ToString(dbReader["Email"]);
     user.newsletterOptOut = Convert.ToBoolean(dbReader["NewsletterOptOut"]);
     user.createdOn = (DateTimeOffset)dbReader["CreatedOn"];
     return user;
 }
 public ReturnedObject insertUser(string publicKey, string privateKey, User user)
 {
     ReturnedObject returnedObject = new ReturnedObject();
     if (Security.authorizeClient(publicKey, privateKey))
     {
         CtrUser _CtrUser = new CtrUser();
         returnedObject.code =  _CtrUser.insertUser(user);
     }
     else
     {
         returnedObject.code = (int)CODE.CLIENT_NOT_AUTHORIZED;
     }
     return returnedObject; 
 }
Exemplo 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;
 }
Exemplo n.º 9
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_User_SetAndGetMethods_ModifyAllFieldsValues_AllValuesAreModified()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int userId = 1;
            string userName = "******";
            string hashedPassword = "******";
            string firstName = "Adrian";
            string lastName = "Frunza";
            string email = "*****@*****.**";
            bool newsletterOptOut = false;
            DateTimeOffset createdOn = initDTO;
            User user_m2 = new User(
                userId,
                userName,
                hashedPassword,
                firstName,
                lastName,
                email,
                newsletterOptOut,
                createdOn
                );

            //act
            user_m2.userId = 2;
            user_m2.userName = "******";
            user_m2.hashedPassword = "******";
            user_m2.firstName = "Adriann";
            user_m2.lastName = "Frunzulita";
            user_m2.email = "*****@*****.**";
            user_m2.newsletterOptOut = true;
            user_m2.createdOn = initDTO.AddMinutes(32);

            //assert
            Assert.IsNotNull(user_m2, "user object is null");
            Assert.AreEqual(2, user_m2.userId, "userId not changed");
            Assert.AreEqual("not.frunza.adrian", user_m2.userName, "userName not changed");
            Assert.AreEqual("rsh45sh46gh4g65h4gf6h4fg6h54ti", user_m2.hashedPassword, "hashedPassword not changed");
            Assert.AreEqual("Adriann", user_m2.firstName, "firstName not changed");
            Assert.AreEqual("Frunzulita", user_m2.lastName, "lastName not changed");
            Assert.AreEqual("*****@*****.**", user_m2.email, "email not changed");
            Assert.IsTrue(user_m2.newsletterOptOut, "newsletterOptOut not changed");
            Assert.AreEqual(initDTO.AddMinutes(32), user_m2.createdOn, "createdOn not changed");
        }
Exemplo n.º 10
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");
        }
Exemplo n.º 11
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");
        }
Exemplo n.º 12
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void MODEL_User_FullConstructor_CreateUser_UserIsCreated()
        {
            //arrange
            DateTimeOffset initDTO = DateTimeOffset.Now;

            int userId = 1;
            string userName = "******";
            string hashedPassword = "******";
            string firstName = "Adrian";
            string lastName = "Frunza";
            string email = "*****@*****.**";
            bool newsletterOptOut = false;
            DateTimeOffset createdOn = initDTO;

            //act
            User user_m1 = new User(
                userId,
                userName,
                hashedPassword,
                firstName,
                lastName,
                email,
                newsletterOptOut,
                createdOn
                );

            //assert
            Assert.IsNotNull(user_m1, "user object is null");
            Assert.AreEqual(1, user_m1.userId, "wrong userId");
            Assert.AreEqual("frunza.adrian", user_m1.userName, "wrong userName");
            Assert.AreEqual("rsh45sh46gh4g65h4gf6h4fg6h54th", user_m1.hashedPassword, "wrong hashedPassword");
            Assert.AreEqual("Adrian", user_m1.firstName, "wrong firstName");
            Assert.AreEqual("Frunza", user_m1.lastName, "wrong lastName");
            Assert.AreEqual("*****@*****.**", user_m1.email, "wrong email");
            Assert.IsTrue(!user_m1.newsletterOptOut,"wrong newsletterOptOut");
            Assert.AreEqual(initDTO, user_m1.createdOn, "wrong createdOn");
        }
Exemplo 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;
 }
Exemplo n.º 14
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertUser(User user)
        {
            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate userName 
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(user.userName) ||
                !Validate.isAlphaNumericWithUnderscore(user.userName) ||
                !Validate.hasMinLength(user.userName, 5) ||
                !Validate.hasMaxLength(user.userName, 15)
               ) { returnCode = (int)CODE.CTRUSER_INSERTUSER_INVALID_USERNAME; result = (int)CODE.ZERO; }
            //validate password(stored in the hashedPassword field at this point. Will be replaced with hash + salt later)
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(user.hashedPassword) ||
                !Validate.hasMinLength(user.hashedPassword, 8) ||
                !Validate.hasMaxLength(user.hashedPassword, 100)
               ) { returnCode = (int)CODE.CTRUSER_INSERTUSER_INVALID_PASSWORD; result = (int)CODE.ZERO; }
            //validate firstName 
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(user.firstName) ||
                !Validate.hasMinLength(user.firstName, 2) ||
                !Validate.hasMaxLength(user.firstName, 20)
               ) { returnCode = (int)CODE.CTRUSER_INSERTUSER_INVALID_FIRSTNAME; result = (int)CODE.ZERO; }
            //validate lastName 
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(user.lastName) ||
                !Validate.hasMinLength(user.lastName, 2) ||
                !Validate.hasMaxLength(user.lastName, 20)
               ) { returnCode = (int)CODE.CTRUSER_INSERTUSER_INVALID_LASTNAME; result = (int)CODE.ZERO; }
            //validate email 
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(user.email) ||
                !Validate.hasMinLength(user.email, 5) ||
                !Validate.hasMaxLength(user.email, 50) ||
                !user.email.Contains("@")
               ) { returnCode = (int)CODE.CTRUSER_INSERTUSER_INVALID_EMAIL; result = (int)CODE.ZERO; }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                user.userName = user.userName;
                user.hashedPassword = Security.hashPassword(user.hashedPassword);
                user.firstName = user.firstName;
                user.lastName = user.lastName;
                user.email = user.email;
                user.newsletterOptOut = user.newsletterOptOut;
                user.createdOn = DateTimeOffset.Now;

                IUsers _DbUsers = new DbUsers();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _DbUsers.insertUser(user);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRUSER_INSERTUSER_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRUSER_INSERTUSER_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRUSER_INSERTUSER_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else {  }
            return returnCode;
        }
Exemplo n.º 15
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        public int insertUser(User user)
        {
            int returnCode = (int)CODE.ZERO;

            string sqlQuery = "INSERT INTO Users OUTPUT INSERTED.UserId VALUES (" +
                "@UserName, " +
                "@HashedPassword, " +
                "@FirstName, " +
                "@LastName, " +
                "@Email, " +
                "@NewsletterOptOut," +
                "@CreatedOn" +
            ")";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                try
                {
                    regenSqlParams();
                    using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        param_userName.Value = user.userName;
                        sqlCommand.Parameters.Add(param_userName);

                        param_hashedPassword.Value = user.hashedPassword;
                        sqlCommand.Parameters.Add(param_hashedPassword);

                        param_firstName.Value = user.firstName;
                        sqlCommand.Parameters.Add(param_firstName);

                        param_lastName.Value = user.lastName;
                        sqlCommand.Parameters.Add(param_lastName);

                        param_email.Value = user.email;
                        sqlCommand.Parameters.Add(param_email);

                        param_newsletterOptOut.Value = user.newsletterOptOut;
                        sqlCommand.Parameters.Add(param_newsletterOptOut);

                        param_createdOn.Value = user.createdOn;
                        sqlCommand.Parameters.Add(param_createdOn);

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

                        sqlCommand.Parameters.Clear();
                    }
                }
                catch (InvalidOperationException ioEx)
                {
                    returnCode = (int)CODE.DBUSERS_INSERTUSER_EXCEPTION;
                    Log.Add(ioEx.ToString());
                }
                catch (SqlException sqlEx)
                {
                    returnCode = (int)CODE.DBUSERS_INSERTUSER_EXCEPTION;
                    Log.Add(sqlEx.ToString());
                }
                catch (ArgumentException argEx)
                {
                    returnCode = (int)CODE.DBUSERS_INSERTUSER_EXCEPTION;
                    Log.Add(argEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.DBUSERS_INSERTUSER_EXCEPTION;
                    Log.Add(ex.ToString());
                }
                return returnCode;
            }
        }
Exemplo n.º 16
0
        //returns "MODEL.User" object if successful
        //returns "null" if not
        public User findUserByEmail(string email)
        {
            string sqlQuery = "SELECT * FROM Users WHERE " +
                "Email = @Email";

            using (SqlConnection sqlConnection = new SqlConnection(AccessTranslatoDb.sqlConnectionString))
            {
                User user = new User();
                IDataReader dbReader;

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

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

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