Beispiel #1
0
        public void EditExpense()
        {
            var person1 = new Person { ChangeSetN = 1, DisplayName = "Bobby", PersonId = 1, RowId = Guid.NewGuid() };
            var person2 = new Person { ChangeSetN = 1, DisplayName = "Sophie", PersonId = 2, RowId = Guid.NewGuid() };
            var person3 = new Person { ChangeSetN = 1, DisplayName = "Glenn", PersonId = 3, RowId = Guid.NewGuid() };

            var trip = new Trip
                {
                    ChangeSetN = 1,
                    DisplayName = "Paris 2011",
                    RowId = Guid.NewGuid(),
                    TripId = 1
                };

            var expense = new Expense
                {
                    Amount = 100,
                    ChangeSetN = 1,
                    DisplayName = "Beers",
                    ExpenseId = 1,
                    Sender = person1,
                    Receivers = new List<Person> { person1, person2 },
                    RecordDate = new DateTime(2011, 01, 02, 15, 30, 00),
                    RowId = Guid.NewGuid(),
                    Trip = trip
                };

            var oldExpenseRowId = expense.RowId;

            var viewModel = new ExpenseViewModel { Model = expense };

            viewModel.LoadFromModel();

            // Switch the payer from person1 to person3 (and also receiver)
            viewModel.Sender = person3;
            viewModel.Receivers.Remove(person1);
            viewModel.Receivers.Add(person3);

            viewModel.SaveToModel();

            Assert.AreEqual(100, expense.Amount);
            Assert.AreEqual(1, expense.ExpenseId);
            Assert.AreEqual(expense.Sender, person3);
            Assert.AreEqual(2, expense.Receivers.Count);
            Assert.IsTrue(expense.Receivers.Contains(person2));
            Assert.IsTrue(expense.Receivers.Contains(person3));
            Assert.AreEqual(new DateTime(2011, 01, 02, 15, 30, 00), expense.RecordDate);
            Assert.AreNotEqual(oldExpenseRowId, expense.RowId);
            Assert.AreEqual(expense.Trip, trip);
        }