public FormRefactorToComponent(EntityImpl entity, List <Property> properties) { InitializeComponent(); SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); FontItem = new Font(Font.FontFamily.Name, 8F, FontStyle.Regular); FontType = new Font(Font.FontFamily.Name, 7F, FontStyle.Regular); FocusHelper = new Slyce.Common.TextBoxFocusHelper(new TextBox[] { textBoxComponentEntityName, textBoxNewComponentName }); NewComponent = new ComponentSpecificationImpl(NewComponentText); foreach (Property prop in properties) { NewComponent.AddProperty(ComponentPropertyImpl.CreateFromProperty(prop)); } textBoxNewComponentName.Text = NewComponentText; Entity = entity; Properties = properties; int maxHeight = Populate(); ResizeForm(maxHeight); }
public void It_Should_Create_This() { const string xml = When_Serialising_A_ComponentProperty.BasicPropertyXml; ComponentSpecification spec = new ComponentSpecificationImpl(); ComponentProperty prop = new EntitySetDeserialisationScheme().DeserialiseComponentProperty(xml.GetXmlDocRoot(), spec); Assert.That(prop.Specification, Is.SameAs(spec)); Assert.That(prop.Name, Is.EqualTo("Street")); Assert.That(prop.ValidationOptions, Is.Not.Null); Assert.That(prop.Type, Is.EqualTo("object")); }
public void Form_Is_Set_Up() { IComponentSpecificationForm form = MockRepository.GenerateMock <IComponentSpecificationForm>(); IMainPanel panel = MockRepository.GenerateMock <IMainPanel>(); var mappingSet = new MappingSetImpl(); var entity = new EntityImpl("Entity1"); entity.AddProperty(new PropertyImpl("Property1")); var table = new Table("Table1"); table.AddColumn(new Column("Column1")); table.AddColumn(new Column("Street")); mappingSet.EntitySet.AddEntity(entity); mappingSet.ChangeMappedColumnFor(entity.Properties.First()).To(table.Columns[0]); ComponentSpecification spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); Component component = spec.CreateImplementedComponentFor(entity, "Street"); mappingSet.EntitySet.AddComponentSpecification(spec); var mapping = new ComponentMappingImpl { ToComponent = component, FromTable = table }; mapping.AddPropertyAndColumn(component.Properties[0], table.Columns[0]); mappingSet.AddMapping(mapping); form.Expect(f => f.SetProperties(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable <ComponentProperty>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetUsages(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable <Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetFullEntityList(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable <Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); ComponentSpecificationPresenter presenter = new ComponentSpecificationPresenter(panel, form); presenter.AttachToModel(spec); form.AssertWasCalled(f => f.Clear()); form.AssertWasCalled(f => f.SpecName = spec.Name); form.AssertWasCalled(f => f.SetVirtualProperties(spec.Ex)); form.VerifyAllExpectations(); }
public void It_Should_Create_This() { const string xml = When_Serialising_A_ComponentProperty.BasicPropertyXml; ComponentSpecification spec = new ComponentSpecificationImpl(); ComponentProperty prop = new EntitySetDeserialisationScheme().DeserialiseComponentProperty(xml.GetXmlDocRoot(), spec); Assert.That(prop.Specification, Is.SameAs(spec)); Assert.That(prop.Name, Is.EqualTo("Street")); Assert.That(prop.ValidationOptions, Is.Not.Null); Assert.That(prop.Type, Is.EqualTo("object")); }
public void It_Should_Serialise_To_This() { const string expectedXML = BasicSpecXml; var spec = new ComponentSpecificationImpl(); spec.Name = "Address"; spec.AddProperty(new ComponentPropertyImpl("Street")); spec.CreateImplementedComponentFor(new EntityImpl("Entity1"), "HomeAddress"); string outputXML = new EntitySetSerialisationScheme().SerialiseComponentSpecification(spec); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public void It_Should_Serialise_To_This() { const string expectedXML = BasicSpecXml; var spec = new ComponentSpecificationImpl(); spec.Name = "Address"; spec.AddProperty(new ComponentPropertyImpl("Street")); spec.CreateImplementedComponentFor(new EntityImpl("Entity1"), "HomeAddress"); string outputXML = new EntitySetSerialisationScheme().SerialiseComponentSpecification(spec); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public void Form_Is_Set_Up() { IComponentSpecificationForm form = MockRepository.GenerateMock<IComponentSpecificationForm>(); IMainPanel panel = MockRepository.GenerateMock<IMainPanel>(); var mappingSet = new MappingSetImpl(); var entity = new EntityImpl("Entity1"); entity.AddProperty(new PropertyImpl("Property1")); var table = new Table("Table1"); table.AddColumn(new Column("Column1")); table.AddColumn(new Column("Street")); mappingSet.EntitySet.AddEntity(entity); mappingSet.ChangeMappedColumnFor(entity.Properties.First()).To(table.Columns[0]); ComponentSpecification spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); Component component = spec.CreateImplementedComponentFor(entity, "Street"); mappingSet.EntitySet.AddComponentSpecification(spec); var mapping = new ComponentMappingImpl {ToComponent = component, FromTable = table}; mapping.AddPropertyAndColumn(component.Properties[0], table.Columns[0]); mappingSet.AddMapping(mapping); form.Expect(f => f.SetProperties(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<ComponentProperty>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetUsages(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetFullEntityList(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); ComponentSpecificationPresenter presenter = new ComponentSpecificationPresenter(panel, form); presenter.AttachToModel(spec); form.AssertWasCalled(f => f.Clear()); form.AssertWasCalled(f => f.SpecName = spec.Name); form.AssertWasCalled(f => f.SetVirtualProperties(spec.Ex)); form.VerifyAllExpectations(); }
public void ApplyChanges(MappingSet mappingSet, EntityKey key) { // Create the new Spec ComponentSpecification spec = new ComponentSpecificationImpl(newComponentSpecificationName); var properties = key.Properties.ToList(); foreach (var property in properties) { var newProperty = ComponentPropertyImpl.CreateFromProperty(property); spec.AddProperty(newProperty); } mappingSet.EntitySet.AddComponentSpecification(spec); // Create the new Component var component = spec.CreateImplementedComponentFor(key.Parent, newComponentName); // Map the old property's columns to the new component for (int i = 0; i < properties.Count; i++) { var property = properties[i]; var newProperty = spec.Properties[i]; var componentProperty = component.GetProperty(newProperty.Name); mappingSet.ChangeMappingFor(componentProperty).To(property.MappedColumn()); } // Delete old properties if (deleteExistingProperties) { foreach (var property in properties) { property.DeleteSelf(); } } // Set the Key to use the new component. key.Component = component; }
public void It_Should_Create_This() { const string xml = When_Serialising_A_Component.BasicComponentXml; var parentEntity = new EntityImpl("Entity1"); var entitySet = new EntitySetImpl(); entitySet.AddEntity(parentEntity); var spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); spec.EntitySet = entitySet; Component comp = new EntitySetDeserialisationScheme().DeserialiseComponent(xml.GetXmlDocRoot(), spec); Assert.That(comp.Name, Is.EqualTo("HomeAddress")); Assert.That(comp.ParentEntity, Is.SameAs(parentEntity)); Assert.That(comp.Specification, Is.SameAs(spec)); Assert.That(comp.Properties, Has.Count(1)); Assert.That(comp.Properties[0].RepresentedProperty, Is.SameAs(spec.Properties[0])); }
public void ApplyChanges(MappingSet mappingSet, EntityKey key) { // Create the new Spec ComponentSpecification spec = new ComponentSpecificationImpl(newComponentSpecificationName); var properties = key.Properties.ToList(); foreach (var property in properties) { var newProperty = ComponentPropertyImpl.CreateFromProperty(property); spec.AddProperty(newProperty); } mappingSet.EntitySet.AddComponentSpecification(spec); // Create the new Component var component = spec.CreateImplementedComponentFor(key.Parent, newComponentName); // Map the old property's columns to the new component for (int i = 0; i < properties.Count; i++) { var property = properties[i]; var newProperty = spec.Properties[i]; var componentProperty = component.GetProperty(newProperty.Name); mappingSet.ChangeMappingFor(componentProperty).To(property.MappedColumn()); } // Delete old properties if(deleteExistingProperties) { foreach(var property in properties) { property.DeleteSelf(); } } // Set the Key to use the new component. key.Component = component; }
private void ProcessComponent(component hComponent, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults) { if (hComponent.@class == null) { log.ErrorFormat("Could not load component named {0} on class {1} because it does not have a class attribute.", hComponent.name, newEntity.Name); return; } var possibleClasses = GetPossibleClasses(hComponent.@class, hmNamespace, mappedTable.Schema, parseResults); if (possibleClasses.Count == 0) { log.ErrorFormat("Could not load component named {0} on class {1} because we could not find the class named {2}.", hComponent.name, newEntity.Name, hComponent.@class); return; } ComponentSpecification spec = null; foreach (var possibleClass in possibleClasses) { spec = specifications.GetValueOrDefault(possibleClass); if (spec != null) break; } bool createProperties = false; if (spec == null) { // Create a new spec from these. spec = new ComponentSpecificationImpl(GetShortClassName(hComponent.@class)); newEntity.EntitySet.AddComponentSpecification(spec); createProperties = true; } Component component = spec.CreateImplementedComponentFor(newEntity, hComponent.name); newEntity.Key.Component = component; var mapping = new ComponentMappingImpl(); foreach (var prop in hComponent.Properties()) { if (createProperties) { ComponentProperty idProperty = new ComponentPropertyImpl(prop.name); idProperty.Type = prop.type1; idProperty.ValidationOptions.MaximumLength = prop.length.As<int>(); SetPropertyInfoFromParsedCode(possibleClasses, idProperty); spec.AddProperty(idProperty); } var compProperty = component.GetProperty(prop.name); var column = mappedTable.GetColumn(prop.column.UnBackTick()); if (column == null) { // Create the column column = entityProcessor.CreateColumn(compProperty.RepresentedProperty); mapping.FromTable.AddColumn(column); } mapping.AddPropertyAndColumn(compProperty, column); } newEntity.EntitySet.MappingSet.AddMapping(mapping); }
private bool ProcessComponentKey(compositeid hCompId, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults) { var possibleClasses = GetPossibleClasses(hCompId.@class, hmNamespace, mappedTable.Schema, parseResults); if (possibleClasses.Count == 0) return false; ComponentSpecification spec = null; foreach (var possibleClass in possibleClasses) { spec = specifications.GetValueOrDefault(possibleClass); if (spec != null) break; } bool createProperties = false; if (spec == null) { // Create a new spec from these. spec = new ComponentSpecificationImpl(GetShortClassName(hCompId.@class)); newEntity.EntitySet.AddComponentSpecification(spec); createProperties = true; } Component component = spec.CreateImplementedComponentFor(newEntity, hCompId.name); newEntity.Key.Component = component; var mapping = new ComponentMappingImpl(); foreach (var prop in hCompId.KeyProperties()) { if (createProperties) { ComponentProperty idProperty = new ComponentPropertyImpl(prop.name); idProperty.Type = prop.type1; idProperty.ValidationOptions.MaximumLength = prop.length.As<int>(); SetPropertyInfoFromParsedCode(possibleClasses, idProperty); spec.AddProperty(idProperty); } var compProperty = component.GetProperty(prop.name); var column = mappedTable.GetColumn(prop.column1.UnBackTick()); if (column == null) { // Create the column column = entityProcessor.CreateColumn(compProperty.RepresentedProperty); mapping.FromTable.AddColumn(column); } mapping.AddPropertyAndColumn(compProperty, column); } newEntity.EntitySet.MappingSet.AddMapping(mapping); return true; }