public void TestConversion_ViewModelHasSubObject() { var viewModel = new TestViewModel() { Name = "Test Model - Changed", IsDone = true, PrimaryKey = 1, TestSubObject = new TestChildViewModel() { Name = "SubObject - Changed", Capacity = 500, ParentID = 1, PrimaryKey = 5 } }; viewModel.Children = new System.Collections.Generic.List <TestChildViewModel>(); var model = new TestModel() { Name = "Test Model", IsDoneIndicator = false.ToIndicator(), PrimaryKey = 1, TestSubObject = new TestChildModel() { Name = "SubObject", Capacity = 300, ParentID = 1, PrimaryKey = 5 } }; model.Children = new System.Collections.Generic.List <TestChildModel>(); var converter = new ViewModelToModelConverter(); converter.Convert(viewModel, model, typeof(TestModel)); Assert.AreEqual(viewModel.Name, model.Name); Assert.AreEqual(viewModel.IsDone, model.IsDoneIndicator.FromIndicator()); Assert.AreEqual(viewModel.TestSubObject.Name, model.TestSubObject.Name); Assert.AreEqual(viewModel.TestSubObject.Capacity, model.TestSubObject.Capacity); Assert.AreEqual(viewModel.TestSubObject.ParentID, model.TestSubObject.ParentID); Assert.AreEqual(viewModel.Children.Count, model.Children.Count); //for (int i = 0; i < viewModel.Children.Count; ++i) //{ // var vmChild = viewModel.Children[i]; // var mChild = model.Children[i]; // Assert.AreEqual(vmChild.Name, mChild.Name); // Assert.AreEqual(vmChild.Capacity, mChild.Capacity); //} }
public void TestConversion_NotExisting() { var viewModel = new TestViewModel() { Name = "Test Model - Changed", IsDone = true, PrimaryKey = null }; viewModel.Children = new System.Collections.Generic.List <TestChildViewModel>() { new TestChildViewModel() { Name = "Child 1 - Modified", Capacity = 100, ParentID = null, PrimaryKey = null }, new TestChildViewModel() { Name = "Child 2 - Modified", Capacity = 200, ParentID = null, PrimaryKey = null } }; var converter = new ViewModelToModelConverter(); var model = (TestModel)converter.Convert(viewModel, typeof(TestModel)); Assert.AreEqual(viewModel.Name, model.Name); Assert.AreEqual(viewModel.IsDone, model.IsDoneIndicator.FromIndicator()); Assert.AreEqual(viewModel.Children.Count, model.Children.Count); for (int i = 0; i < viewModel.Children.Count; ++i) { var vmChild = viewModel.Children[i]; var mChild = model.Children[i]; Assert.AreEqual(vmChild.Name, mChild.Name); Assert.AreEqual(vmChild.Capacity, mChild.Capacity); } }
public void TestConversion_ModelHasChildrenToDelete() { var viewModel = new TestViewModel() { Name = "Test Model - Changed", IsDone = true, PrimaryKey = 1 }; viewModel.Children = new System.Collections.Generic.List <TestChildViewModel>() { new TestChildViewModel() { Name = "Child 1 - Modified", Capacity = 100, ParentID = 1, PrimaryKey = 1 }, new TestChildViewModel() { Name = "Child 2 - Modified", Capacity = 200, ParentID = 1, PrimaryKey = 2 } }; var model = new TestModel() { Name = "Test Model", IsDoneIndicator = false.ToIndicator(), PrimaryKey = 1 }; model.Children = new System.Collections.Generic.List <TestChildModel>() { new TestChildModel() { Name = "Child 1", Capacity = 50, ParentID = 1, PrimaryKey = 1 }, new TestChildModel() { Name = "Child 2", Capacity = 100, ParentID = 1, PrimaryKey = 2 }, new TestChildModel() { Name = "Child 3", Capacity = 100, ParentID = 1, PrimaryKey = 3 } }; var converter = new ViewModelToModelConverter(); converter.Convert(viewModel, model, typeof(TestModel)); Assert.AreEqual(viewModel.Name, model.Name); Assert.AreEqual(viewModel.IsDone, model.IsDoneIndicator.FromIndicator()); Assert.AreEqual(viewModel.Children.Count, model.Children.Count); for (int i = 0; i < viewModel.Children.Count; ++i) { var vmChild = viewModel.Children[i]; var mChild = model.Children[i]; Assert.AreEqual(vmChild.Name, mChild.Name); Assert.AreEqual(vmChild.Capacity, mChild.Capacity); } }