private void PrepareToSavePaymentMethod(Employee employee)
        {
            PaymentMethod method = employee.Method;

            if (method is HoldMethod)
            {
                methodCode = "hold";
            }
            else if (method is DirectDepositMethod)
            {
                methodCode = "directdeposit";
                DirectDepositMethod ddMethod = method as DirectDepositMethod;
                insertPaymentMethodCommand = CreateInsertDirectDepositCommand(ddMethod, employee);
            }
            else if (method is MailMethod)
            {
                methodCode = "mail";
                MailMethod mailMethod = method as MailMethod;
                insertPaymentMethodCommand = CreateInsertMailMethodCommand(mailMethod, employee);
            }
            else
            {
                methodCode = "unknown";
            }
        }
        private SqlCommand CreateInsertMailMethodCommand(MailMethod mailMethod, Employee employee)
        {
            string     sql     = "insert into PaycheckAddress values (@Address, @EmpId)";
            SqlCommand command = new SqlCommand(sql);

            command.Parameters.Add("@Address", mailMethod.Address);
            command.Parameters.Add("@EmpId", employee.EmpId);
            return(command);
        }
Exemplo n.º 3
0
        private void CreateInsertMailMethodCommand(Employee employee, MailMethod mailMethod)
        {
            string sql = "insert into PayCheckAddress " +
                         "values (@Address, @EmpId)";

            insertPaymentMethodCommand = new SqlCommand(sql);
            insertPaymentMethodCommand.Parameters.AddWithValue("@Address", mailMethod.Address);
            insertPaymentMethodCommand.Parameters.AddWithValue("@EmpId", employee.EmpId);
        }
        public void CreateMailMethodFromRow()
        {
            operation = new LoadPaymentMethodOperation(employee, "mail", null);
            operation.Prepare();
            DataRow row = LoadEmployeeOperationTest.ShuntRow("Address", "23 Pine Ct");

            operation.CreatePaymentMethod(row);

            PaymentMethod method = this.operation.Method;

            Assert.IsTrue(method is MailMethod);
            MailMethod mailMethod = method as MailMethod;

            Assert.AreEqual("23 Pine Ct", mailMethod.Address);
        }
Exemplo n.º 5
0
 public static IMailSender GetSender(MailMethod method = MailMethod.SMTP)
 {
     switch (method)
     {
         case MailMethod.SMTP:
         {
             return new SmtpMailSender();
         }
         case MailMethod.Mandrill:
         {
             return new MandrillMailSender();
         }
         default:
         {
             return null;
         }
     }
 }
Exemplo n.º 6
0
 public static IMailAttributes GetAttributes(MailMethod method = MailMethod.SMTP)
 {
     switch (method)
     {
         case MailMethod.SMTP:
         {
             return new SmtpMailAttributes();
         }
         case MailMethod.Mandrill:
         {
             return new MandrillMailAttributes();
         }
         default:
         {
             return null;
         }
     }
 }
Exemplo n.º 7
0
        public void TestChangeMailMethodTransaction()
        {
            int employeeId           = 15;
            AddEmployTransaction aet = new AddSalariedEmployee(employeeId, "Bob", "Home", 1000.0);

            aet.Execute();
            Employee e = PayrollRepository.GetEmployee(employeeId);

            e.Method.Should().BeOfType <HoldMethod>();
            ChangeMailMethodTransation cmmt = new ChangeMailMethodTransation(employeeId, "home");

            cmmt.Execute();

            e = PayrollRepository.GetEmployee(employeeId);
            e.Method.Should().BeOfType <MailMethod>();
            MailMethod mm = e.Method as MailMethod;

            mm.Address.Should().Be("home");
        }
Exemplo n.º 8
0
        public void AddEmployeeTest_SaveMailMethod_InTransactional()
        {
            //Null values won't go in the database.
            MailMethod method = new MailMethod(null);

            employee.Method = method;
            try
            {
                database.AddEmployee(employee);
                Assert.Fail("An exception needs to occur "
                            + "for this test to work");
            }
            catch (SqlException)
            { }

            DataTable table = LoadTable("Employee");

            Assert.AreEqual(0, table.Rows.Count);
        }
Exemplo n.º 9
0
        public void ExecuteTest()
        {
            int    empId       = 28;
            string mailAddress = "MisStreet";

            AddEmployeeTransaction addSalEmp = new AddSalariedEmployee(empId, "kara", "samubola", 3000, database);

            addSalEmp.Execute();

            ChangeMethodTranscation changeMailTrans = new ChangeMailTransaction(empId, mailAddress, database);

            changeMailTrans.Execute();
            Employee emp = database.GetEmployee(empId);

            Assert.IsNotNull(emp);
            Assert.IsTrue(emp.Method  is MailMethod);

            MailMethod mailMethod = emp.Method as MailMethod;

            Assert.IsNotNull(mailMethod);
            Assert.AreEqual(mailMethod.Address, mailAddress);
        }
Exemplo n.º 10
0
        public void TestChangeMailTransaction()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "Home", 15.25);

            t.Execute();

            ChangeMailTransaction mt = new ChangeMailTransaction(empId, "email");

            mt.Execute();
            Employee e = PayrollDatabase.GetEmployee(empId);

            Assert.IsNotNull(e);

            PaymentMethod pm = e.Method;

            Assert.IsNotNull(pm);
            Assert.IsTrue(pm is MailMethod);
            MailMethod dm = pm as MailMethod;

            Assert.AreEqual("email", dm.Address);
        }
Exemplo n.º 11
0
 public void SetMailMethod(MailMethod method)
 {
     MailAttributes = MailMethodUtil.GetAttributes(method);
     MailSender = MailMethodUtil.GetSender(method);
 }
Exemplo n.º 12
0
        private void CreateMailMethod(DataRow row)
        {
            var address = row["Address"].ToString();

            Method = new MailMethod(address);
        }