/// <summary>
        /// Retrieves the expense reports from the database with given query
        /// </summary>
        /// <param name="query">sql query</param>
        /// <returns></returns>
        private List<ExpenseReport> GetReportsFromDatabase(string query)
        {
            List<ExpenseReport> expenseReports = new List<ExpenseReport>();
            EmployeeDAL employeeDAL = new EmployeeDAL();
            DepartmentDAL departmentDAL = new DepartmentDAL();

            DataAccessFunctions daFunctions = new DataAccessFunctions();

            daFunctions.Command = new SqlCommand(query, daFunctions.Connection);

            try
            {
                daFunctions.Connection.Open();

                SqlDataReader rdr = daFunctions.Command.ExecuteReader();

                while (rdr.Read())
                {
                    ExpenseReport report = new ExpenseReport();
                    Employee createdBy = new Employee();
                    Employee approvedBy = new Employee();
                    Employee processedBy = new Employee();
                    decimal expenseTotal;

                    report.ExpenseId = rdr["ExpenseId"] as int? ?? default(int);
                    //report.DepartmentId = rdr["DepartmentId"] as int? ?? default(int);
                    report.CreateDate = (DateTime)rdr["CreateDate"];
                    report.ExpenseToDept = departmentDAL.GetDepartmentProfile(rdr["DepartmentId"] as int? ?? default(int));
                    report.Status = (ReportStatus)Enum.Parse(typeof(ReportStatus), (string)rdr["Status"]);
                    report.CreatedBy = employeeDAL.GetEmployee(rdr["CreatedById"] as Guid? ?? default(Guid));
                    report.ApprovedBy = employeeDAL.GetEmployee(rdr["ApprovedById"] as Guid? ?? default(Guid));
                    report.ProcessedBy = employeeDAL.GetEmployee(rdr["ProcessedById"] as Guid? ?? default(Guid));
                    report.ApprovedDate = rdr["ApprovedDate"] as DateTime? ?? default(DateTime);
                    report.ExpenseItems = GetExpenseItemsByExpenseId(report.ExpenseId, out expenseTotal);
                    report.ExpenseTotal = expenseTotal;
                    expenseReports.Add(report);
                }

            }
            catch (Exception ex)
            {
                throw new Exception("There was a problem retrieving expense reports: " + ex.Message);
            }
            finally
            {
                daFunctions.Connection.Close();
            }

            return expenseReports;
        }
        public void ExpenseReport_CheckExpenseReportItemsIsNotNull_IsNotNull()
        {
            ExpenseReport expenseReport = new ExpenseReport();

            Assert.IsNotNull(expenseReport.ExpenseItems, "ExpenseReport ExpenseItems is null");
        }
        /// <summary>
        /// Inserts the expense report into the database
        /// </summary>
        /// <param name="expenseReport">Expense report object</param>
        public void ProcessExpense(ExpenseReport expenseReport)
        {
            expenseReport.ExpenseId = InsertExpenseHeader(expenseReport.CreatedBy.UserId, expenseReport.CreateDate, expenseReport.ExpenseToDept.DepartmentId, expenseReport.Status.ToString());

            foreach (ExpenseItem item in expenseReport.ExpenseItems)
            {
                item.ExpenseHeaderId = expenseReport.ExpenseId;
                InsertExpenseItem(item.ExpenseHeaderId, item.ExpenseDate, item.Location, item.Description, item.Amount, item.Currency, item.AudAmount, item.ReceiptFileName);
            }
        }
 public void ExpenseReportDAL_SupervisorActionOnExpenseReport_Reject_ActionSuccess()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("18b783f1-cb97-4e03-bb54-d3c41637b69c");
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.Submitted;
         item.ExpenseDate = DateTime.Now;
         item.Location = "London";
         item.Description = "AirTicket";
         item.Amount = 2000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         string status = "RejectedBySupervisor";
         Guid approvedBy = new Guid("832e2e47-e82c-40be-9c39-8587274468fe");
         expenseReportDAL.ProcessExpense(expenseReport);
         Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
         expenseReportDAL.SupervisorActionOnExpenseReport(expenseReport.ExpenseId, approvedBy, status);
         testTransaction.Dispose();
      }
 }
        public void ExpenseReportDAL_ProcessExpense_InsertSuccess()
        {
            ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();

            ExpenseReport expenseReport = new ExpenseReport();
            ExpenseItem item = new ExpenseItem();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy.UserId = new Guid("78560DD3-F95E-4011-B40D-A7B56ED17F24");
            expenseReport.CreatedBy.Dept.DepartmentId = 2;
            expenseReport.Status = ReportStatus.Submitted;

            item.ExpenseDate = DateTime.Now;
            item.Location = "Sydney";
            item.Description = "AirTicket";
            item.Amount = 2000;
            item.Currency = "AUD";
            item.AudAmount = item.Amount;

            expenseReport.ExpenseItems.Add(item);

            using (TransactionScope testTransaction = new TransactionScope())
            {
                expenseReportDAL.ProcessExpense(expenseReport);
                Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
                testTransaction.Dispose();
            }
        }
 public void ExpenseReportDAL_GetReportBySupervisor_StatusIsSubmitted_IsTrue()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         List<ExpenseReport> reports = new List<ExpenseReport>();
         int deptId = 1;
         string status = ReportStatus.Submitted.ToString();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("18b783f1-cb97-4e03-bb54-d3c41637b69c");
         expenseReport.ExpenseToDept.DepartmentId = 1;
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.Submitted;
         item.ExpenseDate = DateTime.Now;
         item.Location = "Sydney";
         item.Description = "AirTicket";
         item.Amount = 5000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         expenseReportDAL.ProcessExpense(expenseReport);
         Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
         reports = expenseReportDAL.GetReportsByDepartment(deptId, status);
         Assert.IsTrue(reports.Count > 0, "No data in expense report");
         testTransaction.Dispose();
     }
 }
 public void ExpenseReportDAL_GetReportBySupervisor_StatusIsApprovedByAccounts_IsTrue()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         List<ExpenseReport> reports = new List<ExpenseReport>();
         int deptId = 1;
         string status = ReportStatus.ApprovedByAccounts.ToString();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("78560dd3-f95e-4011-b40d-a7b56ed17f24");
         expenseReport.ExpenseToDept.DepartmentId = 1;
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.ApprovedByAccounts;
         item.ExpenseDate = DateTime.Now;
         item.Location = "Sydney";
         item.Description = "AirTicket";
         item.Amount = 5000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         expenseReportDAL.ProcessExpense(expenseReport);
         reports = expenseReportDAL.GetReportsByDepartment(deptId, status);
         Assert.IsTrue(reports.Count > 0, "No data in expense report");
         testTransaction.Dispose();
     }
 }
 public ExpenseReportBuilder()
 {
     expenseReport = new ExpenseReport();
     expDAL = new ExpenseReportDAL();
 }