Beispiel #1
0
        public void DbManager_ClearTables()
        {
            var connection = (EffortConnection)DbConnectionFactory.CreateTransient();

            var model   = CompiledModels.GetModel <RelationEntity, EmptyEntity>();
            var context = new FeatureDbContext(connection, model);

            context.Database.Initialize(true);

            context.RelationEntities.Add(
                new RelationEntity
            {
                RequiredRelation = new EmptyEntity()
            });

            context.SaveChanges();

            // Create new context
            context = new FeatureDbContext(connection, model);

            // The records should be in
            context.EmptyEntities.Count().Should().Be(1);
            context.RelationEntities.Count().Should().Be(1);

            // Use DbManager to delete all data from the database
            connection.Open();
            connection.DbManager.ClearTables();

            // Tables should be empty
            context.EmptyEntities.Count().Should().Be(0);
            context.RelationEntities.Count().Should().Be(0);
        }
Beispiel #2
0
        public void Initialize()
        {
            var connection = Effort.DbConnectionFactory.CreateTransient();

            this.model   = CompiledModels.GetModel <RelationEntity, EmptyEntity>();
            this.context = new FeatureDbContext(connection, this.model);
        }
Beispiel #3
0
 public void Initialize()
 {
     this.context =
         new FeatureDbContext(
             DbConnectionFactory.CreateTransient(),
             CompiledModels.GetModel <MathEntity>());
 }
        public void Initialize()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

            this.context =
                new FeatureDbContext(connection, CompiledModels.DecimalIdenityFieldModel);
        }
 public void Initialize()
 {
     this.context =
         new FeatureDbContext(
             Effort.DbConnectionFactory.CreateTransient(),
             CompiledModels.GetModel <
                 StringFieldEntity>());
 }
        public void Initialize()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

            this.context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <GuidKeyEntity>());
        }
        public void Initialize()
        {
            DbConnection connection = DbConnectionFactory.CreateTransient();

            InitializeData(connection);

            this.context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <NumberFieldEntity>());
        }
Beispiel #8
0
        public void DbContext_Create()
        {
            DbConnection     connection = DbConnectionFactory.CreateTransient();
            FeatureDbContext context    = new FeatureDbContext(connection);

            bool created1 = context.Database.CreateIfNotExists();
            bool created2 = context.Database.CreateIfNotExists();

            Assert.IsTrue(created1);
            Assert.IsFalse(created2);
        }
Beispiel #9
0
        public void Initialize()
        {
            this.connection = (EffortConnection)DbConnectionFactory.CreateTransient();

            this.context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <RequiredFieldEntity>());

            this.context.Configuration.ValidateOnSaveEnabled = false;
        }
Beispiel #10
0
        public void StringFieldFixture_LargeStringFieldCreation()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

            FeatureDbContext context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <LargeStringFieldEntity>());

            context.Database.Initialize(true);
        }
Beispiel #11
0
        public void SpatialFixture_SpatialFeatureCreation()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

            FeatureDbContext context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <SpatialEntity>());

            context.Database.Initialize(true);
        }
        public void LargePrimaryKeyCreation()
        {
            var connection =
                DbConnectionFactory.CreateTransient();

            var context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <LargePrimaryKeyEntity>());

            context.Database.CreateIfNotExists();
        }
Beispiel #13
0
        public void DbContext_Insert()
        {
            DbConnection     connection = DbConnectionFactory.CreateTransient();
            FeatureDbContext context    = new FeatureDbContext(connection);

            context.StringFieldEntities.Add(new StringFieldEntity {
                Value = "Foo"
            });
            int count = context.SaveChanges();

            Assert.AreEqual(1, count);
        }
Beispiel #14
0
        public void DbManager_SetIdentityFields()
        {
            EffortConnection connection =
                (EffortConnection)DbConnectionFactory.CreateTransient();

            FeatureDbContext context = new FeatureDbContext(connection);

            context.Database.Initialize(true);

            {
                // Create a separate context for initializing the data (schema without
                // identity field)
                FeatureDbContext dataInitContext =
                    new FeatureDbContext(connection, CompiledModels.DisabledIdentityModel);

                // DbConfiguration require open connection
                connection.Open();
                // Disable identity fields
                connection.DbManager.SetIdentityFields(false);
                // Clear migration history to avoid exception
                connection.DbManager.ClearMigrationHistory();
                // EF cannot handle open connection (fixed in EF6)
                connection.Close();

                // Add data with explicitly set id
                var initEntity = new StringFieldEntity {
                    Id = 5, Value = "Car"
                };
                dataInitContext.StringFieldEntities.Add(initEntity);
                dataInitContext.SaveChanges();

                // Identity generation should not be used
                Assert.AreEqual(5, initEntity.Id);

                // Enable identity field
                connection.Open();
                connection.DbManager.SetIdentityFields(true);
                connection.Close();
            }

            var entity = new StringFieldEntity {
                Id = 0, Value = "Bicycle"
            };

            context.StringFieldEntities.Add(entity);
            context.SaveChanges();

            // Identity generation should be used
            Assert.AreEqual(6, entity.Id);
        }
Beispiel #15
0
        public void DbContext_Query()
        {
            DbConnection     connection = DbConnectionFactory.CreateTransient();
            FeatureDbContext context    = new FeatureDbContext(connection);

            context.StringFieldEntities.Add(new StringFieldEntity {
                Value = "Foo"
            });
            context.SaveChanges();

            StringFieldEntity person = context.StringFieldEntities.Single();

            Assert.AreEqual("Foo", person.Value);
        }
Beispiel #16
0
        public void DbContext_TableName()
        {
            DbConnection connection =
                DbConnectionFactory.CreateTransient(
                    new LocalFeatureDataLoader());

            FeatureDbContext context =
                new FeatureDbContext(connection, CompiledModels.TableNameModel);

            var result = context.StringFieldEntities.ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Foo", result[0].Value);
        }
        public void Initialize()
        {
            if (connection == null)
            {
                connection   = Effort.DbConnectionFactory.CreateTransient();
                this.context =
                    new FeatureDbContext(
                        connection,
                        CompiledModels.GetModel <
                            StringFieldEntity>());

                this.context.Database.CreateIfNotExists();
            }
        }
        public void Initialize()
        {
            this.context =
                new FeatureDbContext(
                    Effort.DbConnectionFactory.CreateTransient(),
                    CompiledModels.GetModel <TimeFieldEntity>());

            this.Entities.Add(
                new TimeFieldEntity
            {
                Time = stored
            });

            this.context.SaveChanges();
        }
        private static void InitializeData(DbConnection connection)
        {
            var context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel <NumberFieldEntity>());

            context.NumberFieldEntities.Add(
                new NumberFieldEntity {
                Value8  = 0x0f,
                Value16 = 0x0f,
                Value32 = 0x0f,
                Value64 = 0x0f
            });

            context.SaveChanges();
            connection.Close();
        }
Beispiel #20
0
        public void CascadedDelete()
        {
            this.RelationEntities.Add(
                new RelationEntity
            {
                RequiredRelation = new EmptyEntity()
            });

            this.context.SaveChanges();

            // If the entity was removed in the current context, EF would remove the
            // referrenced entity automatically
            // If a new context is created, the database would perform the cascaded delete
            var newContext =
                new FeatureDbContext(this.context.Database.Connection, this.model);

            var empty = newContext.EmptyEntities.Single();

            newContext.EmptyEntities.Remove(empty);
            newContext.SaveChanges();
        }
Beispiel #21
0
        public void DbContext_DatabaseExists()
        {
            // Microsoft change the way database existence check works
            //
            // Exist call with an open connection always returns true
            // In an earlier version of Effort, the Exists call opened the connection,
            // so later initialization did not begin

            DbConnection     connection = DbConnectionFactory.CreateTransient();
            FeatureDbContext context    = new FeatureDbContext(connection);

            var exists = context.Database.Exists();

            Assert.IsFalse(exists);

            context.StringFieldEntities.Add(new StringFieldEntity {
                Value = "Foo"
            });
            int count = context.SaveChanges();

            Assert.AreEqual(1, count);
        }