public void The_Rule_Fails_But_Only_For_The_Parent() { var set = new MappingSetImpl(); var parentEntity = new EntityImpl("Parent"); var childEntity = new EntityImpl("Child"); childEntity.Parent = parentEntity; var property = new PropertyImpl("Property1"); parentEntity.AddProperty(property); set.EntitySet.AddEntity(parentEntity); set.EntitySet.AddEntity(childEntity); var table = new Table("Table1"); var column = new Column("Column1"); table.AddColumn(column); set.Database.AddTable(table); var rule = new CheckAllPropertiesMappedRule(); var result = rule.Run(set); Assert.That(result.HasIssues); Assert.That(result.Issues, Has.Count(1)); var issue = result.Issues[0]; Assert.That(issue.ErrorLevel, Is.EqualTo(ValidationErrorLevel.Warning)); Assert.That(issue.Object, Is.SameAs(property)); StringAssert.Contains("Property1", issue.Description); StringAssert.Contains("Parent", issue.Description); }
public void CopyPropertyFromParent(Property o) { Property prop = new PropertyImpl(o); prop.Entity = this; AddProperty(prop); }
public void It_Fails_If_There_Is_No_KeyType() { Entity parentEntity = new EntityImpl(); Component component = new ComponentImpl { Name = "Component_Name" }; parentEntity.AddComponent(component); Property prop = new PropertyImpl { Name = "Property1" }; parentEntity.AddProperty(prop); new EntitySetDeserialisationScheme().DeserialiseKey(NoTypeXml.GetXmlDocRoot(), parentEntity); }
public void It_Should_Serialise_To_This() { const string expectedXML = BasicPropertyXml; Property property = new PropertyImpl(); string outputXML = new EntitySetSerialisationScheme().SerialiseProperty(property); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public bool Equals(PropertyImpl obj) { if (ReferenceEquals(null, obj)) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } return(Equals(obj.name, name) && Equals(obj.Entity, Entity)); }
public void It_Is_Removed_From_The_EntityKey() { Entity entity = new EntityImpl(); Property property = new PropertyImpl(); entity.AddProperty(property); entity.Key.AddProperty(property); CollectionAssert.Contains(entity.Key.Properties, property); property.DeleteSelf(); Assert.That(entity.Key.Properties.ToList(), Is.Empty); }
public void It_Should_Create_This() { Entity parentEntity = new EntityImpl(); Component component = new ComponentImpl {Name = "Component_Name"}; parentEntity.AddComponent(component); Property prop = new PropertyImpl { Name = "Property1" }; parentEntity.AddProperty(prop); EntityKey key = new EntitySetDeserialisationScheme().DeserialiseKey(FullEntityXml.GetXmlDocRoot(), parentEntity); Assert.That(key.Properties.Count(), Is.EqualTo(1)); Assert.That(key.Properties.ElementAt(0), Is.SameAs(prop)); Assert.That(key.Component, Is.SameAs(component)); Assert.That(key.KeyType, Is.EqualTo(EntityKeyType.Properties)); }
public void It_Should_Serialise_To_This() { const string expectedXML = FullPropertyXml; Property property = new PropertyImpl { Name = "Property1", ReadOnly = true, Type = "SomeType", //IsVirtual = true, IsKeyProperty = true }; string outputXML = new EntitySetSerialisationScheme().SerialiseProperty(property); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public Property DeserialiseProperty(XmlNode propertyNode, EntityImpl parentEntity) { Property property = new PropertyImpl(); property.Entity = parentEntity; NodeProcessor processor = new NodeProcessor(propertyNode); if (processor.Exists("IsKey")) { property.IsKeyProperty = processor.GetBool("IsKey"); } property.Name = processor.GetString("Name"); property.ReadOnly = processor.GetBool("ReadOnly"); property.Type = processor.GetString("Type"); if (processor.Exists("NHibernateType")) { property.NHibernateType = processor.GetString("NHibernateType"); } if (processor.Exists("Validation")) { property.ValidationOptions = DeserialiseValidationOptions(propertyNode.SelectSingleNode("Validation")); } else { property.ValidationOptions = new ValidationOptions(); } if (processor.Exists("IsHiddenByAbstractParent")) { property.IsHiddenByAbstractParent = processor.GetBool("IsHiddenByAbstractParent"); } if (processor.Exists("IsPartOfHiddenKey")) { property.IsPartOfHiddenKey = processor.GetBool("IsPartOfHiddenKey"); } ProcessScriptBase(property, propertyNode); return(property); }
public void The_Rule_Does_Not_Identify_It_As_A_Duplicate_Property() { var set = new MappingSetImpl(); var parent = new EntityImpl("Entity1"); var child = new EntityImpl("Entity2"); set.EntitySet.AddEntity(parent); set.EntitySet.AddEntity(child); var property = new PropertyImpl("Property1"); parent.AddProperty(property); child.Parent = parent; child.CopyPropertyFromParent(property); EntityNamingRule rule = new EntityNamingRule(); var result = rule.Run(set); Assert.That(result.HasIssues, Is.False); }
public void The_Rule_Passes() { var mappingSet = new MappingSetImpl(); var parent = new EntityImpl("Parent"); var child = new EntityImpl("Child"); child.Parent = parent; var idProperty = new PropertyImpl("ID") { IsKeyProperty = true }; parent.AddProperty(idProperty); child.CopyPropertyFromParent(idProperty); mappingSet.EntitySet.AddEntity(parent); mappingSet.EntitySet.AddEntity(child); var rule = new CheckEntityInheritanceForTablePerSubclassRule(); var result = rule.Run(mappingSet); Assert.That(result.HasIssues, Is.False); }
public void The_Rule_Passes() { var set = new MappingSetImpl(); var entity = new EntityImpl("Entity1"); var property = new PropertyImpl("Property1"); entity.AddProperty(property); set.EntitySet.AddEntity(entity); var table = new Table("Table1"); var column = new Column("Column1"); table.AddColumn(column); set.Database.AddTable(table); set.ChangeMappedColumnFor(property).To(column); var rule = new CheckAllPropertiesMappedRule(); var result = rule.Run(set); Assert.That(result.HasIssues, Is.False); }
public void The_Rule_Fails() { var mappingSet = new MappingSetImpl(); var parent = new EntityImpl("Parent"); var child = new EntityImpl("Child"); child.Parent = parent; var idProperty = new PropertyImpl("ID") { IsKeyProperty = true }; parent.AddProperty(idProperty); mappingSet.EntitySet.AddEntity(parent); mappingSet.EntitySet.AddEntity(child); var rule = new CheckEntityInheritanceForTablePerSubclassRule(); var result = rule.Run(mappingSet); Assert.That(result.Issues, Has.Count(1)); var issue = result.Issues[0]; Assert.That(issue.Object, Is.SameAs(child)); Assert.That(issue.ErrorLevel, Is.EqualTo(ValidationErrorLevel.Error)); StringAssert.Contains("ID", issue.Description); }
public void SetUp() { mainPanel = MockRepository.GenerateStub<IMainPanel>(); form = MockRepository.GenerateMock<IEntityForm>(); ms = MockRepository.GenerateStub<MappingSet>(); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); entity = new EntityImpl("Entity1") { Key = key }; entity.AddProperty(property); key.AddProperty(property); mapping = new MappingImpl(); form.Stub(f => f.Mappings).Return(new List<Mapping> { mapping }); EntitySet es = new EntitySetImpl(); es.AddEntity(entity); ms.EntitySet = es; es.MappingSet = ms; ms.Stub(m => m.GetMappingsContaining(entity)).Return(new List<Mapping>()); var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); }
private Property CreateProperty(Entity newEntity, Mapping mapping, string typeName, string propertyName, string columnName, string length) { Property idProperty = new PropertyImpl(propertyName); if (typeName != null) { if (typeName.IndexOf(",") > 0) idProperty.Type = typeName.Substring(0, typeName.IndexOf(",")); else { if (NHibernateTypeNames.Contains(typeName)) idProperty.NHibernateType = typeName; else idProperty.Type = typeName; } } idProperty.ValidationOptions.MaximumLength = length.As<int>(); newEntity.AddProperty(idProperty); if (mapping != null) { var column = mapping.FromTable.GetColumn(columnName.UnBackTick()); if (column == null) { // Create the column column = entityProcessor.CreateColumn(idProperty); mapping.FromTable.AddColumn(column); } mapping.AddPropertyAndColumn(idProperty, column); } return idProperty; }
private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace) { if (unionsubclasses == null) return; @class hClass = null; unionsubclass parentSubClass = null; if (parent is @class) hClass = (@class)parent; else parentSubClass = (unionsubclass)parent; foreach (unionsubclass hSubclass in unionsubclasses) { Entity childEntity; string @namespace; string name; if (IsNameFullyQualified(hSubclass.name, out @namespace, out name)) { childEntity = new EntityImpl(name); string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString(); if (string.IsNullOrWhiteSpace(currentNamespace)) ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace); } else childEntity = new EntityImpl(hSubclass.name); childEntity.SetEntityLazy(hSubclass.lazy); newEntity.AddChild(childEntity); var childTableMapping = new MappingImpl(); childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick()); childTableMapping.ToEntity = childEntity; foreach (var ip in childEntity.InheritedProperties) { PropertyImpl np = new PropertyImpl(ip); np.IsHiddenByAbstractParent = true; childEntity.AddProperty(np); string columnName = ""; var props = hClass.Properties().ToList(); if (hClass != null) { property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name); if (matchingProp != null) { if (matchingProp.column != null) columnName = matchingProp.column; else if (matchingProp.Columns().Count > 0) columnName = matchingProp.Columns()[0].name; } else { if (hClass.Id().column1 != null) columnName = hClass.Id().column1; else if (hClass.Id().column != null && hClass.Id().column.Count() > 0) columnName = hClass.Id().column[0].name; } } else columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column; IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick()); if (column != null) childTableMapping.AddPropertyAndColumn(np, column); } foreach (var hProperty in hSubclass.Properties()) { var property = CreateProperty(childEntity, childTableMapping, hProperty); SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name); } // Add the parent's key properties as hidden properties foreach (var keyProp in newEntity.Key.Properties) { Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name); if (childP != null) { //childP.IsHiddenByAbstractParent = true; childP.IsKeyProperty = true; } } entities.AddEntity(childEntity); mappingSet.AddMapping(childTableMapping); ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace); } }
private void Populate() { //ArchAngel.Interfaces. Slyce.Common.Utility.SuspendPainting(slyceGrid1); slyceGrid1.Clear(); // Populate Columns from Entity #region Name column ColumnItem col = new ColumnItem("Name", ColumnItem.ColumnTypes.Textbox, "NewProp", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion #region Type column col = new ColumnItem("Type", ColumnItem.ColumnTypes.ComboBox, "System.String", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; foreach (var x in ArchAngel.Interfaces.ProjectOptions.TypeMappings.Utility.DotNetTypes.Select(t => t.CSharpName).Distinct()) col.ComboItems.Add(x, null); slyceGrid1.Columns.Add(col); #endregion #region NHibernate Type column col = new ColumnItem("NHibernate Type", ColumnItem.ColumnTypes.ComboBox, "System.String", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; foreach (var x in Enum.GetNames(typeof(PropertyImpl.NHibernateTypes)).OrderBy(t => t)) col.ComboItems.Add(x, null); slyceGrid1.Columns.Add(col); #endregion #region MappedColumns column ColumnItem mappedColumnsColumn = new ColumnItem("Mapped To", ColumnItem.ColumnTypes.ComboBox, "", "General"); mappedColumnsColumn.ComboItems.Add("", null); mappedColumnsColumn.ColorScheme = ColumnItem.ColorSchemes.Blue; int numTables = MappedTables.Count; bool hasMultiSchemas = MappedTables.Select(t => t.Schema).Distinct().Count() > 1; foreach (Table table in MappedTables) { foreach (Column column in table.Columns) { string name; if (numTables == 1) name = column.Name; else if (hasMultiSchemas) name = string.Format("{0}.{1}.{2}", table.Schema, table.Name, column.Name); else name = string.Format("{0}.{1}", table.Name, column.Name); if (!mappedColumnsColumn.ComboItems.ContainsKey(name)) mappedColumnsColumn.ComboItems.Add(name, column); } } slyceGrid1.Columns.Add(mappedColumnsColumn); #endregion #region InKey column col = new ColumnItem("In Key", ColumnItem.ColumnTypes.Checkbox, false, "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion #region ReadOnly column col = new ColumnItem("Read-only", ColumnItem.ColumnTypes.Checkbox, false, "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion ArchAngel.Providers.EntityModel.Model.EntityLayer.PropertyImpl prop = new ArchAngel.Providers.EntityModel.Model.EntityLayer.PropertyImpl(); foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in prop.Ex.OrderBy(u => u.Name)) { if (uo.DataType == typeof(bool?)) col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.NullableCheckBox, null, "General"); else if (uo.DataType == typeof(string)) col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"); else if (uo.DataType == typeof(int)) col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.IntegerInput, null, "General"); else if (uo.DataType == typeof(bool)) col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Checkbox, null, "General"); else if (uo.DataType.ToString() == "ArchAngel.Interfaces.NHibernateEnums.PropertyAccessTypes") { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.ComboBox, null, "General"); foreach (var x in Enum.GetNames(typeof(ArchAngel.Interfaces.NHibernateEnums.PropertyAccessTypes)).OrderBy(t => t)) col.ComboItems.Add(x, null); } else if (uo.DataType.ToString() == "ArchAngel.Interfaces.NHibernateEnums.PropertyGeneratedTypes") { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.ComboBox, null, "General"); foreach (var x in Enum.GetNames(typeof(ArchAngel.Interfaces.NHibernateEnums.PropertyGeneratedTypes)).OrderBy(t => t)) col.ComboItems.Add(x, null); } else throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); } #region Validation options slyceGrid1.Columns.Add(new ColumnItem("Fractional Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Future Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Integer Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Max Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Min Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Max Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Min Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Not Empty", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Nullable", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Past Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Regex", ColumnItem.ColumnTypes.NullableTextBox, "", "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Validate", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); #endregion foreach (ArchAngel.Providers.EntityModel.Model.EntityLayer.Property property in Entity.Properties.Except(Entity.ForeignKeyPropertiesToExclude)) { AddPropertyToPropertiesGrid(property, hasMultiSchemas); } slyceGrid1.Populate(); slyceGrid1.FrozenColumnIndex = 1; Slyce.Common.Utility.ResumePainting(slyceGrid1); }
private void slyceGrid1_NewRowAdded(out object newObject) { Property property = new PropertyImpl("NewProperty") { Type = "System.String", NHibernateType = "String", Entity = this.Entity, IsKeyProperty = false, ReadOnly = false }; property.ValidationOptions.FractionalDigits = 0; property.ValidationOptions.FutureDate = false; property.ValidationOptions.IntegerDigits = 0; property.ValidationOptions.MaximumLength = 0; property.ValidationOptions.MaximumValue = 0; property.ValidationOptions.MinimumLength = 0; property.ValidationOptions.MinimumValue = 0; property.ValidationOptions.NotEmpty = false; property.ValidationOptions.Nullable = false; property.ValidationOptions.PastDate = false; property.ValidationOptions.RegexPattern = ""; property.ValidationOptions.Validate = false; Entity.AddProperty(property); newObject = property; bool hasMultiSchemas = MappedTables.Select(t => t.Schema).Distinct().Count() > 1; AddPropertyToPropertiesGrid(property, hasMultiSchemas); }
public void The_Presenter_Fills_In_The_Form() { IMainPanel mainPanel = MockRepository.GenerateStub<IMainPanel>(); IEntityForm form = MockRepository.GenerateMock<IEntityForm>(); form.Expect(f => f.Mappings = null) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Mapping>) action.Arguments[0]).Count(), Is.EqualTo(0))); form.Expect(f => f.SetAvailableTables(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<ITable>)action.Arguments[0]).Count(), Is.EqualTo(0))); form.Expect(f => f.SetProperties(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Property>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetAvailableEntities(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(2))); form.Expect(f => f.SetChildEntities(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); Entity parentEntity = new EntityImpl("Parent"); Entity childEntity = new EntityImpl("Child"); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); Entity entity = new EntityImpl("Entity1") { Key = key }; entity.Parent = parentEntity; entity.AddChild(childEntity); entity.AddProperty(property); key.AddProperty(property); EntitySet es = new EntitySetImpl(); es.AddEntity(parentEntity); es.AddEntity(entity); es.AddEntity(childEntity); MappingSet ms = new MappingSetImpl(); ms.EntitySet = es; var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); form.AssertWasCalled(f => f.EntityName = entity.Name); form.AssertWasCalled(f => f.Discriminator = entity.Discriminator); form.AssertWasCalled(f => f.ParentEntity = entity.Parent); form.AssertWasCalled(f => f.SetVirtualProperties(entity.Ex)); form.VerifyAllExpectations(); }
private void Populate() { //ArchAngel.Interfaces. Slyce.Common.Utility.SuspendPainting(slyceGrid1); slyceGrid1.Clear(); // Populate Columns from Entity #region Name column ColumnItem col = new ColumnItem("Name", ColumnItem.ColumnTypes.Textbox, "NewProp", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion #region Type column col = new ColumnItem("Type", ColumnItem.ColumnTypes.ComboBox, "System.String", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; foreach (var x in ArchAngel.Interfaces.ProjectOptions.TypeMappings.Utility.DotNetTypes.Select(t => t.CSharpName).Distinct()) { col.ComboItems.Add(x, null); } slyceGrid1.Columns.Add(col); #endregion #region NHibernate Type column col = new ColumnItem("NHibernate Type", ColumnItem.ColumnTypes.ComboBox, "System.String", "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; foreach (var x in Enum.GetNames(typeof(PropertyImpl.NHibernateTypes)).OrderBy(t => t)) { col.ComboItems.Add(x, null); } slyceGrid1.Columns.Add(col); #endregion #region MappedColumns column ColumnItem mappedColumnsColumn = new ColumnItem("Mapped To", ColumnItem.ColumnTypes.ComboBox, "", "General"); mappedColumnsColumn.ComboItems.Add("", null); mappedColumnsColumn.ColorScheme = ColumnItem.ColorSchemes.Blue; int numTables = MappedTables.Count; bool hasMultiSchemas = MappedTables.Select(t => t.Schema).Distinct().Count() > 1; foreach (Table table in MappedTables) { foreach (Column column in table.Columns) { string name; if (numTables == 1) { name = column.Name; } else if (hasMultiSchemas) { name = string.Format("{0}.{1}.{2}", table.Schema, table.Name, column.Name); } else { name = string.Format("{0}.{1}", table.Name, column.Name); } if (!mappedColumnsColumn.ComboItems.ContainsKey(name)) { mappedColumnsColumn.ComboItems.Add(name, column); } } } slyceGrid1.Columns.Add(mappedColumnsColumn); #endregion #region InKey column col = new ColumnItem("In Key", ColumnItem.ColumnTypes.Checkbox, false, "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion #region ReadOnly column col = new ColumnItem("Read-only", ColumnItem.ColumnTypes.Checkbox, false, "General"); col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); #endregion ArchAngel.Providers.EntityModel.Model.EntityLayer.PropertyImpl prop = new ArchAngel.Providers.EntityModel.Model.EntityLayer.PropertyImpl(); foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in prop.Ex.OrderBy(u => u.Name)) { if (uo.DataType == typeof(bool?)) { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.NullableCheckBox, null, "General"); } else if (uo.DataType == typeof(string)) { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"); } else if (uo.DataType == typeof(int)) { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.IntegerInput, null, "General"); } else if (uo.DataType == typeof(bool)) { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Checkbox, null, "General"); } else if (uo.DataType.ToString() == "ArchAngel.Interfaces.NHibernateEnums.PropertyAccessTypes") { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.ComboBox, null, "General"); foreach (var x in Enum.GetNames(typeof(ArchAngel.Interfaces.NHibernateEnums.PropertyAccessTypes)).OrderBy(t => t)) { col.ComboItems.Add(x, null); } } else if (uo.DataType.ToString() == "ArchAngel.Interfaces.NHibernateEnums.PropertyGeneratedTypes") { col = new ColumnItem(uo.Text, ColumnItem.ColumnTypes.ComboBox, null, "General"); foreach (var x in Enum.GetNames(typeof(ArchAngel.Interfaces.NHibernateEnums.PropertyGeneratedTypes)).OrderBy(t => t)) { col.ComboItems.Add(x, null); } } else { throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name); } col.ColorScheme = ColumnItem.ColorSchemes.Blue; slyceGrid1.Columns.Add(col); } #region Validation options slyceGrid1.Columns.Add(new ColumnItem("Fractional Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Future Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Integer Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Max Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Min Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Max Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Min Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Not Empty", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Nullable", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Past Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Regex", ColumnItem.ColumnTypes.NullableTextBox, "", "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); slyceGrid1.Columns.Add(new ColumnItem("Validate", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)") { ColorScheme = ColumnItem.ColorSchemes.Green }); #endregion foreach (ArchAngel.Providers.EntityModel.Model.EntityLayer.Property property in Entity.Properties.Except(Entity.ForeignKeyPropertiesToExclude)) { AddPropertyToPropertiesGrid(property, hasMultiSchemas); } slyceGrid1.Populate(); slyceGrid1.FrozenColumnIndex = 1; Slyce.Common.Utility.ResumePainting(slyceGrid1); }
public void Adding_An_Existing_KeyProperty_Should_Add_It_To_The_EntityKey() { var entity = new EntityImpl(); var property = new PropertyImpl(); property.IsKeyProperty = true; entity.AddProperty(property); Assert.That(entity.Key.Properties.Contains(property), "Key doesn't contain the property"); }
void form_AddNewProperty(object sender, EventArgs e) { string name = "New_Property".GetNextName(entity.Properties.Select(p => p.Name)); var property = new PropertyImpl(name); entity.AddProperty(property); form.SetProperties(entity.ConcreteProperties); form.Mappings = entity.Mappings(); form.SetSelectedPropertyName(property); }
public void The_Rule_Fails() { var set = new MappingSetImpl(); var entity = new EntityImpl("Entity1"); set.EntitySet.AddEntity(entity); entity.AddProperty(new PropertyImpl("Property1")); var duplicate = new PropertyImpl("Property1"); entity.AddProperty(duplicate); EntityNamingRule rule = new EntityNamingRule(); var result = rule.Run(set); Assert.That(result.Issues, Has.Count(1)); var issue = result.Issues[0]; Assert.That(issue.ErrorLevel, Is.EqualTo(ValidationErrorLevel.Error)); Assert.That(issue.Object, Is.SameAs(duplicate)); StringAssert.Contains("Property1", issue.Description); }
public void The_Mapping_Mappings_Should_Be_Updated() { var m = new MappingImpl(); m.FromTable = new Table("table1"); m.ToEntity = new EntityImpl("entity1"); m.MappingSet = new MappingSetImpl(); var property = new PropertyImpl("Prop"); var column = new Column("Col"); m.FromTable.AddColumn(column); m.ToEntity.AddProperty(property); m.AddPropertyAndColumn(property, column); form.Mappings = m.Mappings; form.GetEventRaiser(f => f.FromTableChanged += null).Raise(form, new EventArgs()); var colAndProp = m.Mappings.ElementAt(0); Assert.That(colAndProp.Property, Is.SameAs(property)); Assert.That(colAndProp.Column, Is.SameAs(column)); }
public void It_Returns_The_Property_Objects() { ProviderInfo info = new ProviderInfo(); var entity1 = new EntityImpl(); var property1 = new PropertyImpl("1"); entity1.AddProperty(property1); var entity2 = new EntityImpl(); var property2 = new PropertyImpl("2"); entity2.AddProperty(property2); info.MappingSet.EntitySet.AddEntity(entity1); info.MappingSet.EntitySet.AddEntity(entity2); IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(Property)); Assert.That(objects, Has.Length(2)); Assert.That(objects.Contains(property1)); Assert.That(objects.Contains(property2)); }
public bool Equals(PropertyImpl obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return Equals(obj.name, name) && Equals(obj.Entity, Entity); }
public void Setting_IsKeyProperty_To_True_Should_Add_It_To_The_Key() { var entity = new EntityImpl(); var property = new PropertyImpl(); entity.AddProperty(property); Assert.IsFalse(entity.Key.Properties.Contains(property), "Key shouldn't already contain the property"); property.IsKeyProperty = true; Assert.That(entity.Key.Properties.Contains(property), "Key doesn't contain the property"); }
public void CopyPropertyFromParent(Property o) { Property prop = new PropertyImpl(o); prop.Entity = this; AddProperty(prop); }
public void Setting_IsKeyProperty_To_False_Should_Remove_It_From_The_Key() { var entity = new EntityImpl(); var property = new PropertyImpl(); property.IsKeyProperty = true; entity.AddProperty(property); Assert.IsTrue(entity.Key.Properties.Contains(property), "Key should already contain the property"); property.IsKeyProperty = false; Assert.IsFalse(entity.Key.Properties.Contains(property), "Key shouldn't contain the property"); }
private bool CreateNewEntity() { if (RequestorType == RequestorTypes.Table) { List<ITable> tablesToProcess = new List<ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(Table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List<Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet); SelectedEntity = newEntities[0]; #region Remove un-selected columns List<string> selectedColumnNames = new List<string>(); foreach (ListViewItem col in listViewEntities.CheckedItems) selectedColumnNames.Add(col.Text); for (int i = SelectedEntity.Properties.Count() - 1; i >= 0; i--) { Property property = SelectedEntity.Properties.ElementAt(i); if (!selectedColumnNames.Contains(property.MappedColumn().Name)) SelectedEntity.RemoveProperty(property); } #endregion SelectedEntity.Name = textBoxName.Text; return true; } else if (RequestorType == RequestorTypes.Entity_Select_Parent || RequestorType == RequestorTypes.Entity_Create_Abstract_Parent) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some properties to be moved into the abstract parent (Table Per Concrete Class)", "No properties selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (RequestorType == RequestorTypes.Entity_Create_Abstract_Parent && string.IsNullOrWhiteSpace(textBoxName.Text) || textBoxName.Text == DefaultNewAbstractParentName) { MessageBox.Show(this, "Please enter a name for the new abstract parent entity.", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Entity newEntity = new EntityImpl(textBoxName.Text) { Schema = Entity.Schema }; newEntity.IsAbstract = true; // Check that all key-properties are selected List<Property> selectedProperties = new List<Property>(); foreach (ListViewItem item in SelectedPropertyItems) selectedProperties.Add((Property)item.Tag); List<Property> unselectedKepProperties = new List<Property>(); foreach (Property prop in Entity.Properties) if (prop.IsKeyProperty && !selectedProperties.Contains(prop)) unselectedKepProperties.Add(prop); if (unselectedKepProperties.Count > 0) { string keyPropNames = ""; foreach (Property p in unselectedKepProperties) keyPropNames += p.Name + ", "; MessageBox.Show(this, "All key properties need to be selected: " + keyPropNames.TrimEnd(',', ' '), "Invalid selection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; PropertyImpl newProp = new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType, IsKeyProperty = existingProperty.IsKeyProperty }; //newProp.SetMappedColumn(existingProperty.MappedColumn()); newEntity.AddProperty(newProp); //newEntity.AddProperty(existingProperty); // Remove this property from the existing Entity, as it's now been added to the parent //if (existingProperty.IsKeyProperty) existingProperty.IsHiddenByAbstractParent = true; //else // Entity.RemoveProperty(existingProperty); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return true; } else if (RequestorType == RequestorTypes.Entity_Select_Child) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some child entities.", "No entities selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Entity newEntity = new EntityImpl("NewChildEntity") { Schema = Entity.Schema }; foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; newEntity.AddProperty(new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType }); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return true; } else throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString()); }