Ejemplo n.º 1
0
        public void EditTripViewModel()
        {
            var trip = new Trip
                {
                    ChangeSetN = 1,
                    DisplayName = "Trip to Paris",
                    RowId = Guid.NewGuid(),
                    TripId = 1,
                    Expenses = new List<Expense>()
                };

            var oldRowId = trip.RowId;
            var tripViewModel = new TripViewModel { Model = trip };

            tripViewModel.LoadFromModel();

            Assert.AreEqual(trip.DisplayName, tripViewModel.DisplayName);
            Assert.AreEqual(trip.Expenses.Count, tripViewModel.Expenses.Count);

            tripViewModel.DisplayName = "Trip to Paris/Rome";
            tripViewModel.SaveToModel();

            Assert.AreNotEqual(oldRowId, trip.RowId);
            Assert.AreEqual(trip.DisplayName, tripViewModel.DisplayName);
        }
Ejemplo n.º 2
0
        public ActionResult Create(Trip collection)
        {
            if (ModelState.IsValid)
            {
                db.Trips.Add(collection);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(collection);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void EditTripViewModelWithNoChanges()
        {
            var trip = new Trip
            {
                ChangeSetN = 1,
                DisplayName = "Trip to Paris",
                RowId = Guid.NewGuid(),
                TripId = 1,
                Expenses = new List<Expense>()
            };

            var oldRowId = trip.RowId;
            var tripViewModel = new TripViewModel { Model = trip };

            tripViewModel.LoadFromModel();

            Assert.AreEqual(trip.DisplayName, tripViewModel.DisplayName);
            Assert.AreEqual(trip.Expenses.Count, tripViewModel.Expenses.Count);

            tripViewModel.SaveToModel();

            Assert.AreEqual(oldRowId, trip.RowId, "The row id should not change unless changes were made.");
            Assert.AreEqual(trip.DisplayName, tripViewModel.DisplayName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The application bar new trip button click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ApplicationBarNewTripButtonClick(object sender, EventArgs e)
        {
            var newTripModel = new Trip
                {
                   RowId = Guid.NewGuid(), Expenses = new List<Expense>(), DisplayName = "New trip"
                };
            var newTripModelId = Repository.Instance.Add(newTripModel);

            this.NavigationService.Navigate(
                new Uri("/Views/TripView.xaml?id=" + newTripModelId + "&PanoramaItem=Settings", UriKind.Relative));
        }
Ejemplo n.º 6
0
 public ActionResult Edit(Trip collection)
 {
     if (ModelState.IsValid)
     {
         db.Entry(collection).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(collection);
 }