public void ShouldGetZeroExpensesFromNonExistingUser() { var expected = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = new User { UserName = "******" }, ApproverName = "approver name" }; util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, expected); var repository = new ExpenseRepository(TestDatabaseConnectionString); var expenses = repository.GetExpensesByUser("no existing user name"); Assert.AreEqual(0, expenses.Count()); }
public void GetAllExpensesForApproval() { var expected = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = new User { UserName = "******" }, ApproverName = "approverName" }; var anotherExpense = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = new User { UserName = "******" }, ApproverName = "approverName" }; var notForMeExpense = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = new User { UserName = "******" }, ApproverName = "Another approverName" }; util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, expected); util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, anotherExpense); util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, notForMeExpense); var repository = new ExpenseRepository(TestDatabaseConnectionString); var expenses = repository.GetExpensesForApproval("approverName"); Assert.IsNotNull(expenses); Assert.AreEqual(2, expenses.Count()); }
public void ApproveExpense() { var expected = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = false, User = new User { UserName = "******" }, ApproverName = "approver name" }; util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, expected); var repository = new ExpenseRepository(TestDatabaseConnectionString); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Manager" }); repository.UpdateApproved(expected); var actual = util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expected.Id); Assert.IsNotNull(actual); Assert.AreEqual(expected.Approved, actual.Approved); }
public void ApproverIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { User = new User(), ApproverName = "Approver" }; var expenseEntity = expense.ToEntity(); Assert.AreEqual("Approver", expenseEntity.Approver); }
public void ReimbursementMethodIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { ReimbursementMethod = ReimbursementMethod.Cash, User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual(Enum.GetName(typeof(ReimbursementMethod), ReimbursementMethod.Cash), expenseEntity.ReimbursementMethod); }
public void ApprovedIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { Approved = true, User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual(true, expenseEntity.Approved); }
public void CostCenterIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { CostCenter = "Cost Center", User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual("Cost Center", expenseEntity.CostCenter); }
public void AmountIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { Total = 100.0, User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual(100.0, Convert.ToDouble(expenseEntity.Amount)); }
public void TitleIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { Title = "Title", User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual("Title", expenseEntity.Title); }
public void DescriptionIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { Description = "Description", User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual("Description", expenseEntity.Description); }
public void DateIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expectedDate = new DateTime(2000, 1, 1); var expense = new Model.Expense { Date = expectedDate, User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual(expectedDate, expenseEntity.Date); }
public void IdIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expectedId = Guid.NewGuid(); var expense = new Model.Expense { Id = expectedId, User = new User(), ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual(expectedId, expenseEntity.Id); }
public void UserNameIsCopiedWhenConvertingAnExpenseToAnExpenseEntity() { var expense = new Model.Expense { User = new User { UserName = "******" }, ApproverName = string.Empty }; var expenseEntity = expense.ToEntity(); Assert.AreEqual("User Name", expenseEntity.UserName); }
public void SaveExpense() { Guid expenseIdToSave = Guid.Empty; Assert.IsNull(util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave)); var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = stubUser, ApproverName = stubManager }; var repository = new ExpenseRepository(TestDatabaseConnectionString); repository.SaveExpense(expenseToSave); var expenseEntity = util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave); Assert.IsNotNull(expenseEntity); Assert.AreEqual(expenseToSave.Total, Convert.ToDouble(expenseEntity.Amount)); Assert.AreEqual(expenseToSave.Approved, expenseEntity.Approved); Assert.AreEqual(expenseToSave.CostCenter, expenseEntity.CostCenter); Assert.AreEqual(expenseToSave.Date, expenseEntity.Date); Assert.AreEqual(expenseToSave.Description, expenseEntity.Description); Assert.AreEqual(expenseToSave.Id, expenseEntity.Id); Assert.AreEqual(expenseToSave.ReimbursementMethod, Enum.Parse(typeof(ReimbursementMethod), expenseEntity.ReimbursementMethod)); Assert.AreEqual(expenseToSave.Title, expenseEntity.Title); Assert.AreEqual(expenseToSave.User.UserName, expenseEntity.UserName); Assert.AreEqual(expenseToSave.ApproverName, expenseEntity.Approver); }
public void GetAllExpenses() { var expected = new Model.Expense { Id = Guid.NewGuid(), Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = new User { UserName = "******" }, ApproverName = "approver name" }; util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, expected); var repository = new ExpenseRepository(TestDatabaseConnectionString); var expenses = repository.GetAllExpenses(); Assert.IsNotNull(expenses); var actual = expenses.ToList().Where(e => e.Id == expected.Id).FirstOrDefault(); Assert.IsNotNull(actual); Assert.AreEqual(expected.Total, actual.Total); Assert.AreEqual(expected.Approved, actual.Approved); Assert.AreEqual(expected.CostCenter, actual.CostCenter); Assert.AreEqual(expected.Date, actual.Date); Assert.AreEqual(expected.Description, actual.Description); Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.ReimbursementMethod, actual.ReimbursementMethod); Assert.AreEqual(expected.Title, actual.Title); Assert.AreEqual(expected.User.UserName, actual.User.UserName); }