public ActionResult Create([FromBody] ServingViewModel vm) { var rt = vm.ToServing(); var res = _bo.Create(rt); return(res.Success ? Ok() : InternalServerError()); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNonDeletedAsync(); if (!listOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = listOperation.Exception.Message })); } var mIds = listOperation.Result.Select(x => x.MenuId).Distinct().ToList(); var cIds = listOperation.Result.Select(x => x.CourseId).Distinct().ToList(); var dIds = listOperation.Result.Select(x => x.DishId).Distinct().ToList(); var lst = new List <ServingViewModel>(); foreach (var item in listOperation.Result) { lst.Add(ServingViewModel.Parse(item)); } ViewData["Title"] = "Servings"; ViewData["Breadcrumbs"] = GetCrumbs(); ViewData["Menus"] = await GetMenuViewModels(mIds); ViewData["Courses"] = await GetCourseViewModels(cIds); ViewData["Dishes"] = await GetDishViewModels(dIds); return(View(lst)); }
public async Task <IActionResult> Edit(Guid id, ServingViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = getOperation.Exception.Message })); } if (getOperation.Result == null) { return(NotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToModel(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = updateOperation.Exception.Message })); } } } return(RedirectToAction(nameof(Index))); }
public ActionResult Create([FromBody] ServingViewModel vm) { var s = vm.ToServing(); var res = _bo.Create(s); return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError)); }
public async Task <IActionResult> Update([FromBody] ServingViewModel vm) { var getResult = await _bo.ReadAsync(vm.Id); if (!getResult.Success) { return(InternalServerError(getResult.Exception)); } var item = getResult.Result; if (item == null) { return(NotFound()); } if (vm.CompareToModel(item)) { return(NotModified()); } item = vm.ToModel(item); var updateResult = await _bo.UpdateAsync(item); if (!updateResult.Success) { return(InternalServerError(updateResult.Exception)); } return(Ok()); }
public ActionResult Create([FromBody] ServingViewModel vm) { var s = new Serving(vm.MenuId, vm.CourseId, vm.DishId); var res = _bo.Create(s); var code = res.Success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; return(new ObjectResult(code)); }
public void Serving([FromBody] ServingViewModel serving) { servingService.InsertServing(new Serving { Id = Guid.NewGuid(), Meal = serving.Meal, Name = serving.Name, Price = serving.Price }); }
public async Task <IActionResult> CreateAsync([FromBody] ServingViewModel vm) { var newItem = vm.ToModel(); var result = await _bo.CreateAsync(newItem); if (!result.Success) { return(InternalServerError(result.Exception)); } return(Created(Request.Path.Value, null)); }
public void Serving(Guid id, [FromBody] ServingViewModel patch) { servingService.UpdateServing(new Serving { Id = id, Meal = patch.Meal, Name = patch.Name, Price = patch.Price }); }
public ActionResult <List <ServingViewModel> > List() { var res = _bo.List(); if (!res.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var list = new List <ServingViewModel>(); foreach (var item in res.Result) { list.Add(ServingViewModel.Parse(item)); } return(list); }
public async Task <IActionResult> Create(ServingViewModel vm) { if (ModelState.IsValid) { var model = vm.ToModel(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = createOperation.Exception.Message })); } return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> GetAsync(Guid id) { var getResult = await _bo.ReadAsync(id); if (!getResult.Success) { return(InternalServerError(getResult.Exception)); } var item = getResult.Result; if (item == null) { return(NotFound()); } var vm = ServingViewModel.Parse(item); return(Ok(vm)); }
public async Task <IActionResult> ListAsync() { var listResult = await _bo.ListNonDeletedAsync(); if (!listResult.Success) { return(InternalServerError(listResult.Exception)); } var list = listResult.Result; var lst = new List <ServingViewModel>(); foreach (var item in list) { var vm = ServingViewModel.Parse(item); lst.Add(vm); } return(Ok(lst)); }
public ActionResult <ServingViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var svm = ServingViewModel.Parse(res.Result); return(svm); } else { return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public void ServingViewModelEditting() { MealType pi = new MealType( Guid.NewGuid(), "pi", "not the tasty kind", DateTime.Now, false ); MealType unity = new MealType( Guid.NewGuid(), "unity", "it is itself", DateTime.Now, false ); MealType golden = new MealType( Guid.NewGuid(), "golden", "it is very nice", DateTime.Now, false ); ServingViewModel<MealType> servingViewModel = new ServingViewModel<MealType>( pi, 3.14159M ); // Cancel Test. Begin the edit, change the data, then cancel. servingViewModel.BeginEdit(); servingViewModel.Entity = unity; servingViewModel.Quantity = 1; Assert.AreEqual( unity, servingViewModel.Entity ); Assert.AreEqual( 1, servingViewModel.Quantity ); servingViewModel.CancelEdit(); Assert.AreEqual( pi, servingViewModel.Entity ); Assert.AreEqual( 3.14159M, servingViewModel.Quantity ); // In Transaction Test. Begin the edit, change the data, begin again, cancel. Data should still match original. servingViewModel.BeginEdit(); servingViewModel.Entity = unity; servingViewModel.Quantity = 1; Assert.AreEqual( unity, servingViewModel.Entity ); Assert.AreEqual( 1, servingViewModel.Quantity ); servingViewModel.BeginEdit(); servingViewModel.Entity = golden; servingViewModel.Quantity = 1.61803M; Assert.AreEqual( golden, servingViewModel.Entity ); Assert.AreEqual( 1.61803M, servingViewModel.Quantity ); servingViewModel.CancelEdit(); Assert.AreEqual( pi, servingViewModel.Entity ); Assert.AreEqual( 3.14159M, servingViewModel.Quantity ); // End Edit Test. Begin the edit, change the data, end the edit, change should stick servingViewModel.BeginEdit(); servingViewModel.Entity = golden; servingViewModel.Quantity = 1.61803M; Assert.AreEqual( golden, servingViewModel.Entity ); Assert.AreEqual( 1.61803M, servingViewModel.Quantity ); servingViewModel.EndEdit(); Assert.AreEqual( golden, servingViewModel.Entity ); Assert.AreEqual( 1.61803M, servingViewModel.Quantity ); }
public ActionResult Update([FromBody] ServingViewModel s) { var currentResult = _bo.Read(s.Id); if (!currentResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.MenuId == s.MenuId && current.CourseId == s.CourseId && current.DishId == s.DishId) { return(StatusCode((int)HttpStatusCode.NotModified)); } if (current.MenuId != s.MenuId) { current.MenuId = s.MenuId; } if (current.CourseId != s.CourseId) { current.CourseId = s.CourseId; } if (current.DishId != s.DishId) { current.DishId = s.DishId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok()); }
public void ServingViewModelDefault() { FoodGroup foodGroupOne = new FoodGroup( Guid.NewGuid(), "FoodGroupOne", "Test Food Group One" ); ServingViewModel<FoodGroup> servingViewModel = new ServingViewModel<FoodGroup>(); Assert.IsFalse( servingViewModel.IsValid ); Assert.IsNull( servingViewModel.Entity ); Assert.AreEqual( 0, servingViewModel.Quantity ); Assert.AreEqual( Messages.Error_No_Quantity, servingViewModel["Quantity"] ); Assert.AreEqual( Messages.Error_No_ServingItem, servingViewModel["Entity"] ); servingViewModel.Quantity = 42; Assert.IsFalse( servingViewModel.IsValid ); Assert.IsNull( servingViewModel["Quantity"] ); Assert.AreEqual( Messages.Error_No_ServingItem, servingViewModel["Entity"] ); servingViewModel.Entity = foodGroupOne; Assert.IsTrue( servingViewModel.IsValid ); Assert.IsNull( servingViewModel["Quantity"] ); Assert.IsNull( servingViewModel["Entity"] ); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(View("Error", getOperation.Exception.Message)); } if (getOperation.Result == null) { return(NotFound()); } var vm = ServingViewModel.Parse(getOperation.Result); ViewData["Header"] = "Serving"; return(View(vm)); }
public ActionResult Update([FromBody] ServingViewModel bk) { var currentResult = _bo.Read(bk.Id); if (!currentResult.Success) { return(InternalServerError()); } var current = currentResult.Result; if (current == null) { return(NotFound()); } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = getOperation.Exception.Message })); } if (getOperation.Result == null) { return(NotFound()); } var vm = ServingViewModel.Parse(getOperation.Result); return(View(vm)); }
public void FoodItemViewModelIsDirty() { var loggerMock = new Mock<ILoggerFacade>(); var regionNavigationServiceMock = new Mock<IRegionNavigationService>(); var regionManagerMock = new Mock<IRegionManager>(); var interactionServiceMock = new Mock<IInteractionService>(); var configurationMock = new Mock<IConfiguration>(); configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile ); configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName ); FullTestData.Reset(); var dataRepository = new DataRepository( configurationMock.Object ); // Existing Food Item // Starts clean // Change Name - dirty // Undo - clean // Change Description - dirty // Undo - clean // Change Calories - dirty // Undo - clean // Change Food Group Serving - dirty // Undo - clean // Add food group - dirty // undo - clean // FoodItem cheeseBurger = dataRepository.GetFoodItem( FullTestData.CheeseBurgerID ); Assert.IsNotNull( cheeseBurger ); String originalName = cheeseBurger.Name; String originalDescription = cheeseBurger.Description; FoodItemViewModel cheeseBurgerViewModel = new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object ); NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + cheeseBurger.ID.ToString(), UriKind.Relative ) ); cheeseBurgerViewModel.OnNavigatedTo( navigationContext ); Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Name += "Modified"; Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Name = originalName; Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Description += "Different"; Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Description = originalDescription; Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Name = null; Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.Name = originalName; Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.CaloriesPerServing += 90; Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.CaloriesPerServing -= 90; Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.FoodGroupsPerServing[0].Quantity += 1; Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.FoodGroupsPerServing[0].Quantity -= 1; Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); ServingViewModel<FoodGroup> serving = cheeseBurgerViewModel.FoodGroupsPerServing[0]; cheeseBurgerViewModel.FoodGroupsPerServing.Remove( serving ); Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); // Create an exact duplicate of the servings. ServingViewModel<FoodGroup> copyOfServing = new ServingViewModel<FoodGroup>( serving.Entity, serving.Quantity ); cheeseBurgerViewModel.FoodGroupsPerServing.Add( copyOfServing ); Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); serving = new ServingViewModel<FoodGroup>( dataRepository.FindFoodGroup( fg => fg.Name == "Water" ), 1 ); cheeseBurgerViewModel.FoodGroupsPerServing.Add( serving ); Assert.IsTrue( cheeseBurgerViewModel.IsDirty ); cheeseBurgerViewModel.FoodGroupsPerServing.Remove( serving ); Assert.IsFalse( cheeseBurgerViewModel.IsDirty ); }
public void FoodItemViewModelUndoRedo() { var loggerMock = new Mock<ILoggerFacade>(); Mock<IRegionNavigationService> regionNavigationServiceMock = new Mock<IRegionNavigationService>(); Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>(); Mock<IInteractionService> interactionServiceMock = new Mock<IInteractionService>(); var configurationMock = new Mock<IConfiguration>(); configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile ); configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName ); FullTestData.Reset(); DataRepository dataRepository = new DataRepository( configurationMock.Object ); // TODO: Update this test when the undo and redo is expanded. // TODO: Update this test to include Calories (can be done before expansion) // Should not be able to undo or redo on a new object. ServingViewModel<FoodGroup> waterServing = new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.WaterID ), 1.0M ); ServingViewModel<FoodGroup> meatServing = new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.MeatID ), 1.5M ); ServingViewModel<FoodGroup> fruitServing = new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.FruitID ), 2.5M ); FoodItemViewModel foodItemViewModel = new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object ); NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView", UriKind.Relative ) ); foodItemViewModel.OnNavigatedTo( navigationContext ); Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Assign values to properties, save, and the load into new view model to reset the undo/redo log foodItemViewModel.Name = "Bob"; foodItemViewModel.Description = "Battery Operated Buddy"; foodItemViewModel.CaloriesPerServing = 42.0M; foodItemViewModel.FoodGroupsPerServing.Add( waterServing ); navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + foodItemViewModel.ID.ToString(), UriKind.Relative ) ); foodItemViewModel.SaveCommand.Execute( null ); foodItemViewModel = new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object ); foodItemViewModel.OnNavigatedTo( navigationContext ); Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Make changes as such: // o name changed from Bob to Pete // o name changed from Pete to Peter // o Description changed from "Battery Operated Buddy" to "The Rock" // o Add Meat food group serving (1.5) // o Change Calroies to 69 // o Add Fruit food group serving (2.5) // o Change Meat servings to 3 // o Remove the Fruit food serving // o name changed from Peter to Simon // o name changed from Simon to Saul // o description changed from "The Rock" to "The Persecutor" // o description changed from "The Persecutor" to "The Apostle" // o name changed from Saul to Paul // Verify can undo, cannot redo at each step foodItemViewModel.Name = "Pete"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Name += "r"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Description = "The Rock"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.FoodGroupsPerServing.Add( meatServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.CaloriesPerServing = 69; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.FoodGroupsPerServing.Add( fruitServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); meatServing.Quantity = 3; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.FoodGroupsPerServing.Remove( fruitServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Name = "Simon"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Name = "Saul"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Description = "The Persecutor"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Description = "The Apostle"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.Name = "Paul"; Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); Assert.AreEqual( "Paul", foodItemViewModel.Name ); Assert.AreEqual( "The Apostle", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); // Undo once. Verify last thing done is undone, and we can redo. foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Apostle", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Redo. Verify last thing undone is redone, can no longer redo, can still undo. foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Paul", foodItemViewModel.Name ); Assert.AreEqual( "The Apostle", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Undo 4 times, verify undo worked foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Apostle", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Persecutor", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Simon", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Redo 2 times, verify foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Persecutor", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Undo until back to original, cannot undo, can redo foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Saul", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 3, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Simon", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 3, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 3, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 3, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( fruitServing ) ); Assert.AreEqual( 3, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 3, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( fruitServing ) ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Pete", foodItemViewModel.Name ); Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.UndoCommand.Execute( null ); Assert.AreEqual( "Bob", foodItemViewModel.Name ); Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 1.5M, meatServing.Quantity ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); // Redo 4 times, verify foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Pete", foodItemViewModel.Name ); Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); foodItemViewModel.RedoCommand.Execute( null ); Assert.AreEqual( "Peter", foodItemViewModel.Name ); Assert.AreEqual( "The Rock", foodItemViewModel.Description ); Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) ); Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing ); Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) ); Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) ); }
public void ServingViewModelEntityQuantity() { FoodGroup foodGroupOne = new FoodGroup( Guid.NewGuid(), "Food Group One", "Test Food Group One" ); ServingViewModel<FoodGroup> servingViewModel = new ServingViewModel<FoodGroup>( foodGroupOne, 43 ); Assert.IsTrue( servingViewModel.IsValid ); Assert.AreEqual( foodGroupOne, servingViewModel.Entity ); Assert.AreEqual( 43, servingViewModel.Quantity ); Assert.IsNull( servingViewModel["Quantity"] ); Assert.IsNull( servingViewModel["Entity"] ); }
public void FoodItemViewModelFoodGroupServings() { var loggerMock = new Mock<ILoggerFacade>(); var regionNavigationServiceMock = new Mock<IRegionNavigationService>(); var regionManagerMock = new Mock<IRegionManager>(); var interactionServiceMock = new Mock<IInteractionService>(); var configurationMock = new Mock<IConfiguration>(); configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile ); configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName ); FullTestData.Reset(); var dataRepository = new DataRepository( configurationMock.Object ); PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler(); // Navigate to a known food group mealType and make sure the food group servings makes sense. // NOTE: No need to get too fancy, the model tests makes sure the data loaded properly. FoodItem foodItem = dataRepository.GetFoodItem( FullTestData.CheeseBurgerID ); FoodItemViewModel foodItemViewModel = new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object ); NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + foodItem.ID.ToString(), UriKind.Relative ) ); foodItemViewModel.OnNavigatedTo( navigationContext ); foodItemViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged; Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsFalse( foodItemViewModel.IsDirty ); Assert.IsTrue( foodItemViewModel.IsValid ); // Add a food group ServingViewModel<FoodGroup> testFoodServings = new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.JunkFoodID ), 1 ); foodItemViewModel.FoodGroupsPerServing.Add( testFoodServings ); Assert.IsTrue( foodItemViewModel.IsDirty ); Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); foodItemViewModel.FoodGroupsPerServing.Remove( testFoodServings ); Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsFalse( foodItemViewModel.IsDirty ); propertyChangedHandler.Reset(); // Delete a food group testFoodServings = foodItemViewModel.FoodGroupsPerServing.ElementAt( 0 ); foodItemViewModel.FoodGroupsPerServing.Remove( testFoodServings ); Assert.IsTrue( foodItemViewModel.IsDirty ); Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); foodItemViewModel.FoodGroupsPerServing.Add( testFoodServings ); Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsFalse( foodItemViewModel.IsDirty ); propertyChangedHandler.Reset(); // Modify a food group foodItemViewModel.FoodGroupsPerServing[0].Quantity += 1; Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count ); Serving<FoodGroup> modelServing = foodItem.FoodGroupsPerServing.Find( f => f.Entity.ID == foodItemViewModel.FoodGroupsPerServing[0].Entity.ID ); Assert.IsNotNull( modelServing ); Assert.IsTrue( foodItemViewModel.IsDirty ); Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); foodItemViewModel.FoodGroupsPerServing[0].Quantity -= 1; Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsFalse( foodItemViewModel.IsDirty ); propertyChangedHandler.Reset(); // Make a serving invalid. foodItemViewModel.FoodGroupsPerServing[0].Quantity *= -1; Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count ); Assert.IsTrue( foodItemViewModel.IsDirty ); Assert.IsFalse( foodItemViewModel.IsValid ); Assert.AreEqual( Messages.Error_No_Quantity, foodItemViewModel.Error ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); foodItemViewModel.FoodGroupsPerServing[0].Quantity *= -1; Assert.IsTrue( foodItemViewModel.IsValid ); Assert.IsFalse( foodItemViewModel.IsDirty ); propertyChangedHandler.Reset(); // Remove all food groups foodItemViewModel.FoodGroupsPerServing.Clear(); Assert.IsTrue( foodItemViewModel.IsDirty ); Assert.IsFalse( foodItemViewModel.IsValid ); Assert.AreEqual( Messages.Error_No_FoodGroups, foodItemViewModel.Error ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); }
public override void OnNavigatedTo( NavigationContext navigationContext ) { if (Model == null) { String idParameter = navigationContext.Parameters["ID"]; Guid myID; FoodItem foodItem = null; if (idParameter != null && Guid.TryParse( idParameter, out myID )) { foodItem = this.DataRepository.GetFoodItem( myID ); } else { foodItem = new FoodItem(); } Model = foodItem; // TODO: Read up and see if there is a better way of diabling the event. // Also, refactor this into a private method. FoodGroupsPerServing.CollectionChanged -= OnFoodGroupServingsChanged; FoodGroupsPerServing.Clear(); foreach (Serving<FoodGroup> serving in foodItem.FoodGroupsPerServing) { ServingViewModel<FoodGroup> servingViewModel = new ServingViewModel<FoodGroup>( serving ); servingViewModel.PropertyChanged += OnFoodGroupServingPropertyChanged; FoodGroupsPerServing.Add( servingViewModel ); } FoodGroupsPerServing.CollectionChanged += OnFoodGroupServingsChanged; base.OnNavigatedTo( navigationContext ); } }
public override void OnNavigatedTo( NavigationContext navigationContext ) { FoodItemServings.CollectionChanged -= this.OnFoodItemServingsChanged; FoodItemServings.Clear(); foreach (Serving<FoodItem> foodItemServing in ((MealBase)Model).FoodItemServings) { ServingViewModel<FoodItem> foodItemServingViewModel = new ServingViewModel<FoodItem>( foodItemServing ); foodItemServingViewModel.PropertyChanged += this.OnFoodItemServingPropertyChanged; FoodItemServings.Add( foodItemServingViewModel ); } FoodItemServings.CollectionChanged += this.OnFoodItemServingsChanged; RebuildFoodGroupServingList(); // Assume that the time is automatically set if the time of the meal matches the time on the meal type. if (TypeOfMeal != null) { _timeSetManually = !(TypeOfMeal.UseDefaultMealTime && (TypeOfMeal.DefaultTimeOfMeal.TimeOfDay == TimeOfMeal.TimeOfDay)); } else { _timeSetManually = false; } base.OnNavigatedTo( navigationContext ); }
public void ServingViewModelServing() { FoodGroup foodGroupOne = new FoodGroup( Guid.NewGuid(), "FoodGroupOne", "Test Food Group #1" ); Serving<FoodGroup> serving = new Serving<FoodGroup>( foodGroupOne, 2.5M ); ServingViewModel<FoodGroup> servingViewModel = new ServingViewModel<FoodGroup>( serving ); Assert.IsTrue( servingViewModel.IsValid ); Assert.AreEqual( foodGroupOne, servingViewModel.Entity ); Assert.AreEqual( 2.5M, servingViewModel.Quantity ); Assert.IsNull( servingViewModel["Quantity"] ); Assert.IsNull( servingViewModel["Entity"] ); }
public void ServingViewModelPropertyChanged() { MealType pi = new MealType( Guid.NewGuid(), "pi", "not the tasty kind", DateTime.Now, false ); MealType e = new MealType( Guid.NewGuid(), "e", "exponent", DateTime.Now, false ); PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler(); Serving<MealType> serving = new Serving<MealType>( pi, 3.14159M ); ServingViewModel<MealType> servingViewModel = new ServingViewModel<MealType>( serving ); servingViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged; Assert.AreEqual( pi, servingViewModel.Entity ); Assert.AreEqual( 3.14159M, servingViewModel.Quantity ); Assert.IsNull( propertyChangedHandler.Sender ); Assert.AreEqual( 0, propertyChangedHandler.PropertiesChanged.Count ); servingViewModel.Entity = e; Assert.AreEqual( servingViewModel, propertyChangedHandler.Sender ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Entity" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( e, serving.Entity ); Assert.AreEqual( 3.14159M, serving.Quantity ); propertyChangedHandler.Reset(); servingViewModel.Quantity = 2.71828183M; Assert.AreEqual( servingViewModel, propertyChangedHandler.Sender ); Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Quantity" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) ); Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) ); Assert.AreEqual( e, serving.Entity ); Assert.AreEqual( 2.71828183M, serving.Quantity ); }
public void ServingViewModelIsDirty() { FoodGroup foodGroupOne = new FoodGroup( Guid.NewGuid(), "FoodGroupOne", "Test Food Group #1" ); FoodGroup foodGroupTwo = new FoodGroup( Guid.NewGuid(), "FoodGroupTwo", "Test Food Group #2" ); FoodGroup foodGroupThree = new FoodGroup( Guid.NewGuid(), "FoodGroupThree", "Test Food Group #3" ); // Upon creation, the view model should be clean. ServingViewModel<FoodGroup> servingViewModel = new ServingViewModel<FoodGroup>( foodGroupOne, 2 ); Assert.IsFalse( servingViewModel.IsDirty ); // Change the Entity, the view model should be dirty servingViewModel.Entity = foodGroupTwo; Assert.IsTrue( servingViewModel.IsDirty ); // Change the Entity back to the original value, the view model should no longer be dirty servingViewModel.Entity = foodGroupOne; Assert.IsFalse( servingViewModel.IsDirty ); // Change the Quantity, the view model should be dirty servingViewModel.Quantity = 3; Assert.IsTrue( servingViewModel.IsDirty ); // Change the Quantity back to the original value, the view model should no lonber be dirty servingViewModel.Quantity = 2; Assert.IsFalse( servingViewModel.IsDirty ); // Make it dirty again, then reset the cache, the flag should fo false. servingViewModel.Entity = foodGroupThree; servingViewModel.Quantity = 4.5M; Assert.IsTrue( servingViewModel.IsDirty ); servingViewModel.ResetPreviousValueCache(); Assert.IsFalse( servingViewModel.IsDirty ); }