public void AddReport_GivenValidExpense_AddsReportAndExpenseToDB2() { DateTime date = DateTime.Now.Date; string reportName = "REPORT"; string location = "Broadway"; string description = "food"; string strAmount = "100.1111"; double amount = Math.Round(100.1111, 2); double amount_aud = 148.16; string currency = "Euros"; byte[] receipt = new byte[] { 2, 3, 4, 2 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("41651a9d-3122-4ea2-bfe0-dca38d7248d1"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, currency, receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("PROCESSING", report.Supervisor_approval); Assert.AreEqual("PROCESSING", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual(consultant.Username, report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } ExpensesTableAdapter adapter2 = new ExpensesTableAdapter(); Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable(); adapter2.FillByReportId(expensesTable, reportId); foreach (Reports.ExpensesRow expense in expensesTable) { Assert.AreEqual(date, expense.Date); Assert.AreEqual(location, expense.Location); Assert.AreEqual(description, expense.Description); Assert.AreEqual(amount, expense.Amount); Assert.AreEqual(currency, expense.Currency); Assert.AreEqual(amount_aud, expense.Amount_aud); } testTransaction.Dispose(); // rollback } }
/* * This will all expenses of selected report. */ public Reports.ExpensesDataTable GetExpenses(int reportId) { ExpensesTableAdapter adapter = new ExpensesTableAdapter(); Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable(); adapter.FillByReportId(expensesTable, reportId); return expensesTable; }
public void AddReport_GivenValidExpense_AddsReportAndExpenseToDB() { DateTime date = DateTime.Now.Date; string reportName = "report"; string location = "AA"; string description = "BB"; string strAmount = "100"; double amount = Math.Round(100.000, 2); string currency = "AUD"; byte[] receipt = new byte[] { 1, 2, 3, 4 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("ce65a8ac-728b-405e-a00d-4a14e6ad23dc"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, currency, receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("PROCESSING", report.Supervisor_approval); Assert.AreEqual("PROCESSING", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual("ce65a8ac-728b-405e-a00d-4a14e6ad23dc", report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } ExpensesTableAdapter adapter2 = new ExpensesTableAdapter(); Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable(); adapter2.FillByReportId(expensesTable, reportId); foreach (Reports.ExpensesRow expense in expensesTable) { Assert.AreEqual(date, expense.Date); Assert.AreEqual(location, expense.Location); Assert.AreEqual(description, expense.Description); Assert.AreEqual(amount, expense.Amount); Assert.AreEqual(currency, expense.Currency); Assert.AreEqual(amount, expense.Amount_aud); } testTransaction.Dispose(); // rollback } }