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); }
public void TestSerialization() { var impl = new PropertyImpl { Id = 1 }; var doc = impl.ToBsonDocument(); var expected = new BsonDocument("_id", 1); Assert.AreEqual(expected, doc); }
private void ContentTypeSettingsForm_Load(object sender, EventArgs e) { if (EditorUtility.IsDesignerHosted(this)) { return; } //ESet<string> addedComponentNames = new ESet<string>(); foreach (var child in component.Components) { if (child.DisplayInEditor && !child.TypeOnly && !string.IsNullOrEmpty(child.Name) && child.TypeSettingsIsPublic()) //&& !addedComponentNames.Contains( child.Name ) ) { //bool skip = false; //Type Settings filter //var baseComponentType = component.BaseType as Metadata.ComponentTypeInfo; //if( baseComponentType != null && component.TypeSettingsIsPrivateObject( child ) ) // skip = true; //if( !skip ) //{ bool value = !ComponentUtility.TypeSettingsPrivateObjectsContains(component.TypeSettingsPrivateObjects, child); //bool value = !component._TypeSettingsIsPrivateObject( child, false ); //List<Attribute> attributes = new List<Attribute>(); var propertyImpl = new PropertyImpl(this, ObjectTypeEnum.Component, child, child.Name, MetadataManager.GetTypeOfNetType(typeof(bool)), "Components", value); propertyImpl.DefaultValueSpecified = true; propertyImpl.DefaultValue = true; objectImpl.properties.Add(propertyImpl); //addedComponentNames.Add( child.Name ); //} } } foreach (var member in MetadataManager.MetadataGetMembers(component)) { var property = member as Metadata.Property; //!!!!что еще? от базового класс Type Settings if (property != null && EditorUtility.IsMemberVisible(property)) { bool value = !ComponentUtility.TypeSettingsPrivateObjectsContains(component.TypeSettingsPrivateObjects, property); //bool value = !component._TypeSettingsIsPrivateObject( property, false ); //List<Attribute> attributes = new List<Attribute>(); var propertyImpl = new PropertyImpl(this, ObjectTypeEnum.Property, null, property.Name, MetadataManager.GetTypeOfNetType(typeof(bool)), "Properties", value); propertyImpl.DefaultValueSpecified = true; propertyImpl.DefaultValue = true; objectImpl.properties.Add(propertyImpl); } } hierarchicalContainer1.SetData(null, new object[] { objectImpl }); }
public override void NeedUpdateCreatedMembers() { base.NeedUpdateCreatedMembers(); createdProperty = null; createdChangedEvent = null; }
void Update() { if (needUpdate) { //!!!!slowly? var demandedReturnType = GetDemandedReturnType(); if (demandedReturnType != createdPropertyReturnType || property == null) { Clear(); if (Enabled) //!!!!? { needUpdate = false; if (demandedReturnType != null) { //!!!!TypeInfo? Type unrefNetType = ReferenceUtility.GetUnreferencedType(demandedReturnType.GetNetType()); var type = MetadataManager.GetTypeOfNetType(unrefNetType); //!!!! var typeUnreferenced = type; var p = new PropertyImpl(this, "Output", false, type, typeUnreferenced, new Metadata.Parameter[0], true, "Parameter", false); p.Description = ""; property = p; createdPropertyReturnType = demandedReturnType; } } } } }
private bool AddOrUpdateProperty(string name, bool isGet, IMethod orig) { var holder = _type as IHasProperties; if (holder == null) { return(false); } if (orig.Parameters.Count >= (isGet ? 1 : 2)) { return(AddOrUpdateIndexer(name, isGet, orig)); } var prop = holder.Properties.FirstOrDefault(p => p.Name == name); if (prop == null) { holder.Properties.Add(prop = new PropertyImpl(name)); } prop.Visibility = orig.Visibility; if (isGet) { prop.Type = orig.ReturnType; prop.Getter = ""; } else { prop.Type = orig.Parameters.FirstOrDefault()?.Type ?? typeof(object).FullName; prop.Setter = ""; } return(true); }
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 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); }
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(); }
void Clear() { memberObject = null; properties.Clear(); propertyBySignature.Clear(); propertyMethodParameters = null; //propertyMethodReturnParameter = null; propertyPropertyValue = null; }
PropertyImpl CreateProperty() { //!!!! List <Component_MemberParameter> indexers = new List <Component_MemberParameter>(); //List<Component_MemberParameter> indexers = Indexers; List <Metadata.Parameter> indexers2 = new List <Metadata.Parameter>(indexers.Count); //!!!! //foreach( var index in indexers ) //{ // if( Cache == null ) // Log.Fatal( "Component_Property: CreateMetadataMember: Cache == null." ); // Metadata.Parameter p = index.CreateMetadataParameter( Cache ); // if( p == null ) // { // //!!!! // return null; // } // indexers2.Add( p ); //} //!!!!! var unrefType = Type.Value; // MetadataManager.GetType( Type ); if (unrefType == null) { //!!!! //Log.Warning( "The type with name \"{0}\" is not exists.", type ); return(null); } var resultType = unrefType; if (ReferenceSupport) { Type unrefNetType = unrefType.GetNetType(); var refNetType = typeof(Reference <>).MakeGenericType(unrefNetType); resultType = MetadataManager.GetTypeOfNetType(refNetType); } var property = new PropertyImpl(Parent, Name, Static, resultType, unrefType, indexers2.ToArray(), ReadOnly, this, Category, ReferenceSupport); property.Description = Description; property.Serializable = Serializable; property.Cloneable = Cloneable; property.Browsable = Browsable; UpdateDefaultValue(property); //!!!!ChangedEvent return(property); }
public void Inherited_Properties_Are_Not_Included_In_ConcreteProperties() { var property1 = new PropertyImpl { Name = "Prop2" }; entity.AddProperty(property1); Assert.That(entity.ConcreteProperties.Count, Is.EqualTo(1)); Assert.That(entity.Properties.Contains(property1), "Child property missing"); }
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"); }
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)); }
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 PropertyImpl AddProperty(string name, string category, object value, IList <Attribute> attributes = null) { var property = new PropertyImpl(this, StringUtility.ToUpperFirstCharacter(name), MetadataManager.GetTypeOfNetType(value.GetType()), attributes, category, value); property.DefaultValueSpecified = true; property.DefaultValue = value; Properties.Add(property); return(property); }
protected override void CreateMembers(List <Metadata.Member> created) { //!!!!ChangedEvent var property = CreateProperty(); if (property != null) { createdProperty = property; created.Add(property); } }
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"); }
void Update() { //check disabled if (!Enabled) { Clear(); return; } //check for updates if (!needUpdate && !Cases.SequenceEqual(initializedForCases)) { needUpdate = true; } //nothing to update if (!needUpdate) { return; } //do update Clear(); initializedForCases = new List <string>(Cases); needUpdate = false; //Cases for (int nCase = 0; nCase < Cases.Count; nCase++) { var caseValue = Cases[nCase]; var p = new PropertyImpl(this, "Case" + nCase.ToString(), false, MetadataManager.GetTypeOfNetType(typeof(Reference <FlowInput>)), MetadataManager.GetTypeOfNetType(typeof(FlowInput)), new Metadata.Parameter[0], false, this, "Cases", caseValue, nCase); p.Description = ""; p.Serializable = SerializeType.Enable; properties.Add(p); propertyBySignature[p.Signature] = p; } //Default { var p = new PropertyImpl(this, "Default", false, MetadataManager.GetTypeOfNetType(typeof(Reference <FlowInput>)), MetadataManager.GetTypeOfNetType(typeof(FlowInput)), new Metadata.Parameter[0], false, this, "Cases", "Default", -1); p.Description = ""; p.Serializable = SerializeType.Enable; properties.Add(p); propertyBySignature[p.Signature] = p; } }
void UpdateDefaultValue(PropertyImpl property) { property.DefaultValueSpecified = DefaultValueSpecified.Value; if (property.DefaultValueSpecified && defaultValueProperty != null) { //!!!!need check type? property.DefaultValue = ReferenceUtility.GetUnreferencedValue(defaultValueProperty.GetValue(this, null)); } else { property.DefaultValue = null; } }
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 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"); }
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 Overridden_Properties_Are_Marked_As_Inherited() { var property1 = new PropertyImpl { Name = "Prop1" }; Assert.That(property1.IsInherited, Is.False); Assert.That(property.IsOverridden, Is.False); entity.AddProperty(property1); Assert.That(property.IsOverridden, Is.True); Assert.That(property1.IsInherited, Is.True); Assert.That(entity.Properties.Count(), Is.EqualTo(2)); Assert.That(entity.Properties.Contains(property), "Parent property missing"); Assert.That(entity.Properties.Contains(property1), "Child property missing"); }
public void It_Should_Create_This() { Entity parentEntity = new EntityImpl(); 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.Null); 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 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 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 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); }