public void TestGetClass() { // Act var interfaceDefinition = new CSharpInterfaceDefinition { Namespace = "Entities", AccessModifier = AccessModifier.Public, Name = "IEntity" }; var classDefinition = new CSharpClassDefinition { Namespace = "Entities", AccessModifier = AccessModifier.Public, Name = "OrderHeader", Implements = { "Entities.IEntity" } }; // Arrange var classDef = TypeManager.GetItemByFullName(classDefinition.FullName); // Assert Assert.True(TypeManager.ObjectDefinitions.Count > 0); Assert.True(classDef != null); }
public void TestCSharpInterfaceGeneration() { // Arrange var definition = new CSharpInterfaceDefinition { Namespace = "ContactManager", Name = "IPerson", Namespaces = new List <string> { "System", "System.ComponentModel" } }; definition.Properties.Add(new PropertyDefinition("Int32?", "ID")); definition.Properties.Add(new PropertyDefinition("String", "FirstName")); definition.Properties.Add(new PropertyDefinition("String", "MiddleName")); definition.Properties.Add(new PropertyDefinition("String", "LastName")); definition.Properties.Add(new PropertyDefinition("String", "FullName") { IsReadOnly = true }); definition.Properties.Add(new PropertyDefinition("String", "Gender")); definition.Properties.Add(new PropertyDefinition("DateTime?", "BirthDate")); definition.Properties.Add(new PropertyDefinition("Int32", "Age") { IsReadOnly = true }); // Act CSharpCodeBuilder.CreateFiles("C:\\Temp\\CatFactory.DotNetCore", string.Empty, true, definition); }
private static void ScaffoldEntityInterface(this DapperProject project) { var globalSelection = project.GlobalSelection(); var interfaceDefinition = new CSharpInterfaceDefinition { Namespace = project.GetEntityLayerNamespace(), Name = "IEntity" }; CSharpCodeBuilder.CreateFiles(project.OutputDirectory, project.GetEntityLayerDirectory(), globalSelection.Settings.ForceOverwrite, interfaceDefinition); }
public static CSharpInterfaceDefinition GetResponseInterfaceDefinition(this AspNetCoreProject project) { var definition = new CSharpInterfaceDefinition(); definition.Namespaces.Add("System"); definition.Namespace = project.GetResponsesNamespace(); definition.Name = "IResponse"; definition.Properties.Add(new PropertyDefinition("String", "Message")); definition.Properties.Add(new PropertyDefinition("Boolean", "DidError")); definition.Properties.Add(new PropertyDefinition("String", "ErrorMessage")); return(definition); }
public static CSharpInterfaceDefinition GetEntityTypeConfigurationInterfaceDefinition(this EntityFrameworkCoreProject project) { var interfaceDefinition = new CSharpInterfaceDefinition(); interfaceDefinition.Namespaces.Add("Microsoft.EntityFrameworkCore"); interfaceDefinition.Namespace = project.GetDataLayerConfigurationsNamespace(); interfaceDefinition.Name = "IEntityTypeConfiguration"; interfaceDefinition.Methods.Add(new MethodDefinition("void", "Configure", new ParameterDefinition("ModelBuilder", "modelBuilder"))); return(interfaceDefinition); }
public void TestCSharpGenericInterfaceGeneration() { // Arrange var definition = new CSharpInterfaceDefinition { Namespaces = new List <string> { "System", "System.Threading.Tasks" }, Namespace = "Contracts", IsPartial = true, Name = "IGenericRepository", GenericTypes = new List <GenericTypeDefinition> { new GenericTypeDefinition { Name = "TEntity", Constraint = "TEntity : class, new()" } } }; definition.Properties.Add(new PropertyDefinition("DbContext", "DbContext") { IsReadOnly = true }); definition.Methods.Add(new MethodDefinition("Task<Int32>", "CommitChanges", new ParameterDefinition("int", "foo", "0"))); definition.Methods.Add(new MethodDefinition("Task<Int32>", "CommitChangesAsync")); definition.Methods.Add(new MethodDefinition("void", "Audit") { GenericTypes = new List <GenericTypeDefinition> { new GenericTypeDefinition { Name = "TEntity" } } }); // Act CSharpCodeBuilder.CreateFiles("C:\\Temp\\CatFactory.DotNetCore", string.Empty, true, definition); }
public static CSharpInterfaceDefinition GetRepositoryInterfaceDefinition(this EntityFrameworkCoreProject project) { var interfaceDefinition = new CSharpInterfaceDefinition(); interfaceDefinition.Namespaces.Add("System"); interfaceDefinition.Namespaces.Add("System.Threading.Tasks"); interfaceDefinition.Namespace = project.GetDataLayerContractsNamespace(); interfaceDefinition.Name = "IRepository"; interfaceDefinition.Implements.Add("IDisposable"); interfaceDefinition.Methods.Add(new MethodDefinition("Int32", "CommitChanges")); interfaceDefinition.Methods.Add(new MethodDefinition("Task<Int32>", "CommitChangesAsync")); return(interfaceDefinition); }
public static CSharpInterfaceDefinition GetAuditEntityInterfaceDefinition(this EntityFrameworkCoreProject project) { var interfaceDefinition = new CSharpInterfaceDefinition(); interfaceDefinition.Namespaces.Add("System"); interfaceDefinition.Namespace = project.GetEntityLayerNamespace(); interfaceDefinition.Name = "IAuditEntity"; interfaceDefinition.Implements.Add("IEntity"); interfaceDefinition.Properties.Add(new PropertyDefinition("String", "CreationUser")); interfaceDefinition.Properties.Add(new PropertyDefinition("DateTime?", "CreationDateTime")); interfaceDefinition.Properties.Add(new PropertyDefinition("String", "LastUpdateUser")); interfaceDefinition.Properties.Add(new PropertyDefinition("DateTime?", "LastUpdateDateTime")); return(interfaceDefinition); }
public static CSharpInterfaceDefinition GetSingleResponseInterfaceDefinition(this AspNetCoreProject project) { var definition = new CSharpInterfaceDefinition(); definition.Namespace = project.GetResponsesNamespace(); definition.Name = "ISingleResponse"; definition.GenericTypes = new List <GenericTypeDefinition> { new GenericTypeDefinition { Name = "TModel", Constraint = "TModel : class" } }; definition.Implements.Add("IResponse"); definition.Properties.Add(new PropertyDefinition("TModel", "Model")); return(definition); }
public static CSharpInterfaceDefinition GetEntityMapperInterfaceDefinition(this EntityFrameworkCoreProject project) { var interfaceDefinition = new CSharpInterfaceDefinition(); interfaceDefinition.Namespaces.Add("System.Collections.Generic"); interfaceDefinition.Namespaces.Add("Microsoft.EntityFrameworkCore"); interfaceDefinition.Namespace = project.GetDataLayerConfigurationsNamespace(); interfaceDefinition.Name = "IEntityMapper"; interfaceDefinition.Properties.Add(new PropertyDefinition("IEnumerable<IEntityTypeConfiguration>", "Configurations") { IsReadOnly = true }); interfaceDefinition.Methods.Add(new MethodDefinition("void", "ConfigureEntities", new ParameterDefinition("ModelBuilder", "modelBuilder"))); return(interfaceDefinition); }
public void ScaffoldingBaseRepositoryInterface() { // Arrange var definition = new CSharpInterfaceDefinition { Namespaces = { "System" }, Namespace = "DesignPatterns", AccessModifier = AccessModifier.Public, Name = "IRepository", Implements = { "IDisposable" } }; // Act CSharpCodeBuilder.CreateFiles(@"C:\Temp\CatFactory.NetCore\DesignPatterns", string.Empty, true, definition); }
public static CSharpInterfaceDefinition GetPagedResponseInterfaceDefinition(this AspNetCoreProject project) { var definition = new CSharpInterfaceDefinition(); definition.Namespaces.Add("System"); definition.Namespace = project.GetResponsesNamespace(); definition.Name = "PagedResponse"; definition.GenericTypes = new List <GenericTypeDefinition> { new GenericTypeDefinition { Name = "TModel", Constraint = "TModel : class" } }; definition.Implements.Add("IListResponse"); definition.Properties.Add(new PropertyDefinition("Int32", "ItemsCount")); definition.Properties.Add(new PropertyDefinition("Int32", "PageCount")); return(definition); }
public void ScaffoldingRepositoryInterface() { // Arrange var definition = new CSharpInterfaceDefinition { Namespaces = { "System", "System.Linq" }, Namespace = "DesignPatterns", Documentation = new Documentation("Contains all operations related to Northwind database access"), AccessModifier = AccessModifier.Public, Name = "INorthwindRepository", Implements = { "IRepository" }, Methods = { new MethodDefinition("IQueryable<Product>", "GetProducts") { Documentation = new Documentation("Retrieves all products"), Parameters = { new ParameterDefinition("int?", "supplierID") }, }, new MethodDefinition("IQueryable<Shipper>", "GetShippers"), new MethodDefinition("IQueryable<Order>", "GetOrders") } }; // Act CSharpCodeBuilder.CreateFiles(@"C:\Temp\CatFactory.NetCore\DesignPatterns", string.Empty, true, definition); }
private static void ScaffoldDataLayerContract(EntityFrameworkCoreProject project, CSharpInterfaceDefinition interfaceDefinition) => CSharpCodeBuilder.CreateFiles(project.OutputDirectory, project.GetDataLayerContractsDirectory(), project.Settings.ForceOverwrite, interfaceDefinition);
private static void ScaffoldDataLayerContract(DapperProject project, CSharpInterfaceDefinition interfaceDefinition) { CSharpCodeBuilder.CreateFiles(project.OutputDirectory, project.GetDataLayerContractsDirectory(), project.GlobalSelection().Settings.ForceOverwrite, interfaceDefinition); }