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 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);
        }