Ejemplo n.º 1
0
        public void TestAlterSchemaPassIdentityType()
        {
            MockRepository      mocks = new MockRepository();
            IConnection         conn  = mocks.DynamicMock <IConnection>();
            ISchemaCapabilities caps  = mocks.DynamicMock <ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int64 });
                //--
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64, DataType.DataType_String });
                //--
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);

                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.StrictMock <FdoFeatureService>(conn);

            mocks.ReplayAll();

            FeatureSchema schema = new FeatureSchema("Default", "");

            ClassDefinition cls = new Class("Test", "");

            //ID - float
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");

            id.DataType = DataType.DataType_Single;
            id.Nullable = false;

            cls.Properties.Add(id);
            cls.IdentityProperties.Add(id);

            //Name
            DataPropertyDefinition name = new DataPropertyDefinition("Name", "");

            name.DataType = DataType.DataType_String;
            name.Nullable = true;
            name.Length   = 100;

            cls.Properties.Add(name);

            schema.Classes.Add(cls);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);

            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[0];

            //Should have been "promoted" to string
            Assert.AreEqual(DataType.DataType_String, newClass.IdentityProperties[0].DataType);
        }
Ejemplo n.º 2
0
        public void TestAlterSchemaBaseClass()
        {
            MockRepository      mocks  = new MockRepository();
            FeatureSchema       schema = new FeatureSchema("Default", "");
            IConnection         conn   = mocks.DynamicMock <IConnection>();
            ISchemaCapabilities caps   = mocks.DynamicMock <ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);

                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.DynamicMock <FdoFeatureService>(conn);

            mocks.ReplayAll();

            ClassDefinition baseClass = new Class("Base", "");

            //ID
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");

            id.DataType = DataType.DataType_Int64;
            id.Nullable = false;

            baseClass.Properties.Add(id);
            baseClass.IdentityProperties.Add(id);

            //Name
            DataPropertyDefinition name = new DataPropertyDefinition("Name", "");

            name.DataType = DataType.DataType_String;
            name.Nullable = true;
            name.Length   = 100;

            baseClass.Properties.Add(name);

            ClassDefinition derivedClass = new Class("Derived", "");

            derivedClass.BaseClass = baseClass;

            //DOB
            DataPropertyDefinition dob = new DataPropertyDefinition("DOB", "");

            dob.DataType = DataType.DataType_DateTime;
            dob.Nullable = true;

            derivedClass.Properties.Add(dob);

            schema.Classes.Add(baseClass);
            schema.Classes.Add(derivedClass);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);

            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[newSchema.Classes.IndexOf("Derived")];

            //Base class properties should be copied to derived class
            Assert.AreEqual("BASE_ID", newClass.IdentityProperties[0].Name);
            Assert.AreEqual(3, newClass.Properties.Count);
            Assert.IsTrue(newClass.Properties.IndexOf("BASE_ID") >= 0);
            Assert.IsTrue(newClass.Properties.IndexOf("BASE_Name") >= 0);
        }
Ejemplo n.º 3
0
        public void TestAlterSchemaPassValueConstraints()
        {
            MockRepository      mocks = new MockRepository();
            IConnection         conn  = mocks.DynamicMock <IConnection>();
            ISchemaCapabilities caps  = mocks.DynamicMock <ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int64 });
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                //--
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                //--
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                //--
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);
                //--
                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.StrictMock <FdoFeatureService>(conn);

            mocks.ReplayAll();

            FeatureSchema schema = new FeatureSchema("Default", "");

            ClassDefinition cls = new Class("Test", "");

            //ID
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");

            id.DataType        = DataType.DataType_Int64;
            id.IsAutoGenerated = true; //Should be converted to int64
            id.ReadOnly        = true;
            id.Nullable        = false;

            cls.Properties.Add(id);
            cls.IdentityProperties.Add(id);

            //Age
            DataPropertyDefinition       age   = new DataPropertyDefinition("Age", "");
            PropertyValueConstraintRange range = new PropertyValueConstraintRange();

            range.MinValue      = new Int32Value(0);
            range.MinInclusive  = true;
            range.MaxValue      = new Int32Value(100);
            range.MaxInclusive  = true;
            age.ValueConstraint = range;
            age.DataType        = DataType.DataType_Int32;
            age.Nullable        = true;

            cls.Properties.Add(age);

            //Gender
            DataPropertyDefinition      gender = new DataPropertyDefinition("Gender", "");
            PropertyValueConstraintList list   = new PropertyValueConstraintList();

            list.ConstraintList.Add(new StringValue("M"));
            list.ConstraintList.Add(new StringValue("F"));
            gender.ValueConstraint = list;
            age.DataType           = DataType.DataType_String;
            age.Nullable           = false;
            age.Length             = 1;

            cls.Properties.Add(gender);

            schema.Classes.Add(cls);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);

            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[0];

            DataPropertyDefinition age2 = newClass.Properties[newClass.Properties.IndexOf("Age")] as DataPropertyDefinition;

            //Should have constraint removed
            Assert.IsNull(age2.ValueConstraint);

            DataPropertyDefinition gender2 = newClass.Properties[newClass.Properties.IndexOf("Gender")] as DataPropertyDefinition;

            //Should have constraint removed
            Assert.IsNull(gender2.ValueConstraint);
        }