// -------------------------------------------------------------------------------------------------------------------------- public NewWineEntry(LegacyWineEntry oldData) { // Basic copy.... DTOMapper.CopyMembers(oldData, this); // Now the manual stuff..... Label = oldData.Name; Variety = oldData.Varietal; WineType = TranslateType(oldData.Type, oldData.Varietal); Qty = oldData.Bottles; BottleSize = oldData.Size; Best = oldData.PeakYear; UserNotes1 = oldData.TastingNotes; UserNotes2 = oldData.Notes + Environment.NewLine + oldData.ExtendedNotes; //RackNames = string.Join(" Location = oldData.Location; // + ", " + oldData.Position; UserField3 = oldData.Position; // This is how we will handle the racks.... if (oldData.Bottles == "1") { RackNames = "Rack 1"; RackCols = "1"; RackRows = "1"; } }
public void CanCopyTypeWithNullListToNonWritableList() { ListHost3 from = new ListHost3(); ListHost3 to = new ListHost3(new List <int>() { 1, 2, 3 }); // NOTE: Because the target item isn't directly settable, the best we can do is clear it out. DTOMapper.CopyMembers(from, to); Assert.AreEqual(0, to.IntList.Count, "The target list should be empty!"); // Show that the item will remain null. We basically wrote this to avoid a crash. to = new ListHost3(); DTOMapper.CopyMembers(from, to); Assert.IsNull(to.IntList); }
public void CanCopyLists() { string[] names = new[] { "Frank", "Larry", "David", "Chet", "Marla" }; ListHost1 source = new ListHost1(); for (int i = 0; i < names.Length; i++) { source.IntList.Add(i); source.Names.Add(names[i]); source.Types.Add(new SomeType() { Count = i + 100, Name = names[i], }); } ListHost2 comp = new ListHost2(); DTOMapper.CopyMembers(source, comp); drewCo.UnitTesting.ObjectInspector inspector = new UnitTesting.ObjectInspector(); var compIntResult = inspector.CompareLists(source.IntList, comp.IntList); Assert.IsTrue(compIntResult.Item1, compIntResult.Item2); var compNameResult = inspector.CompareLists(source.Names, comp.Names); Assert.IsTrue(compNameResult.Item1, compNameResult.Item2); var compTypeResult = inspector.CompareLists(source.Types, comp.Types); Assert.IsTrue(compTypeResult.Item1, compTypeResult.Item2); }
public void CanMapClassToStruct() { const string TEST_NAME = "abcdef"; const int TEST_NUMBER = 551; const double TEST_WEIGHT = 3.14159; var t1 = new Classo.MyType() { Name = TEST_NAME, Number = TEST_NUMBER, Weight = TEST_WEIGHT, }; Structo.MyType t2 = new Structo.MyType(); DTOMapper.CopyMembers <Classo.MyType, Structo.MyType>(t1, t2); Assert.AreEqual(TEST_NAME, t2.Name); Assert.AreEqual(TEST_NUMBER, t2.Number); Assert.AreEqual(TEST_WEIGHT, t2.Weight); }
public void CanCopyListsFromDifferentNamespaces() { const string NAME_1 = "myName"; const int NUMBER_1 = 123; ListHost_T1 host1 = new ListHost_T1(); host1.List.Add(new ListType1() { Name = NAME_1, Number = NUMBER_1, }); ListHost_T2 host2 = new ListHost_T2(); DTOMapper.CopyMembers(host1, host2); Assert.AreEqual(1, host2.List.Count, "There should be one item!"); var item = host2.List[0]; Assert.AreEqual(NAME_1, item.Name); Assert.AreEqual(NUMBER_1, item.Number); }