public void Test() { string codeText = File.ReadAllText("Resources\\BasicClass.txt"); var parser = new CSharpParser(); parser.ParseCode(codeText); var codeRoot = (CodeRoot)parser.CreatedCodeRoot; //Actions actions = Test2(codeRoot);//Test1(codeRoot); Actions actions = new Actions(); Entity entity = new EntityImpl("BasicClass"); entity.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" }); Entity entity1 = new EntityImpl("Class1"); entity1.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" }); entity.MappedClass = codeRoot.Namespaces[0].Classes[0]; entity1.MappedClass = codeRoot.Namespaces[0].Classes[1]; CheckEntity(entity, actions); codeText = actions.RunActions(codeText, codeRoot, true); actions = new Actions(); actions.AddAction(new AddAttributeToPropertyAction(entity.MappedClass.Properties[0], new Attribute(codeRoot.Controller){Name = "Attr"})); CheckEntity(entity1, actions); var output = actions.RunActions(codeText, codeRoot, false); }
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 Nothing_Is_Null() { Entity entity = new EntityImpl(); Assert.That(entity.Key, Is.Not.Null); Assert.That(entity.Properties, Is.Not.Null); Assert.That(entity.References, Is.Not.Null); }
public void Everything_Is_Empty() { Entity entity = new EntityImpl(); Assert.That(entity.Key.Properties, Is.Empty); Assert.That(entity.Properties, Is.Empty); Assert.That(entity.References, Is.Empty); }
public FormDiscriminator(EntityImpl entity) { InitializeComponent(); Entity = entity; Populate(); }
public void Delete_Does_Nothing() { // I realise this test has no asserts. I am making sure there are no // null pointer exceptions thrown. Entity entity = new EntityImpl(); entity.DeleteSelf(); }
public Entity DeserialiseEntity(XmlNode entityNode) { var entity = new EntityImpl(); entity.EventRaisingDisabled = true; entity.Name = entityNode.SelectSingleNode("Name").InnerText; entity.Schema = entityNode.SelectSingleNode("Schema").InnerText; XmlNodeList nodes = entityNode.SelectNodes("Properties/Property"); if (nodes != null) { foreach (XmlNode propertyNode in nodes) { entity.AddProperty(DeserialiseProperty(propertyNode, entity)); } } ProcessScriptBase(entity, entityNode); if (Version >= 3) { XmlNode generatorNode = entityNode.SelectSingleNode("Generator"); if (generatorNode == null) { entity.Generator = new EntityGenerator("assigned"); } else { entity.Generator = DeserialiseGenerator(generatorNode); } } if (Version > 4) { entity.Cache = DeserialiseCache(entityNode.SelectSingleNode("Cache")); } if (Version > 5) { entity.IsAbstract = bool.Parse(entityNode.SelectSingleNode("IsAbstract").InnerText); } if (Version > 6) { entity.Discriminator = DeserialiseDiscriminator(entityNode.SelectSingleNode("Discriminator")); entity.DiscriminatorValue = entityNode.SelectSingleNode("DiscriminatorValue").InnerText; } else { entity.Discriminator = new Discriminator(); } entity.EventRaisingDisabled = false; return(entity); }
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); }
private static Entity CreateEntity(EntitySet set, string entityName) { var entity = new EntityImpl(entityName); entity.AddProperty(new PropertyImpl("Property1")); entity.AddProperty(new PropertyImpl("Property2")); entity.AddProperty(new PropertyImpl("Property3")); set.AddEntity(entity); return entity; }
public void It_Should_Serialise_To_This() { const string expectedXML = FullEntityXml; Entity entity = new EntityImpl("Entity1"); entity.AddProperty(new PropertyImpl()); Entity entity2 = new EntityImpl("Entity2"); entity2.AddChild(entity); string outputXML = new EntitySetSerialisationScheme().SerialiseEntity(entity); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
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 Setup() { mappingSet = new MappingSetImpl(); entity1 = new EntityImpl("Entity1"); var entity2 = new EntityImpl("Entity2"); mapping3 = new MappingImpl { ToEntity = entity2 }; mappingSet.AddMapping(new MappingImpl { ToEntity = entity1 }); mappingSet.AddMapping(new MappingImpl { ToEntity = entity1 }); mappingSet.AddMapping(mapping3); }
public void It_Should_Create_This() { const string xml = When_Serialising_A_Property_With_All_Fields_Set.FullPropertyXml; var parentEntity = new EntityImpl(); Property prop = new EntitySetDeserialisationScheme().DeserialiseProperty(xml.GetXmlDocRoot(), parentEntity); Assert.That(prop.Entity, Is.SameAs(parentEntity)); Assert.That(prop.Name, Is.EqualTo("Property1")); Assert.That(prop.ReadOnly, Is.True); Assert.That(prop.ValidationOptions, Is.Not.Null); Assert.That(prop.Type, Is.EqualTo("SomeType")); Assert.That(prop.IsKeyProperty, Is.True); //Assert.That(prop.IsVirtual, Is.True); }
public void It_Should_Create_This() { const string xml = When_Serialising_An_Empty_Property.BasicPropertyXml; var parentEntity = new EntityImpl(); Property prop = new EntitySetDeserialisationScheme().DeserialiseProperty(xml.GetXmlDocRoot(), parentEntity); Assert.That(prop.Entity, Is.SameAs(parentEntity)); Assert.That(prop.Name, Is.EqualTo("")); Assert.That(prop.ReadOnly, Is.False); Assert.That(prop.ValidationOptions, Is.Not.Null); Assert.That(prop.Type, Is.EqualTo("object")); Assert.That(prop.IsKeyProperty, Is.False); //Assert.That(prop.IsVirtual, Is.False); }
public void It_Returns_The_EntityKey_Objects() { ProviderInfo info = new ProviderInfo(); var entity1 = new EntityImpl(); var entity2 = new EntityImpl(); info.MappingSet.EntitySet.AddEntity(entity1); info.MappingSet.EntitySet.AddEntity(entity2); IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(EntityKey)); Assert.That(objects, Has.Length(2)); Assert.That(objects.Contains(entity1.Key)); Assert.That(objects.Contains(entity2.Key)); }
public void It_Should_Create_This() { const string xml = When_Serialising_A_ComponentSpecification.BasicSpecXml; var parentEntity = new EntityImpl("Entity1"); var entitySet = new EntitySetImpl(); entitySet.AddEntity(parentEntity); ComponentSpecification spec = new EntitySetDeserialisationScheme().DeserialiseComponentSpecification(xml.GetXmlDocRoot(), entitySet); Assert.That(spec.Name, Is.EqualTo("Address")); Assert.That(spec.Properties, Has.Count(1)); Assert.That(spec.Properties[0].Name, Is.EqualTo("Street")); Assert.That(spec.ImplementedComponents, Has.Count(1)); Assert.That(spec.ImplementedComponents[0].ParentEntity, Is.SameAs(parentEntity)); }
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 The_Rule_Fails() { var set = new MappingSetImpl(); var emptyEntity = new EntityImpl(""); set.EntitySet.AddEntity(emptyEntity); 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(emptyEntity)); StringAssert.Contains("name", issue.Description); }
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 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 Setup() { database = new Database("Db1"); entitySet = new EntitySetImpl(); table = new Table("Table1"); table.AddColumn(new Column("Column1")); entity1 = new EntityImpl("Entity1"); entity1.AddProperty(new PropertyImpl("Property1")); entity2 = new EntityImpl("Entity2"); entity2.AddProperty(new PropertyImpl("Property2")); var reference = entity1.CreateReferenceTo(entity2); reference.Identifier = new Guid("11111111-1111-1111-1111-111111111111"); reference.End1Name = "end1"; reference.End2Name = "end2"; entitySet.AddReference(reference); database.AddTable(table); entitySet.AddEntity(entity1); }
public void The_Rule_Fails() { var set = new MappingSetImpl(); var entity1 = new EntityImpl("Entity1"); var entity2 = new EntityImpl("Entity2"); set.EntitySet.AddEntity(entity1); set.EntitySet.AddEntity(entity2); entity1.AddProperty(new PropertyImpl("Property1")); var reference = entity1.CreateReferenceTo(entity2); reference.End1Name = "Property1"; 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(reference)); StringAssert.Contains("Property1", issue.Description); }
public void All_Its_References_Are_Deleted() { EntitySet entitySet = new EntitySetImpl(); Entity entity1 = new EntityImpl("Table1"); Entity entity2 = new EntityImpl("Table2"); entitySet.AddEntity(entity1); entitySet.AddEntity(entity2); entity1.CreateReferenceTo(entity2); Assert.That(entity2.References.Count(), Is.EqualTo(1)); Assert.That(entitySet.Entities.Count(), Is.EqualTo(2)); entity1.DeleteSelf(); Assert.That(entitySet.Entities.Count(), Is.EqualTo(1)); Assert.That(entitySet.Entities.ElementAt(0), Is.SameAs(entity2)); Assert.That(entity2.References.Count, Is.EqualTo(0)); }
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 It_Should_Deserialise_To_This() { const string xml = Specs_For_Serialisation_Of_Entities.When_Serialising_An_Entity_With_All_Fields_Set.FullEntityXml; var scheme = new EntitySetDeserialisationScheme(); XmlNode root = xml.GetXmlDocRoot(); Entity entity = scheme.DeserialiseEntity(root); Entity entity2 = new EntityImpl("Entity2"); EntitySet entitySet = new EntitySetImpl(); entitySet.AddEntity(entity); entitySet.AddEntity(entity2); scheme.PostProcessEntity(entitySet, null, entity, root); Assert.That(entity.Name, Is.EqualTo("Entity1")); Assert.That(entity.Key, Is.Not.Null); // Don't both checking the contents of the Properties collection, // as long as it had something added to it. The tests on deserialising // properties will catch most bugs. Assert.That(entity.Properties, Is.Not.Empty); Assert.That(entity.Discriminator, Is.Not.Null, "The deserialisation of the Discriminator should happen in the post process step."); Assert.That(entity.HasParent, Is.True); Assert.That(entity.Parent, Is.SameAs(entity2)); }
public void It_Should_Serialise_To_This() { XmlNode root = When_Serialising_A_Discriminator_With_One_Condition.FullDiscriminatorXml.GetXmlDocRoot(); Entity entity = new EntityImpl("Entity1"); var column = new Column("Column1"); Table table = new Table("Table1"); table.AddColumn(column); var database = new Database("db1"); database.AddTable(table); var dis = new EntitySetDeserialisationScheme().DeserialiseDiscriminator(root, database); Assert.That(dis, Is.Not.Null); Assert.That(dis.RootGrouping, Is.Not.Null); Assert.That(dis.RootGrouping.ContainsConditions, Is.True); Assert.That(dis.RootGrouping.ContainsGroupings, Is.False); var condition = dis.RootGrouping.Conditions.ElementAt(0); Assert.That(condition.Column, Is.SameAs(column)); Assert.That(condition.Operator, Is.SameAs(Operator.Equal)); Assert.That(condition.ExpressionValue.Value, Is.EqualTo("5")); }
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 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 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"); }