public void ExpenseRepository_GetById_Returns_Object_If_Found() { var testDataWithID = baseTestData.Copy(); testDataWithID.Id = 1; var mock = RepositoryMocks.GetMockExpenseRepository(new List <Expense> { testDataWithID }); var actual = mock.GetById(1); Assert.AreEqual(testDataWithID, actual); }
public void Expense_Copy() { var first = new Expense { Amount = 120, Category = new ExpenseCategory { Id = 0, Name = "Category" }, Comments = "Stuff", Date = DateTime.Today, Id = 0, Method = new PaymentMethod { Id = 0, Name = "Method" } }; var second = first.Copy(); Assert.AreNotSame(first, second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(second.Equals(first)); }
public void MonthService_GetExpensesForMonth_No_Matching_Data_Returns_Empty_List() { var data = Enumerable.Range(1, 5) .Select(i => { var c = expenseBaseTestData.Copy(); c.Id = i; c.Date = new DateTime(2015, 3, 3); c.Amount = (decimal)Math.Pow(i, i); return(c); }) .ToList(); var mock = ServiceMocks.GetMockMonthService(data); var actual = mock.GetExpensesForMonth(new DateTime(2010, 1, 1)); CollectionAssert.AreEquivalent(new List <Expense>(), actual.ToList()); }
/// <summary> /// Sets the intial state and current state expense properties of the form /// </summary> /// <param name="expense">The expense the form was opened for</param> public ExpenseViewer(Expense expense) { currentExpense = expense; // Makes a shallow copy of the expense passed in originalExpense = currentExpense.Copy(); InitializeComponent(); _dataContext = new AccountingDataContext(); _expenseService = new ExpenseService(new ExpenseRepository(_dataContext)); _expenseCategoryService = new ExpenseCategoryService(new ExpenseCategoryRepository(_dataContext)); _paymentMethodService = new PaymentMethodService(new PaymentMethodRepository(_dataContext)); }
/// <summary> /// Cancels the edit and leaves the form open /// -clears any changes made /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCancel_Click(object sender, EventArgs e) { // Enables the controls for editing and updates which buttons are visible ToggleEnableControls(txtAmount, txtDetail, cmbCategory, cmbPayment, dtPick, btnSave, btnEdit, btnCancel, btnDelete); ToggleVisibility(btnSave, btnCancel, btnEdit, btnDelete); // Makes sure that the expense of the binding has the origional values currentExpense = originalExpense.Copy(); // Resets the data bindings SetDataBindings(); }
public void ExpenseService_GetAll_Returns_Data() { var data = Enumerable.Range(1, 5) .Select(i => { var c = baseTestData.Copy(); c.Id = i; c.Amount = (decimal)Math.Pow(i, i); return(c); }) .ToList(); var mock = ServiceMocks.GetMockExpenseService(data); var actual = mock.LoadAll(); CollectionAssert.AreEquivalent(data, actual.ToList()); }