private static DatabaseSchema PrepareModel() { var schema = new DatabaseSchema(null, null); schema.AddTable("Categories") .AddColumn("CategoryId", DbType.Int32).AddPrimaryKey() .AddColumn("CategoryName", DbType.String); var view = new DatabaseView { Name = "AlphabeticCategories"}; schema.Views.Add(view); view .AddColumn("CategoryId", DbType.Int32) .AddColumn("CategoryName", DbType.String); DatabaseSchemaFixer.UpdateReferences(schema); PrepareSchemaNames.Prepare(schema, new Namer()); return schema; }
private static DatabaseSchema PrepareModel() { var schema = new DatabaseSchema(null, null); schema.AddTable("Categories") .AddColumn("CategoryId", DbType.Int32).AddPrimaryKey() .AddColumn("CategoryName", DbType.String); schema.AddTable("Products") .AddColumn("ProductId", DbType.Int32).AddPrimaryKey() .AddColumn("ProductName", DbType.String) .AddColumn("CategoryId", DbType.Int32).AddForeignKey("fk", "Categories"); var view = new DatabaseView { Name = "ActiveCategories" }; view.AddColumn<string>("CategoryName"); schema.Views.Add(view); DatabaseSchemaFixer.UpdateReferences(schema); return schema; }
public void WriteViewTest() { //arrange var view = new DatabaseView(); view.Name = "AlphabeticNames"; view.AddColumn("FirstName", typeof(string)).AddNullable() .AddColumn("LastName", typeof(string)).AddNullable(); var schema = new DatabaseSchema(null, null); schema.Views.Add(view); PrepareSchemaNames.Prepare(schema, new Namer()); var codeWriterSettings = new CodeWriterSettings { CodeTarget = CodeTarget.PocoNHibernateHbm, IncludeViews = true }; var cw = new ClassWriter(view, codeWriterSettings); //act var txt = cw.Write(); //assert var hasFirstName = txt.Contains("public virtual string FirstName"); var hasLastName = txt.Contains("public virtual string LastName"); var hasEquals = txt.Contains("public override bool Equals(object obj)"); Assert.IsTrue(hasFirstName); Assert.IsTrue(hasLastName); Assert.IsTrue(hasEquals); }