public void create_mapper_property_for_nullable_int_column() { // Arrange IColumns columns = new CategoryColumns(); columns.Add(new ViewCountIntNullableColumn()); ITable table = new CategoryTable(columns, null); string expected = "model.ViewCount = entity.ViewCount.HasValue ? (int)entity.ViewCount : default(int);"; // Act string actual = string.Empty; foreach (IColumn c in table.Columns) { actual = "model." + c.Name + " = entity." + c.Name; if (c.LanguageType.ToLower() != "string") { if (c.IsNullable) { actual += ".HasValue ? (" + c.LanguageType + ")entity." + c.Name + " : default(" + c.LanguageType + ")"; } } actual += ";"; } // Assert Assert.AreEqual(expected, actual); }
public void create_mapper_property_for_nullable_datetime_column() { // Arrange IColumns columns = new CategoryColumns(); columns.Add(new DateTimeNullableColumn()); ITable table = new CategoryTable(columns, null); string expected = "model.DateCreated = entity.DateCreated.HasValue ? (DateTime)entity.DateCreated : default(DateTime)"; // Act string actual = string.Empty; foreach (IColumn c in table.Columns) { if (c.LanguageType.ToLower() != "string") { if (c.IsNullable) { actual = "model." + c.Name + " = entity." + c.Name + ".HasValue ? (DateTime)entity.DateCreated : default(DateTime)"; } } } // Assert Assert.AreEqual(expected, actual); }
public void dataannotationswriter_test() { // Arrange IColumns columns = new CategoryColumns(); columns.Add(new IdentityColumn()); columns.Add(new DateTimeColumn()); columns.Add(new CategoryNameColumn()); columns.Add(new RowversionColumn()); ITable table = new CategoryTable(columns, null); RequestContext context = new RequestContext(); context.Zeus = new TempZeusContext(); // Act ICodeWriter writer = new DataAnnotationsWriter(context, table); writer.Write(); string actual = writer.Read; Console.WriteLine(actual); }
public void TestMethod1() { // Arrange ITable table = null; IColumns columns = new CategoryColumns(); columns.Add(new IdentityColumn(table)); columns.Add(new DateTimeColumn(table)); columns.Add(new CategoryNameColumn(table)); table = new CategoryTable(columns, null); RequestContext context = new RequestContext(); context.Zeus = new TempZeusContext(); //context.ScriptSettings = new ScriptSettings(null, null, null, null); Condor.Core.Property prop = null; foreach (IColumn c in table.Columns) { prop = new BusinessObjectsPropertyRenderDataAnnotationsForDbContext(c, context); prop.Render(); } }
public void create_complete_mapper_for_category_table_with_nullable_datetime_column() { // Arrange IColumns columns = new CategoryColumns(); columns.Add(new DateTimeNullableColumn()); ITable table = new CategoryTable(columns, null); string expected = "model.Id = (int)entity.Id;" + Environment.NewLine; expected += "model.CategoryName = entity.CategoryName;" + Environment.NewLine; expected += "model.rowversion = entity.Rowversion.AsBase64String();" + Environment.NewLine; expected += "model.DateCreated = entity.DateCreated.HasValue ? (DateTime)entity.DateCreated : default(DateTime);" + Environment.NewLine; // Act string actual = string.Empty; foreach (IColumn c in table.Columns) { if (c.IsInPrimaryKey) { actual += "model." + c.Name + " = (int)entity." + c.Name + ";" + Environment.NewLine; } else if (c.Name.ToLower() == "rowversion") { actual += "model." + c.Name.ToLower() + " = entity." + c.Name + ".AsBase64String();" + Environment.NewLine; } else { actual += "model." + c.Name + " = entity." + c.Name; if (c.LanguageType.ToLower() != "string") { if (c.IsNullable) { actual += ".HasValue ? (" + c.LanguageType + ")entity." + c.Name + " : default(" + c.LanguageType + ")"; } } actual += ";" + Environment.NewLine; } } // Assert Assert.AreEqual(expected, actual); }
public void create_complete_mapper_for_category_table() { // Arrange IColumns columns = new CategoryColumns(); columns.Add(new DateTimeColumn()); ITable table = new CategoryTable(columns, null); string expected = "model.Id = (int)entity.Id;" + Environment.NewLine; expected += "model.CategoryName = entity.CategoryName;" + Environment.NewLine; expected += "model.rowversion = entity.Rowversion.AsBase64String();" + Environment.NewLine; expected += "model.DateCreated = entity.DateCreated;" + Environment.NewLine; // Act string actual = string.Empty; foreach (IColumn c in table.Columns) { if (c.IsInPrimaryKey) { actual += "model." + c.Name + " = (int)entity." + c.Name + ";" + Environment.NewLine; } else if (c.Name.ToLower() == "rowversion") { actual += "model." + c.Name.ToLower() + " = entity." + c.Name + ".AsBase64String();" + Environment.NewLine; } else { actual += "model." + c.Name + " = entity." + c.Name; if (c.LanguageType.ToLower() != "string") { if (c.IsNullable) { actual += ".HasValue ? (" + c.LanguageType + ")entity." + c.Name + " : default(" + c.LanguageType + ")"; } } actual += ";" + Environment.NewLine; } } // Assert Assert.AreEqual(expected, actual); }