public void when_saving_process_then_can_retrieve_it()
        {
            var dbName = this.GetType().Name + "-" + Guid.NewGuid();
            using (var context = new RegistrationProcessManagerDbContext(dbName))
            {
                context.Database.Create();
            }

            try
            {
                Guid id = Guid.Empty;
                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    var pm = new RegistrationProcessManager();
                    context.RegistrationProcesses.Add(pm);
                    context.SaveChanges();
                    id = pm.Id;
                }
                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    var pm = context.RegistrationProcesses.Find(id);
                    Assert.NotNull(pm);
                }
            }
            finally
            {
                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    context.Database.Delete();
                }
            }
        }
Exemplo n.º 2
0
        //private IDatabaseInitializer<RegistrationProcessManagerDbContext> innerInitializer;

        //public RegistrationProcessManagerDbContextInitializer(IDatabaseInitializer<RegistrationProcessManagerDbContext> innerInitializer)
        //{
        //    this.innerInitializer = innerInitializer;
        //}

        public void InitializeDatabase(RegistrationProcessManagerDbContext context)
        {
            // this.innerInitializer.InitializeDatabase(context);

            CreateIndexes(context);

            context.SaveChanges();
        }
        public void when_saving_process_performs_optimistic_locking()
        {
            var dbName = this.GetType().Name + "-" + Guid.NewGuid();
            using (var context = new RegistrationProcessManagerDbContext(dbName))
            {
                context.Database.Create();
            }

            try
            {
                Guid id = Guid.Empty;
                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    var pm = new RegistrationProcessManager();
                    context.RegistrationProcesses.Add(pm);
                    context.SaveChanges();
                    id = pm.Id;
                }

                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    var pm = context.RegistrationProcesses.Find(id);

                    pm.State = RegistrationProcessManager.ProcessState.PaymentConfirmationReceived;

                    using (var innerContext = new RegistrationProcessManagerDbContext(dbName))
                    {
                        var innerProcess = innerContext.RegistrationProcesses.Find(id);

                        innerProcess.State = RegistrationProcessManager.ProcessState.ReservationConfirmationReceived;

                        innerContext.SaveChanges();
                    }

                    Assert.Throws<DbUpdateConcurrencyException>(() => context.SaveChanges());
                }
            }
            finally
            {
                using (var context = new RegistrationProcessManagerDbContext(dbName))
                {
                    context.Database.Delete();
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.AppSettings["defaultConnection"];
            if (args.Length > 0)
            {
                connectionString = args[0];
            }

            // Use ConferenceContext as entry point for dropping and recreating DB
            using (var context = new ConferenceContext(connectionString))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.Create();
            }

            Database.SetInitializer<EventStoreDbContext>(null);
            Database.SetInitializer<MessageLogDbContext>(null);
            Database.SetInitializer<BlobStorageDbContext>(null);
            Database.SetInitializer<ConferenceRegistrationDbContext>(null);
            Database.SetInitializer<RegistrationProcessManagerDbContext>(null);
            Database.SetInitializer<PaymentsDbContext>(null);

            DbContext[] contexts =
                new DbContext[] 
                { 
                    new EventStoreDbContext(connectionString),
                    new MessageLogDbContext(connectionString),
                    new BlobStorageDbContext(connectionString),
                    new PaymentsDbContext(connectionString),
                    new RegistrationProcessManagerDbContext(connectionString),
                    new ConferenceRegistrationDbContext(connectionString),
                };

            foreach (DbContext context in contexts)
            {
                var adapter = (IObjectContextAdapter)context;

                var script = adapter.ObjectContext.CreateDatabaseScript();

                context.Database.ExecuteSqlCommand(script);

                context.Dispose();
            }

            using (var context = new ConferenceRegistrationDbContext(connectionString))
            {
                ConferenceRegistrationDbContextInitializer.CreateIndexes(context);
            }

            using (var context = new RegistrationProcessManagerDbContext(connectionString))
            {
                RegistrationProcessManagerDbContextInitializer.CreateIndexes(context);
            }

            using (var context = new PaymentsDbContext(connectionString))
            {
                PaymentsReadDbContextInitializer.CreateViews(context);
            }

            MessagingDbInitializer.CreateDatabaseObjects(connectionString, "SqlBus");
        }