Esempio n. 1
0
        public static void Seed(BonusCustomerProfileContext context)
        {
            if (!context.CustomerProfiles.Any())
            {
                var customerProfiles = new List <CustomerProfile>
                {
                    new CustomerProfile()
                    {
                        CustomerId = new Guid(CustomerId),
                        TotalCampaignsContributedCount = 1
                    }
                };

                context.CustomerProfiles.AddRange(customerProfiles);
                context.SaveChangesAsync();
            }

            if (!context.CampaignsContributions.Any())
            {
                var campaigns = new List <CampaignsContribution>
                {
                    new CampaignsContribution()
                    {
                        Id         = Guid.NewGuid(),
                        CustomerId = new Guid(CustomerId),
                        CampaignId = new Guid(CampaignId)
                    }
                };

                context.CampaignsContributions.AddRange(campaigns);
                context.SaveChangesAsync();
            }
        }
        private BonusCustomerProfileContext CreateDataContext()
        {
            DbContextOptions = new DbContextOptionsBuilder()
                               .UseInMemoryDatabase(nameof(BonusCustomerProfileContext))
                               .Options;

            var context = new BonusCustomerProfileContext(DbContextOptions);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            return(context);
        }