Ejemplo n.º 1
0
        private static void CreateParentsForSomeChildren(
            Context context,
            IEnumerable <ChildCard> childrenCards
            )
        {
            var fixture = new Fixture();
            // special variable for variating number of parents from 0 to 2
            var parentsCount = 0;

            foreach (var childCard in childrenCards)
            {
                var parents = fixture.Build <Parent>()
                              .Without(parent => parent.ParentsChildren)
                              .CreateMany(parentsCount).ToList();
                foreach (var parent in parents)
                {
                    context.Parents.Add(parent);

                    var parentChildCard = new ParentChildCard
                    {
                        ChildCard = childCard,
                        Parent    = parent
                    };
                    context.ParentsChildrenCards.Add(parentChildCard);
                }
                parentsCount = (++parentsCount) % 3;
            }
        }
Ejemplo n.º 2
0
 public static ParentChildCardDTO EntityToDTO(ParentChildCard parentChildCard)
 {
     Mapper.Initialize(cfg => cfg.CreateMap <ParentChildCard, ParentChildCardDTO>());
     return(Mapper.Map <ParentChildCardDTO>(parentChildCard));
 }