Exemple #1
0
        public void InitializeDb()
        {
            InitializeObjects();

            IdentityRepository.CreateRole(new Role()
            {
                Name = Constants.UserRoleName
            });

            IdentityRepository.CreateRole(new Role()
            {
                Name = Constants.AdminRoleName
            });

            var users = Builder <User>
                        .CreateListOfSize(_dataCount)
                        .All()
                        .Build();

            foreach (var user in users)
            {
                IdentityRepository.Create(user);
            }
            Context.SaveChanges();

            users = IdentityRepository.GetAll().ToList();


            var orderCategories = Builder <OrderCategory>
                                  .CreateListOfSize(_dataCount)
                                  .Build();

            var providerCategories = Builder <ProviderCategory>
                                     .CreateListOfSize(_dataCount)
                                     .Build();

            var orders = Builder <Order>
                         .CreateListOfSize(_dataCount)
                         .All()
                         .With(o => o.Creator  = Pick <User> .RandomItemFrom(users))
                         .With(o => o.Category = Pick <OrderCategory> .RandomItemFrom(orderCategories))
                         .With(o => o.Closed   = false)
                         .With(o => o.Approved = true)
                         .Build();

            var providers = Builder <Provider>
                            .CreateListOfSize(_dataCount)
                            .All()
                            .With(p => p.Creator  = Pick <User> .RandomItemFrom(users))
                            .With(p => p.Category = Pick <ProviderCategory> .RandomItemFrom(providerCategories))
                            .With(p => p.Approved = true)
                            .Build();

            var orderResponses = Builder <OrderResponse>
                                 .CreateListOfSize(_dataCount)
                                 .All()
                                 .With(or => or.Provider  = Pick <Provider> .RandomItemFrom(providers))
                                 .With(or => or.Order     = Pick <Order> .RandomItemFrom(orders))
                                 .With(or => or.Creator   = or.Provider.Creator)
                                 .With(or => or.Completed = false)
                                 .Build();

            var providerResponses = Builder <ProviderResponse>
                                    .CreateListOfSize(_dataCount)
                                    .All()
                                    .With(pr => pr.Order    = Pick <Order> .RandomItemFrom(orders))
                                    .With(pr => pr.Provider = Pick <Provider> .RandomItemFrom(providers))
                                    .With(pr => pr.Creator  = pr.Order.Creator)
                                    .Build();

            var images = Builder <Image>
                         .CreateListOfSize(_dataCount)
                         .Build();

            Context.Photos.AddOrUpdate(x => x.Id, images.ToArray());
            Context.ProviderCategories.AddOrUpdate(x => x.Id, providerCategories.ToArray());
            Context.OrderCategories.AddOrUpdate(x => x.Id, orderCategories.ToArray());
            Context.SaveChanges();
            Context.Orders.AddOrUpdate(x => x.Id, orders.ToArray());
            Context.Providers.AddOrUpdate(x => x.Id, providers.ToArray());
            Context.SaveChanges();
            Context.OrderResponses.AddOrUpdate(x => x.Id, orderResponses.ToArray());
            Context.ProviderResponses.AddOrUpdate(x => x.Id, providerResponses.ToArray());
            Context.SaveChanges();
        }