예제 #1
0
        public void ComplexToSimpleElement()
        {
            var source = new GenericArray <InnerType>()
            {
                Array = Enumerable.Range(0, 100).Select(i =>
                                                        new InnerType()
                {
                    String = i.ToString()
                }).ToArray()
            };

            var target = new GenericCollections <int>(false);

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.Array, b => b.Array);

                cfg.MapTypes <InnerType, int>(inner => Int32.Parse(inner.String));
            });

            ultraMapper.Map(source, target);
            Assert.IsTrue(source.Array.Select(inner => inner.String).SequenceEqual(
                              target.Array.Select(item => item.ToString())));
        }
예제 #2
0
        public void UpdateAssignToNullCollection()
        {
            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 50; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            var target = new GenericCollections <ComplexType>(true)
            {
                List                 = null,
                HashSet              = null,
                SortedSet            = null,
                Stack                = null,
                Queue                = null,
                LinkedList           = null,
                ObservableCollection = null
            };

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes <IEnumerable <ComplexType>, IEnumerable <ComplexType>, ComplexType, ComplexType>(
                    (itemA, itemB) => itemA.A == itemB.A);
            });

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #3
0
        public void ComplexArrayToCollection()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };
            var source = new GenericArray <ComplexType>()
            {
                Array = new ComplexType[3]
            };

            for (int i = 0; i < 3; i++)
            {
                source.Array[i] = new ComplexType()
                {
                    A = i, InnerType = innerType
                };
            }

            var target = new GenericCollections <ComplexType>(false);

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.Array, b => b.Array, memCfg => memCfg.ReferenceBehavior = ReferenceBehaviors.CREATE_NEW_INSTANCE)
                .MapMember(a => a.Array, b => b.List);
            });

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #4
0
        public void FromComplexCollectionToAnother()
        {
            var typeProperties = typeof(GenericCollections <ComplexType>).GetProperties();

            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 50; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            foreach (var sourceProp in typeProperties)
            {
                var ultraMapper = new Mapper(cfg =>
                {
                    //cfg.GlobalConfiguration.IgnoreConventions = true;
                });

                var target = new GenericCollections <ComplexType>(false);

                var typeMappingConfig = ultraMapper.MappingConfiguration.MapTypes(source, target);
                foreach (var targetProp in typeProperties)
                {
                    typeMappingConfig.MapMember(sourceProp, targetProp);
                }

                ultraMapper.Map(source, target);

                bool isResultOk = ultraMapper.VerifyMapperResult(source, target);
                Assert.IsTrue(isResultOk);
            }
        }
예제 #5
0
        private void SelectCollection(Object sender, EventArgs e)
        {
            CheckedListBox cbList = (CheckedListBox)sender;

            aCollection = (GenericCollections)Enum.Parse(typeof(GenericCollections), cbList.SelectedItem.ToString());
            SetCollectionType();
        }
예제 #6
0
        public void ComplexCollection()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };

            var source = new GenericCollections <ComplexType>(false);

            for (int i = 0; i < 3; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
            }

            var target = new GenericCollections <ComplexType>(false);

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);

            Assert.IsTrue(!Object.ReferenceEquals(source.HashSet.First().InnerType, target.HashSet.First().InnerType));

            Assert.IsTrue(target.List.Concat(target.HashSet.Concat(target.SortedSet.Concat(target.Stack.Concat(
                                                                                               target.Queue.Concat(target.LinkedList.Concat(target.ObservableCollection))))))
                          .Select(it => it.InnerType)
                          .All(item => Object.ReferenceEquals(item, target.HashSet.First().InnerType)));
        }
예제 #7
0
        public void CollectionToReadOnlyComplexCollection()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };

            var source = new GenericCollections <ComplexType>(false);

            for (int i = 0; i < 10; i++)
            {
                source.Array[i] = new ComplexType()
                {
                    A = i, InnerType = innerType
                };
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
            }

            var target = new ReadOnlyGeneric <ComplexType>();

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #8
0
        public void ComplexCollectionToArray()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };
            var source = new GenericCollections <ComplexType>(false);

            for (int i = 0; i < 3; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
            }

            var target = new GenericArray <ComplexType>();

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.List, b => b.Array);
            });

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
 /// <summary>
 /// <remarks> Later review </remarks>
 /// </summary>
 public void RestoreToDefault()
 {
     SelectedType           = String.Empty;
     IsCollection           = false;
     SelectedCollectionType = String.Empty;
     SelectedAccessModifier = String.Empty;
     WithBackingField       = false;
     BackingFieldPrefix     = String.Empty;
     WithNotifier           = false;
     NotifyMethodName       = String.Empty;
     GenericCollections.ApplyType("T");
 }
예제 #10
0
        public void CollectionToReadOnlySimpleCollection()
        {
            var source = new GenericCollections <int>(true);
            var target = new ReadOnlyGeneric <int>();

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #11
0
        private void EditRules(IDataRule aRule)
        {
            CollectionRule cRule = (CollectionRule)aRule;

            if (cRule.KeyRule != null)
            {
                collectionsCtrl.SetRule(cRule.KeyRule, true);
                lblKeyRule.Text = SetType(cRule.KeyRule);
                lblKeyRule.Tag  = cRule.KeyRule;
            }
            collectionsCtrl.SetRule(cRule.ValueRule, false);
            lblValueRule.Text = SetType(cRule.ValueRule);
            lblValueRule.Tag  = cRule.ValueRule;
            aCollection       = cRule.Generic;
        }
예제 #12
0
        public void SimpleCollectionToArray()
        {
            var source = new GenericCollections <int>(false)
            {
                List = Enumerable.Range(0, 100).ToList()
            };

            var target = new GenericArray <int>();

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.List, b => b.Array);
            });

            ultraMapper.Map(source, target);

            Assert.IsTrue(source.List.SequenceEqual(target.Array));
        }
예제 #13
0
        public void FromPrimitiveCollectionToAnother()
        {
            var sourceProperties = typeof(GenericCollections <int>).GetProperties();
            var targetProperties = typeof(GenericCollections <double>).GetProperties();

            var source = new GenericCollections <int>(false);

            //initialize source
            for (int i = 0; i < 10; i++)
            {
                source.Array[i] = i;
                source.List.Add(i);
                source.HashSet.Add(i);
                source.SortedSet.Add(i);
                source.Stack.Push(i);
                source.Queue.Enqueue(i);
                source.LinkedList.AddLast(i);
                source.ObservableCollection.Add(i);
            }

            foreach (var sourceProp in sourceProperties)
            {
                var target = new GenericCollections <double>(false);

                var ultraMapper       = new Mapper();
                var typeMappingConfig = ultraMapper.MappingConfiguration.MapTypes(source, target);

                foreach (var targetProp in targetProperties)
                {
                    typeMappingConfig.MapMember(sourceProp, targetProp);
                }

                ultraMapper.Map(source, target);

                bool isResultOk = ultraMapper.VerifyMapperResult(source, target);
                Assert.IsTrue(isResultOk);
            }
        }
예제 #14
0
        public void AssignNullCollection()
        {
            var source = new GenericCollections <int>(false)
            {
                List                 = null,
                HashSet              = null,
                SortedSet            = null,
                Stack                = null,
                Queue                = null,
                LinkedList           = null,
                ObservableCollection = null
            };

            var target = new GenericCollections <int>(true);

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #15
0
        public void SimpleCollectionUpdate()
        {
            var source = new GenericCollections <int>(true, 0, 10);
            var target = new GenericCollections <int>(true, 5, 15);
            var check  = new GenericCollections <int>(true, 5, 15);

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.CollectionBehavior = CollectionBehaviors.MERGE;

                cfg.MapTypes <IEnumerable <int>, IEnumerable <int> >(( ITypeOptions op ) =>
                                                                     op.ReferenceBehavior = ReferenceBehaviors.USE_TARGET_INSTANCE_IF_NOT_NULL);
            });

            ultraMapper.Map(source, target);

            Assert.IsTrue(target.List.SequenceEqual(
                              check.List.Concat(source.List)));

            Assert.IsTrue(target.LinkedList.SequenceEqual(
                              check.LinkedList.Concat(source.LinkedList)));

            Assert.IsTrue(target.ObservableCollection.SequenceEqual(
                              check.ObservableCollection.Concat(source.ObservableCollection)));

            Assert.IsTrue(check.SortedSet.Concat(source.SortedSet)
                          .All(item => target.SortedSet.Contains(item)));

            Assert.IsTrue(check.HashSet.Concat(source.HashSet)
                          .All(item => target.HashSet.Contains(item)));

            Assert.IsTrue(target.Queue.SequenceEqual(
                              check.Queue.Concat(source.Queue)));

            Assert.IsTrue(target.Stack.SequenceEqual(
                              source.Stack.Concat(check.Stack)));
        }
예제 #16
0
        public void SimpleToComplexElement()
        {
            var source = new GenericCollections <int>(false)
            {
                List = Enumerable.Range(0, 100).ToList()
            };

            var target = new GenericArray <InnerType>();

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.List, b => b.Array);

                cfg.MapTypes <int, InnerType>(i => new InnerType()
                {
                    String = i.ToString()
                });
            });

            ultraMapper.Map(source, target);
            Assert.IsTrue(source.List.Select(inner => inner.ToString()).SequenceEqual(
                              target.Array.Select(item => item.String)));
        }
예제 #17
0
        public void AssignToNullCollection()
        {
            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 10; i++)
            {
                source.Array[i] = new ComplexType()
                {
                    A = i
                };
                source.List.Add(new ComplexType()
                {
                    A = i
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            var target = new GenericCollections <ComplexType>(true)
            {
                Array                = null,
                List                 = null,
                HashSet              = null,
                SortedSet            = null,
                Stack                = null,
                Queue                = null,
                LinkedList           = null,
                ObservableCollection = null
            };

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #18
0
        public void CollectionUpdate()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };

            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 50; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            var tempItemA = new ComplexType()
            {
                A = 1
            };
            var tempItemB = new ComplexType()
            {
                A = 49
            };

            var target = new GenericCollections <ComplexType>(false)
            {
                List = new List <ComplexType>()
                {
                    tempItemA,
                    tempItemB,
                    new ComplexType()
                    {
                        A = 50
                    }
                }
            };

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.List, b => b.List, (itemA, itemB) => itemA.A == itemB.A);
            });

            ultraMapper.Map(source, target);
            Assert.IsTrue(object.ReferenceEquals(target.List.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.List.First(item => item.A == 49), tempItemB));
        }
        public void CollectionUpdate()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };

            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 50; i++)
            {
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            var target = new GenericCollections <ComplexType>(false);

            var temp = new List <ComplexType>()
            {
                new ComplexType()
                {
                    A = 1
                },
                new ComplexType()
                {
                    A = 49
                },
                new ComplexType()
                {
                    A = 50
                }
            };


            var ultraMapper = new UltraMapper(cfg =>
            {
                cfg.MapTypes(source, target)
                .MapMember(a => a.List, b => b.List, (itemA, itemB) => itemA.A == itemB.A);
            });

            LinqExtensions.Update(ultraMapper, source.List, temp, new RelayEqualityComparison <ComplexType>((itemA, itemB) => itemA.A == itemB.A));

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #20
0
        public void KeepAndClearCollection()
        {
            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 10; i++)
            {
                source.Array[i] = new ComplexType()
                {
                    A = i
                };
                source.List.Add(new ComplexType()
                {
                    A = i
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i
                });
            }

            var target = new GenericCollections <ComplexType>(false)
            {
                List = new List <ComplexType>()
                {
                    new ComplexType()
                    {
                        A = 100
                    }
                }
            };

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.IgnoreMemberMappingResolvedByConvention = true;

                cfg.MapTypes <ComplexType, ComplexType>(typeCfg =>
                {
                    typeCfg.IgnoreMemberMappingResolvedByConvention = false;
                });

                cfg.MapTypes <GenericCollections <ComplexType>, GenericCollections <ComplexType> >()
                .MapMember(a => a.List, b => b.List, memberConfig =>
                {
                    memberConfig.CollectionBehavior = CollectionBehaviors.RESET;
                    memberConfig.ReferenceBehavior  = ReferenceBehaviors.USE_TARGET_INSTANCE_IF_NOT_NULL;
                });
            });

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #21
0
        public void CollectionUpdate()
        {
            var innerType = new InnerType()
            {
                String = "test"
            };
            var source = new GenericCollections <ComplexType>(false);

            //initialize source
            for (int i = 0; i < 10; i++)
            {
                source.Array[i] = new ComplexType()
                {
                    A = i, InnerType = innerType
                };
                source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.HashSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.SortedSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Stack.Push(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.Queue.Enqueue(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.LinkedList.AddLast(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                source.ObservableCollection.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
            }

            var tempItemA = new ComplexType()
            {
                A = 1
            };
            var tempItemB = new ComplexType()
            {
                A = 9
            };

            var target = new GenericCollections <ComplexType>(false)
            {
                Array = new ComplexType[10] {
                    tempItemA, tempItemB, new ComplexType()
                    {
                        A = 10
                    }, null, null, null, null, null, null, null
                },
                List = new List <ComplexType>()
                {
                    tempItemA, tempItemB, new ComplexType()
                    {
                        A = 10
                    }
                },
                HashSet = new HashSet <ComplexType>()
                {
                    tempItemA, tempItemB, new ComplexType()
                    {
                        A = 10
                    }
                },
                SortedSet = new SortedSet <ComplexType>()
                {
                    tempItemA, tempItemB, new ComplexType()
                    {
                        A = 10
                    }
                },
                ObservableCollection = new ObservableCollection <ComplexType>()
                {
                    tempItemA, tempItemB, new ComplexType()
                    {
                        A = 10
                    }
                }
            };

            target.Stack = new Stack <ComplexType>();
            target.Stack.Push(tempItemA);
            target.Stack.Push(tempItemB);
            target.Stack.Push(new ComplexType()
            {
                A = 10
            });

            target.Queue = new Queue <ComplexType>();
            target.Queue.Enqueue(tempItemA);
            target.Queue.Enqueue(tempItemB);
            target.Queue.Enqueue(new ComplexType()
            {
                A = 10
            });

            target.LinkedList = new LinkedList <ComplexType>();
            target.LinkedList.AddLast(tempItemA);
            target.LinkedList.AddLast(tempItemB);
            target.LinkedList.AddLast(new ComplexType()
            {
                A = 10
            });

            //item comparer should also check for nulls ALWAYS
            Expression <Func <ComplexType, ComplexType, bool> > itemComparer =
                (itemA, itemB) => Comparison(itemA, itemB);

            var ultraMapper = new Mapper(cfg =>
            {
                cfg.MapTypes <IEnumerable <ComplexType>, IEnumerable <ComplexType> >(cfg2 =>
                {
                    cfg2.ReferenceBehavior              = ReferenceBehaviors.USE_TARGET_INSTANCE_IF_NOT_NULL;
                    cfg2.CollectionBehavior             = CollectionBehaviors.UPDATE;
                    cfg2.CollectionItemEqualityComparer = itemComparer;
                });
            });

            ultraMapper.Map(source, target);

            Assert.IsTrue(target.Array.Length == source.Array.Length);
            Assert.IsTrue(object.ReferenceEquals(target.Array.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.Array.First(item => item.A == 9), tempItemB));

            foreach (var item in target.Array)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.List.Count == source.List.Count);
            Assert.IsTrue(object.ReferenceEquals(target.List.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.List.First(item => item.A == 9), tempItemB));

            foreach (var item in target.List)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.HashSet.Count == source.HashSet.Count);
            Assert.IsTrue(object.ReferenceEquals(target.HashSet.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.HashSet.First(item => item.A == 9), tempItemB));

            foreach (var item in target.HashSet)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.SortedSet.Count == source.SortedSet.Count);
            Assert.IsTrue(object.ReferenceEquals(target.SortedSet.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.SortedSet.First(item => item.A == 9), tempItemB));

            foreach (var item in target.SortedSet)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.ObservableCollection.Count == source.ObservableCollection.Count);
            Assert.IsTrue(object.ReferenceEquals(target.ObservableCollection.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.ObservableCollection.First(item => item.A == 9), tempItemB));

            foreach (var item in target.ObservableCollection)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.LinkedList.Count == source.LinkedList.Count);
            Assert.IsTrue(object.ReferenceEquals(target.LinkedList.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.LinkedList.First(item => item.A == 9), tempItemB));

            foreach (var item in target.LinkedList)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.Stack.Count == source.Stack.Count);
            Assert.IsTrue(object.ReferenceEquals(target.Stack.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.Stack.First(item => item.A == 9), tempItemB));

            foreach (var item in target.Stack)
            {
                Assert.IsTrue(item.InnerType != null);
            }


            Assert.IsTrue(target.Queue.Count == source.Queue.Count);
            Assert.IsTrue(object.ReferenceEquals(target.Queue.First(item => item.A == 1), tempItemA));
            Assert.IsTrue(object.ReferenceEquals(target.Queue.First(item => item.A == 9), tempItemB));

            foreach (var item in target.Queue)
            {
                Assert.IsTrue(item.InnerType != null);
            }

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
예제 #22
0
        public MappersBenchmark()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <GenericCollections <ComplexType>, ReadOnlyGeneric <ComplexType> >();
                cfg.CreateMap <ComplexType, ComplexType>();
                cfg.CreateMap <InnerType, InnerType>();
            });

            _autoMapper = new AutoMapper.Mapper(config);

            _ultraMapper = new Mapper(cfg =>
            {
                cfg.IsReferenceTrackingEnabled = true;

                cfg.MapTypes <ComplexType, ComplexType>()
                .MapTypeToMember <int>(typeof(InnerType).GetProperties().First());
            });

            var innerType = new InnerType()
            {
                String = "test"
            };

            _source = new GenericCollections <ComplexType>(false, 0, 1000);
            for (int i = 0; i < 1000; i++)
            {
                _source.Array[i] = new ComplexType()
                {
                    A = i, InnerType = innerType
                };
                _source.List.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.HashSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.SortedSet.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.Stack.Push(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.Queue.Enqueue(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.LinkedList.AddLast(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
                _source.ObservableCollection.Add(new ComplexType()
                {
                    A = i, InnerType = innerType
                });
            }
        }