Exemplo n.º 1
0
        public void Initialize()
        {
            var connection = Effort.DbConnectionFactory.CreateTransient();

            this.model = CompiledModels.GetModel<RelationEntity, EmptyEntity>();
            this.context = new FeatureDbContext(connection, this.model);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public void Initialize()
 {
     this.context =
         new FeatureDbContext(
             Effort.DbConnectionFactory.CreateTransient(),
             CompiledModels.GetModel<
                 StringFieldEntity>());
 }
Exemplo n.º 6
0
        public void Initialize()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

            this.context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel<FlagEnumFieldEntity>());
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void Initialize()
        {
            this.connection = (EffortConnection)DbConnectionFactory.CreateTransient();

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

            this.context.Configuration.ValidateOnSaveEnabled = false;
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public void Initialize()
        {
            DbConnection connection = DbConnectionFactory.CreateTransient();

            InitializeData(connection);

            this.context =
                new FeatureDbContext(
                    connection,
                    CompiledModels.GetModel<NumberFieldEntity>());
        }
Exemplo n.º 11
0
        public void LargePrimaryKeyCreation()
        {
            var connection =
                DbConnectionFactory.CreateTransient();

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

            context.Database.CreateIfNotExists();
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public void StringFieldFixture_LargeStringFieldCreation()
        {
            DbConnection connection =
                Effort.DbConnectionFactory.CreateTransient();

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

            context.Database.Initialize(true);
        }
Exemplo n.º 14
0
        public void Initialize()
        {
            this.context =
                new FeatureDbContext(
                    Effort.DbConnectionFactory.CreateTransient(),
                    CompiledModels.GetModel<TimeFieldEntity>());

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

            this.context.SaveChanges();
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
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);
        }