public PushResponseBuilder(ISession session, PushRequest pushRequest, IAccessControlLists acls) { this.session = session; this.pushRequest = pushRequest; this.acls = acls; this.metaPopulation = this.session.Database.MetaPopulation; }
internal WorkspaceRole(IMetaPopulation metaPopulation, SyncResponseRole syncResponseRole) { var value = syncResponseRole.v; this.RoleType = (IRoleType)metaPopulation.Find(Guid.Parse(syncResponseRole.t)); var objectType = this.RoleType.ObjectType; if (objectType.IsUnit) { this.Value = UnitConvert.Parse(this.RoleType.ObjectType.Id, value); } else { if (this.RoleType.IsOne) { this.Value = value != null?long.Parse(value) : (long?)null; } else { this.Value = value != null ? value.Split(Encoding.Separator).Select(long.Parse).ToArray() : Array.Empty <long>(); } } }
/// <summary> /// Initializes a new instance of the <see cref="ObjectFactory"/> class. /// </summary> /// <param name="metaPopulation"> /// The meta population. /// </param> /// <param name="assembly"> /// The assembly. /// </param> /// <param name="namespace"> /// The namespace /// </param> public ObjectFactory(IMetaPopulation metaPopulation, Type instance) { var assembly = instance.GetTypeInfo().Assembly; var types = assembly.GetTypes() .Where(type => type.Namespace != null && type.Namespace.Equals(instance.Namespace) && type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(ISessionObject))) .ToArray(); var extensionMethods = (from type in assembly.ExportedTypes where type.GetTypeInfo().IsSealed&& !type.GetTypeInfo().IsGenericType&& !type.IsNested from method in type.GetTypeInfo().DeclaredMethods where method.IsStatic && method.IsDefined(typeof(ExtensionAttribute), false) select method).ToArray(); this.MetaPopulation = metaPopulation; this.Namespace = instance.Namespace; var validationLog = metaPopulation.Validate(); if (validationLog.ContainsErrors) { throw new Exception(validationLog.ToString()); } metaPopulation.Bind(types, extensionMethods); this.typeByObjectType = new Dictionary <IObjectType, Type>(); this.objectTypeByType = new Dictionary <Type, IObjectType>(); this.objectTypeByName = new Dictionary <string, IObjectType>(); this.objectTypeByObjectTypeId = new Dictionary <Guid, IObjectType>(); this.contructorInfoByObjectType = new Dictionary <IObjectType, ConstructorInfo>(); var typeByName = types.ToDictionary(type => type.Name, type => type); foreach (var objectType in metaPopulation.Composites) { var type = typeByName[objectType.Name]; this.typeByObjectType[objectType] = type; this.objectTypeByType[type] = objectType; this.objectTypeByName[type.Name] = objectType; this.objectTypeByObjectTypeId[objectType.Id] = objectType; if (objectType is IClass) { var parameterTypes = new[] { typeof(Session) }; var constructor = type.GetTypeInfo().GetConstructor(parameterTypes); if (constructor == null) { throw new ArgumentException(objectType.Name + " has no Allors constructor."); } this.contructorInfoByObjectType[objectType] = constructor; } } }
/// <summary> /// Initializes a new instance of the <see cref="ObjectFactory"/> class. /// </summary> /// <param name="metaPopulation"> /// The meta population. /// </param> /// <param name="assembly"> /// The assembly. /// </param> /// <param name="namespace"> /// The namespace /// </param> public ObjectFactory(IMetaPopulation metaPopulation, Assembly assembly, string @namespace) { this.MetaPopulation = metaPopulation; this.Assembly = assembly; this.Namespace = @namespace; var validationLog = metaPopulation.Validate(); if (validationLog.ContainsErrors) { throw new Exception(validationLog.ToString()); } metaPopulation.Bind(assembly); this.typeByObjectType = new Dictionary <IObjectType, Type>(); this.objectTypeByType = new Dictionary <Type, IObjectType>(); this.objectTypeByName = new Dictionary <string, IObjectType>(); this.objectTypeByObjectTypeId = new Dictionary <Guid, IObjectType>(); this.contructorInfoByObjectType = new Dictionary <IObjectType, ConstructorInfo>(); var types = assembly.GetTypes().Where(type => type.Namespace != null && type.Namespace.Equals(@namespace) && type.GetInterfaces().Contains(typeof(ISessionObject))); var typeByName = types.ToDictionary(type => type.Name, type => type); foreach (var objectType in metaPopulation.Composites) { var type = typeByName[objectType.Name]; this.typeByObjectType[objectType] = type; this.objectTypeByType[type] = objectType; this.objectTypeByName[type.Name] = objectType; this.objectTypeByObjectTypeId[objectType.Id] = objectType; if (objectType is IClass) { var parameterTypes = new[] { typeof(Session) }; var constructor = type.GetConstructor(parameterTypes); if (constructor == null) { throw new ArgumentException(objectType.Name + " has no Allors constructor."); } this.contructorInfoByObjectType[objectType] = constructor; } } }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Configuration { ObjectFactory = this.CreateObjectFactory(metaPopulation), ConnectionString = ConnectionString }; var database = new Database(configuration); if (init) { database.Init(); } return database; }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Configuration { ObjectFactory = this.CreateObjectFactory(metaPopulation), ConnectionString = ConnectionString }; var database = new Database(configuration); if (init) { database.Init(); } return(database); }
//protected string ConnectionString => // $"Server=localhost; User Id=allors; Password=allors; Database=adapters; Pooling=false"; public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Configuration { ObjectFactory = this.ObjectFactory, ConnectionString = this.ConnectionString, IsolationLevel = IsolationLevel.Serializable, }; var database = new Database(this.ServiceProvider, configuration); if (init) { database.Init(); } return(database); }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new SqlClient.Configuration { ObjectFactory = this.CreateObjectFactory(metaPopulation), ConnectionString = this.ConnectionString, ConnectionFactory = this.connectionFactory, CacheFactory = this.cacheFactory }; var database = new Database(this.ServiceProvider, configuration); if (init) { database.Init(); } return(database); }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Adapters.Database.Npgsql.LongId.Configuration { ObjectFactory = this.ObjectFactory, Id = Guid.NewGuid(), ConnectionString = this.ConnectionString }; var database = new Database(this.ServiceProvider, configuration); if (init) { database.Init(); } return(database); }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Adapters.Database.Npgsql.IntegerId.Configuration { ObjectFactory = this.ObjectFactory, CacheFactory = this.CacheFactory, Id = Guid.NewGuid(), ConnectionString = ConnectionString }; var database = new Database(configuration); if (init) { database.Init(); } return(database); }
public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { var configuration = new Adapters.Database.Npgsql.IntegerId.Configuration { ObjectFactory = this.ObjectFactory, CacheFactory = this.CacheFactory, Id = Guid.NewGuid(), ConnectionString = ConnectionString }; var database = new Database(configuration); if (init) { database.Init(); } return database; }
protected ObjectFactory CreateObjectFactory(IMetaPopulation metaPopulation) => new ObjectFactory(metaPopulation, typeof(C1));
protected override IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { return(this.profile.CreateDatabase(metaPopulation, init)); }
//[Test] //[ExpectedException] //public void InitInvalidDomain() //{ // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); //} //[Test] //public void SystemTables() //{ // Assert.IsTrue(this.IsUnique("_O", "T")); // Assert.IsTrue(this.IsInteger("_O", "C")); // Assert.IsTrue(this.ExistPrimaryKey("_O", "O")); // Assert.IsFalse(this.ExistIndex("_O", "T")); // Assert.IsFalse(this.ExistIndex("_O", "C")); //} //[Test] //public void ValidateBinaryRelationDifferentSize() //{ // if (this.DetectBinarySizedDifferences) // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var allorsBinary = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BinaryId); // new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithObjectTypes(c1, allorsBinary).WithSize(200).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // allorsBinary = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BinaryId); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithObjectTypes(c1, allorsBinary).Build(); // // Different Size // c1RelationType.RoleType.Size = 300; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("allorsbinary", error.ColumnName); // } //} //[Test] //public void ValidateDecimalRelationDifferentPrecision() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // // Different precision // c1RelationType.RoleType.Precision = 11; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("allorsdecimal", error.ColumnName); //} //[Test] //public void ValidateDecimalRelationDifferentScale() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // // Different scale // c1RelationType.RoleType.Scale = 3; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("allorsdecimal", error.ColumnName); //} //[Test] //public void ValidateNewConcreteClass() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.Name = "MyDomain"; // this.CreateClass("C1"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.Name = "MyDomain"; // this.CreateClass("C1"); // // Extra class // this.CreateClass("C2"); // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // var error = tableErrors[0]; // Assert.AreEqual("c2", error.TableName); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); //} //[Test] //public void ValidateNewInterfaceInheritanceWithBooleanRelation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // var i12 = this.CreateInterface("I12"); // var i12AllorsString = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // i12AllorsString.AssociationType.ObjectType = i12; // i12AllorsString.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c1).WithSupertype(i12).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // i12 = this.CreateInterface("I12"); // i12AllorsString = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // i12AllorsString.AssociationType.ObjectType = i12; // i12AllorsString.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c1).WithSupertype(i12).Build(); // // Extra inheritance // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c2).WithSupertype(i12).Build(); // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // var error = tableErrors[0]; // Assert.AreEqual("c2", error.TableName); // Assert.AreEqual("allorsboolean", error.ColumnName); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); //} //[Test] //public void ValidateNewMany2ManyRelation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // Extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.ManyToMany).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErros = validationErrors.TableErrors; // Assert.AreEqual(1, tableErros.Length); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErros[0].Kind); // var error = tableErros[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(fromC1ToC2, error.RelationType); // Assert.AreEqual(null, error.Role); // Assert.AreEqual("c1c2", error.TableName); // Assert.AreEqual(null, error.ColumnName); //} //[Test] //public void ValidateNewMany2OneRelation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // Extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.ManyToOne).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErros = validationErrors.TableErrors; // Assert.AreEqual(1, tableErros.Length); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErros[0].Kind); // var error = tableErros[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(fromC1ToC2.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("c2", error.ColumnName); //} //[Test] //public void ValidateNewOne2ManyRelation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.OneToMany).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(fromC1ToC2.RoleType, error.Role); // Assert.AreEqual("c2", error.TableName); // Assert.AreEqual("c2c1", error.ColumnName); //} //[Test] //public void ValidateNewOne2OneRelation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(fromC1ToC2.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("c2", error.ColumnName); //} //[Test] //public void ValidateStringRelationDifferentSize() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // // Different size // c1RelationType.RoleType.Size = 101; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("allorsstring", error.ColumnName); //} //[Test] //public void ValidateStringToOne2One() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // c1RelationType.RoleType.AssignedSingularName = "RelationType"; // c1RelationType.RoleType.AssignedPluralName = "RelationTypes"; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // c1RelationType.RoleType.AssignedSingularName = "RelationType"; // c1RelationType.RoleType.AssignedPluralName = "RelationTypes"; // // From string to one2one // c1RelationType.RoleType.Size = null; // c1RelationType.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("relationtype", error.ColumnName); //} //[Test] //public void ValidateUnitRelationDifferentType() //{ // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // c1RelationType.RoleType.AssignedSingularName = "RelationType"; // c1RelationType.RoleType.AssignedPluralName = "RelationTypes"; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // c1RelationType.RoleType.AssignedSingularName = "RelationType"; // c1RelationType.RoleType.AssignedPluralName = "RelationTypes"; // // Different type // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.Unique); // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(database); // var tableErrors = validationErrors.TableErrors; // Assert.AreEqual(1, tableErrors.Length); // Assert.AreEqual(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.AreEqual(null, error.ObjectType); // Assert.AreEqual(null, error.RelationType); // Assert.AreEqual(c1RelationType.RoleType, error.Role); // Assert.AreEqual("c1", error.TableName); // Assert.AreEqual("relationtype", error.ColumnName); //} //[Test] //public void IndexesMany2Many() //{ // this.CreateDatabase().Init(); // Assert.IsTrue(this.ExistIndex("CompanyIndexedMany2ManyPerson", "R")); // Assert.IsFalse(this.ExistIndex("CompanyMany2ManyPerson", "R")); //} //[Test] //public void IndexesUnits() //{ // this.CreateDatabase().Init(); // Assert.IsTrue(this.ExistIndex("C1", "C1AllorsInteger")); // Assert.IsFalse(this.ExistIndex("C1", "C1AllorsString")); //} //[Test] //public void IncompatiblePopulation() //{ // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // var c1c2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1c2.AssociationType.ObjectType = c1; // c1c2.RoleType.ObjectType = c2; // var database = this.CreateDatabase(this.domain.MetaPopulation, false); // ISession session = null; // try // { // session = database.CreateSession(); // Assert.Fail(); // } // catch (SchemaValidationException e) // { // var validationErrors = e.ValidationErrors; // Assert.IsTrue(validationErrors.HasErrors); // } // finally // { // if (session != null) // { // session.Rollback(); // } // } //} //protected Class CreateClass(string name) //{ // return new ClassBuilder(this.domain, Guid.NewGuid()).WithSingularName(name).WithPluralName(name + "s").Build(); //} //protected Interface CreateInterface(string name) //{ // return new InterfaceBuilder(this.domain, Guid.NewGuid()).WithSingularName(name).WithPluralName(name + "s").Build(); //} protected abstract IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init);
// [Fact] // [ExpectedException] // public void InitInvalidDomain() // { // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); // } // [Fact] // public void SystemTables() // { // Assert.True(this.IsUnique("_O", "T")); // Assert.True(this.IsInteger("_O", "C")); // Assert.True(this.ExistPrimaryKey("_O", "O")); // Assert.False(this.ExistIndex("_O", "T")); // Assert.False(this.ExistIndex("_O", "C")); // } // [Fact] // public void ValidateBinaryRelationDifferentSize() // { // if (this.DetectBinarySizedDifferences) // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var allorsBinary = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BinaryId); // new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithObjectTypes(c1, allorsBinary).WithSize(200).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // allorsBinary = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BinaryId); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithObjectTypes(c1, allorsBinary).Build(); // // Different Size // c1RelationType.RoleType.Size = 300; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("allorsbinary", error.ColumnName); // } // } // [Fact] // public void ValidateDecimalRelationDifferentPrecision() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // // Different precision // c1RelationType.RoleType.Precision = 11; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("allorsdecimal", error.ColumnName); // } // [Fact] // public void ValidateDecimalRelationDifferentScale() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.DecimalId); // c1RelationType.RoleType.Precision = 10; // c1RelationType.RoleType.Scale = 2; // // Different scale // c1RelationType.RoleType.Scale = 3; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("allorsdecimal", error.ColumnName); // } // [Fact] // public void ValidateNewConcreteClass() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.Name = "MyDomain"; // this.CreateClass("C1"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.Name = "MyDomain"; // this.CreateClass("C1"); // // Extra class // this.CreateClass("C2"); // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // var error = tableErrors[0]; // Assert.Equal("c2", error.TableName); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // } // [Fact] // public void ValidateNewInterfaceInheritanceWithBooleanRelation() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // var i12 = this.CreateInterface("I12"); // var i12AllorsString = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // i12AllorsString.AssociationType.ObjectType = i12; // i12AllorsString.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c1).WithSupertype(i12).Build(); // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // i12 = this.CreateInterface("I12"); // i12AllorsString = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // i12AllorsString.AssociationType.ObjectType = i12; // i12AllorsString.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c1).WithSupertype(i12).Build(); // // Extra inheritance // new InheritanceBuilder(this.domain, Guid.NewGuid()).WithSubtype(c2).WithSupertype(i12).Build(); // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // var error = tableErrors[0]; // Assert.Equal("c2", error.TableName); // Assert.Equal("allorsboolean", error.ColumnName); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // } // [Fact] // public void ValidateNewMany2ManyRelation() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // Extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.ManyToMany).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErros = validationErrors.TableErrors; // Assert.Equal(1, tableErros.Length); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErros[0].Kind); // var error = tableErros[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(fromC1ToC2, error.RelationType); // Assert.Equal(null, error.Role); // Assert.Equal("c1c2", error.TableName); // Assert.Equal(null, error.ColumnName); // } // [Fact] // public void ValidateNewMany2OneRelation() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // Extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.ManyToOne).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErros = validationErrors.TableErrors; // Assert.Equal(1, tableErros.Length); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErros[0].Kind); // var error = tableErros[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(fromC1ToC2.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("c2", error.ColumnName); // } // [Fact] // public void ValidateNewOne2ManyRelation() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).WithCardinality(Multiplicity.OneToMany).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(fromC1ToC2.RoleType, error.Role); // Assert.Equal("c2", error.TableName); // Assert.Equal("c2c1", error.ColumnName); // } // [Fact] // public void ValidateNewOne2OneRelation() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // // extra relation // var fromC1ToC2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // fromC1ToC2.AssociationType.ObjectType = c1; // fromC1ToC2.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Missing, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(fromC1ToC2.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("c2", error.ColumnName); // } // [Fact] // public void ValidateStringRelationDifferentSize() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // // Different size // c1RelationType.RoleType.Size = 101; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("allorsstring", error.ColumnName); // } // [Fact] // public void ValidateStringToOne2One() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // c1RelationType.RoleType.SingularName = "RelationType"; // c1RelationType.RoleType.PluralName = "RelationTypes"; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.StringId); // c1RelationType.RoleType.Size = 100; // c1RelationType.RoleType.SingularName = "RelationType"; // c1RelationType.RoleType.PluralName = "RelationTypes"; // // From string to one2one // c1RelationType.RoleType.Size = null; // c1RelationType.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("relationtype", error.ColumnName); // } // [Fact] // public void ValidateUnitRelationDifferentType() // { // this.DropTable("C1"); // this.DropTable("C2"); // var environment = new MetaPopulation(); // var core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // var c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // var c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // c1RelationType.RoleType.SingularName = "RelationType"; // c1RelationType.RoleType.PluralName = "RelationTypes"; // this.CreateDatabase(this.domain.MetaPopulation, true); // environment = new MetaPopulation(); // core = Repository.Core(environment); // this.domain = new Domain(environment, Guid.NewGuid()) { Name = "MyDomain" }; // this.domain.AddDirectSuperdomain(core); // c1 = this.CreateClass("C1"); // this.CreateClass("C2"); // c1RelationType = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1RelationType.AssociationType.ObjectType = c1; // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.BooleanId); // c1RelationType.RoleType.SingularName = "RelationType"; // c1RelationType.RoleType.PluralName = "RelationTypes"; // // Different type // c1RelationType.RoleType.ObjectType = (ObjectType)this.domain.MetaPopulation.Find(UnitIds.Unique); // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // var validationErrors = this.GetSchemaValidation(Database); // var tableErrors = validationErrors.TableErrors; // Assert.Equal(1, tableErrors.Length); // Assert.Equal(SchemaValidationErrorKind.Incompatible, tableErrors[0].Kind); // var error = tableErrors[0]; // Assert.Equal(null, error.ObjectType); // Assert.Equal(null, error.RelationType); // Assert.Equal(c1RelationType.RoleType, error.Role); // Assert.Equal("c1", error.TableName); // Assert.Equal("relationtype", error.ColumnName); // } // [Fact] // public void IndexesMany2Many() // { // this.CreateDatabase().Init(); // Assert.True(this.ExistIndex("CompanyIndexedMany2ManyPerson", "R")); // Assert.False(this.ExistIndex("CompanyMany2ManyPerson", "R")); // } // [Fact] // public void IndexesUnits() // { // this.CreateDatabase().Init(); // Assert.True(this.ExistIndex("C1", "C1AllorsInteger")); // Assert.False(this.ExistIndex("C1", "C1AllorsString")); // } // [Fact] // public void IncompatiblePopulation() // { // this.DropTable("C1"); // this.DropTable("C2"); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // var c1 = this.CreateClass("C1"); // var c2 = this.CreateClass("C2"); // this.CreateDatabase(this.domain.MetaPopulation, true); // this.domain = new Domain(new MetaPopulation(), Guid.NewGuid()) { Name = "MyDomain" }; // c1 = this.CreateClass("C1"); // c2 = this.CreateClass("C2"); // var c1c2 = new RelationTypeBuilder(this.domain, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()).Build(); // c1c2.AssociationType.ObjectType = c1; // c1c2.RoleType.ObjectType = c2; // var Database = this.CreateDatabase(this.domain.MetaPopulation, false); // ISession session = null; // try // { // session = Database.CreateSession(); // Assert.True(false); // Fail // } // catch (SchemaValidationException e) // { // var validationErrors = e.ValidationErrors; // Assert.True(validationErrors.HasErrors); // } // finally // { // if (session != null) // { // session.Rollback(); // } // } // } // protected Class CreateClass(string name) // { // return new ClassBuilder(this.domain, Guid.NewGuid()).WithSingularName(name).WithPluralName(name + "s").Build(); // } // protected Interface CreateInterface(string name) // { // return new InterfaceBuilder(this.domain, Guid.NewGuid()).WithSingularName(name).WithPluralName(name + "s").Build(); // } protected abstract IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init);
public Fetch(IMetaPopulation metaPopulation, params Guid[] propertyTypeIds) : this(propertyTypeIds.Select(v => (IPropertyType)metaPopulation.Find(v)).ToArray()) { }
protected ObjectFactory CreateObjectFactory(IMetaPopulation metaPopulation) { return(new ObjectFactory(metaPopulation, typeof(C1).Assembly, "Allors.Domain")); }
protected ObjectFactory CreateObjectFactory(IMetaPopulation metaPopulation) { return new ObjectFactory(metaPopulation, typeof(C1).Assembly, "Allors.Domain"); }
protected override IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init) { return this.profile.CreateDatabase(metaPopulation, init); }
/// <summary> /// Initializes a new instance of the <see cref="ObjectFactory"/> class. /// </summary> /// <param name="environment"> /// The domain. /// </param> /// <param name="assembly"> /// The assembly. /// </param> /// <param name="namespace"> /// The namespace /// </param> public ObjectFactory(IMetaPopulation metaPopulation, Assembly assembly, string @namespace) { this.metaPopulation = metaPopulation; this.assembly = assembly; this.ns = @namespace; var validationLog = metaPopulation.Validate(); if (validationLog.ContainsErrors) { throw new Exception(validationLog.ToString()); } metaPopulation.Bind(assembly); this.typeByObjectType = new Dictionary<IObjectType, Type>(); this.objectTypeByType = new Dictionary<Type, IObjectType>(); this.objectTypeByObjectTypeId = new Dictionary<Guid, IObjectType>(); this.contructorInfoByObjectType = new Dictionary<IObjectType, ConstructorInfo>(); var types = assembly.GetTypes().Where(type => type.Namespace != null && type.Namespace.Equals(@namespace) && type.GetInterfaces().Contains(typeof(IObject))); var typeByName = types.ToDictionary(type => type.Name, type => type); foreach (var objectType in metaPopulation.Composites) { var type = typeByName[objectType.Name]; this.typeByObjectType[objectType] = type; this.objectTypeByType[type] = objectType; this.objectTypeByObjectTypeId[objectType.Id] = objectType; if (objectType is IClass) { var parameterTypes = new[] { typeof(IStrategy) }; var constructor = type.GetConstructor(parameterTypes); if (constructor == null) { throw new ArgumentException(objectType.Name + " has no Allors constructor."); } this.contructorInfoByObjectType[objectType] = constructor; } } }