public static void CreateCommand(string solutionDirectory, string srcDirectory, Entity entity, string contextName, string projectBaseName, Feature feature, IFileSystem fileSystem) { var classPath = ClassPathHelper.FeaturesClassPath(srcDirectory, $"{feature.Name}.cs", entity.Plural, projectBaseName); var fileText = GetCommandFileText(classPath.ClassNamespace, entity, contextName, solutionDirectory, srcDirectory, feature, projectBaseName); Utilities.CreateFile(classPath, fileText, fileSystem); }
private static string WriteTestFileText(string solutionDirectory, string testDirectory, string srcDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.UpdateEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var commandName = Utilities.CommandUpdateName(entity.Name); var fakeEntity = Utilities.FakerName(entity.Name); var fakeUpdateDto = Utilities.FakerName(Utilities.GetDtoName(entity.Name, Dto.Update)); var fakeCreationDto = Utilities.FakerName(Utilities.GetDtoName(entity.Name, Dto.Creation)); var updateDto = Utilities.GetDtoName(entity.Name, Dto.Update); var fakeEntityVariableName = $"fake{entity.Name}One"; var lowercaseEntityName = entity.Name.LowercaseFirstLetter(); var lowercaseEntityPluralName = entity.Plural.LowercaseFirstLetter(); var pkName = Entity.PrimaryKeyProperty.Name; var lowercaseEntityPk = pkName.LowercaseFirstLetter(); var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(testDirectory, projectBaseName, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(testDirectory, "", entity.Name, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(srcDirectory, featureName, entity.Plural, projectBaseName); var fakeParent = Utilities.FakeParentTestHelpers(entity, out var fakeParentIdRuleFor); var foreignEntityUsings = Utilities.GetForeignEntityUsings(testDirectory, entity, projectBaseName); return(@$ "namespace {classPath.ClassNamespace}; using {fakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using FluentAssertions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using Microsoft.AspNetCore.JsonPatch; using {featuresClassPath.ClassNamespace}; using static {testFixtureName};{foreignEntityUsings}
public static void CreateCommand(string solutionDirectory, Entity entity, string contextName, string projectBaseName) { try { var classPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, $"{Utilities.UpdateEntityFeatureClassName(entity.Name)}.cs", entity.Plural, projectBaseName); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { throw new FileAlreadyExistsException(classPath.FullClassPath); } using (FileStream fs = File.Create(classPath.FullClassPath)) { var data = ""; data = GetCommandFileText(classPath.ClassNamespace, entity, contextName, solutionDirectory, projectBaseName); fs.Write(Encoding.UTF8.GetBytes(data)); } } catch (FileAlreadyExistsException e) { WriteError(e.Message); throw; } catch (Exception e) { WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}"); throw; } }
private static string WriteTestFileText(string solutionDirectory, string testDirectory, string srcDirectory, ClassPath classPath, Entity entity, Feature feature, string projectBaseName) { var featureName = Utilities.AddEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var commandName = feature.Command; var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(testDirectory, projectBaseName, ""); var dtoUtilClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(testDirectory, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(testDirectory, "", entity.Name, projectBaseName); var parentFakerClassPath = ClassPathHelper.TestFakesClassPath(testDirectory, "", feature.ParentEntity, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(srcDirectory, featureName, entity.Plural, projectBaseName); var foreignEntityUsings = Utilities.GetForeignEntityUsings(testDirectory, entity, projectBaseName); return(@$ "namespace {classPath.ClassNamespace}; using {dtoUtilClassPath.ClassNamespace}; using {fakerClassPath.ClassNamespace}; using {parentFakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using {featuresClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using FluentAssertions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using static {testFixtureName};{foreignEntityUsings}
private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.GetEntityListFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var fakerClassPath = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, featureName, entity.Plural, projectBaseName); var sortTests = ""; var filterTests = ""; foreach (var prop in entity.Properties.Where(e => e.CanSort && e.Type != "Guid").ToList()) { sortTests += GetEntitiesListSortedInAscOrder(entity, prop); sortTests += GetEntitiesListSortedInDescOrder(entity, prop); } foreach (var prop in entity.Properties.Where(e => e.CanFilter).ToList()) { filterTests += GetEntitiesListFiltered(entity, prop); } return(@$ "namespace {classPath.ClassNamespace} {{ using {dtoClassPath.ClassNamespace}; using {fakerClassPath.ClassNamespace}; using FluentAssertions; using NUnit.Framework; using System; using System.Linq; using System.Threading.Tasks; using static {featuresClassPath.ClassNamespace}.{featureName};
private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.DeleteEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var commandName = Utilities.CommandDeleteName(entity.Name); var fakeEntity = Utilities.FakerName(entity.Name); var fakeEntityVariableName = $"fake{entity.Name}One"; var lowercaseEntityName = entity.Name.LowercaseFirstLetter(); var lowercaseEntityPluralName = entity.Plural.LowercaseFirstLetter(); var pkName = entity.PrimaryKeyProperty.Name; var lowercaseEntityPk = pkName.LowercaseFirstLetter(); var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(solutionDirectory, projectBaseName, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, featureName, entity.Plural, projectBaseName); return(@$ "namespace {classPath.ClassNamespace} {{ using {fakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using FluentAssertions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using static {featuresClassPath.ClassNamespace}.{featureName};
public static string GetControllerFileText(string classNamespace, string entityName, string entityPlural, string solutionDirectory, string srcDirectory, string projectBaseName, bool usesJwtAuth) { // TODO create an attribute factory that can order them how i want and work more dynamically var endpointBase = Utilities.EndpointBaseGenerator(entityPlural); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entityName, projectBaseName); var wrapperClassPath = ClassPathHelper.WrappersClassPath(srcDirectory, "", projectBaseName); var featureClassPath = ClassPathHelper.FeaturesClassPath(srcDirectory, "", entityPlural, projectBaseName); var permissionsClassPath = ClassPathHelper.PolicyDomainClassPath(srcDirectory, "", projectBaseName); var rolesClassPath = ClassPathHelper.SharedKernelDomainClassPath(solutionDirectory, ""); var permissionsUsing = usesJwtAuth ? @$ "{Environment.NewLine}using {permissionsClassPath.ClassNamespace}; using {rolesClassPath.ClassNamespace};"
public static string GetControllerFileText(string classNamespace, Entity entity, bool AddSwaggerComments, List <Policy> policies, string solutionDirectory, string projectBaseName) { var lowercaseEntityVariable = entity.Name.LowercaseFirstLetter(); var entityName = entity.Name; var entityNamePlural = entity.Plural; var readDto = Utilities.GetDtoName(entityName, Dto.Read); var readParamDto = Utilities.GetDtoName(entityName, Dto.ReadParamaters); var creationDto = Utilities.GetDtoName(entityName, Dto.Creation); var updateDto = Utilities.GetDtoName(entityName, Dto.Update); var primaryKeyProp = entity.PrimaryKeyProperty; var queryListMethodName = Utilities.QueryListName(entityName); var queryRecordMethodName = Utilities.QueryRecordName(entityName); var addRecordCommandMethodName = Utilities.CommandAddName(entityName); var deleteRecordCommandMethodName = Utilities.CommandDeleteName(entityName); var updateRecordCommandMethodName = Utilities.CommandUpdateName(entityName); var patchRecordCommandMethodName = Utilities.CommandPatchName(entityName); var pkPropertyType = primaryKeyProp.Type; var listResponse = $@"Response<IEnumerable<{readDto}>>"; var singleResponse = $@"Response<{readDto}>"; var getListEndpointName = entity.Name == entity.Plural ? $@"Get{entityNamePlural}List" : $@"Get{entityNamePlural}"; var getRecordEndpointName = entity.Name == entity.Plural ? $@"Get{entityNamePlural}Record" : $@"Get{entity.Name}"; var endpointBase = Utilities.EndpointBaseGenerator(entityNamePlural); var getListAuthorizations = BuildAuthorizations(policies, Endpoint.GetList, entity.Name); var getRecordAuthorizations = BuildAuthorizations(policies, Endpoint.GetRecord, entity.Name); var addRecordAuthorizations = BuildAuthorizations(policies, Endpoint.AddRecord, entity.Name); var updateRecordAuthorizations = BuildAuthorizations(policies, Endpoint.UpdateRecord, entity.Name); var updatePartialAuthorizations = BuildAuthorizations(policies, Endpoint.UpdatePartial, entity.Name); var deleteRecordAuthorizations = BuildAuthorizations(policies, Endpoint.DeleteRecord, entity.Name); var idParam = $@"{lowercaseEntityVariable}Id"; var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entityName, projectBaseName); var wrapperClassPath = ClassPathHelper.WrappersClassPath(solutionDirectory, "", projectBaseName); var featureClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, "", entity.Plural, projectBaseName); return(@$ "namespace {classNamespace} {{ using System; using System.Collections.Generic; using System.Text.Json; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using System.Threading.Tasks; using {dtoClassPath.ClassNamespace}; using {wrapperClassPath.ClassNamespace}; using System.Threading; using MediatR; using static {featureClassPath.ClassNamespace}.{Utilities.GetEntityListFeatureClassName(entity.Name)};
private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.PatchEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var commandName = Utilities.CommandPatchName(entity.Name); var fakeEntity = Utilities.FakerName(entity.Name); var updateDto = Utilities.GetDtoName(entity.Name, Dto.Update); var fakeEntityVariableName = $"fake{entity.Name}One"; var lowercaseEntityName = entity.Name.LowercaseFirstLetter(); var lowercaseEntityPluralName = entity.Plural.LowercaseFirstLetter(); var pkName = entity.PrimaryKeyProperty.Name; var lowercaseEntityPk = pkName.LowercaseFirstLetter(); var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(solutionDirectory, projectBaseName, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, featureName, entity.Plural, projectBaseName); var myProp = entity.Properties.Where(e => e.Type == "string" && e.CanManipulate).FirstOrDefault(); var lookupVal = $@"""Easily Identified Value For Test"""; // if no string properties, do one with an int if (myProp == null) { myProp = entity.Properties.Where(e => e.Type.Contains("int") && e.CanManipulate).FirstOrDefault(); lookupVal = "999999"; } if (myProp == null) { return("// no patch tests were created"); } return(@$ "namespace {classPath.ClassNamespace} {{ using {fakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using FluentAssertions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using Microsoft.AspNetCore.JsonPatch; using System.Linq; using static {featuresClassPath.ClassNamespace}.{featureName};
private static string WriteTestFileText(string solutionDirectory, string testDirectory, string srcDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.PatchEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var commandName = Utilities.CommandPatchName(entity.Name); var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(testDirectory, projectBaseName, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(testDirectory, "", entity.Name, projectBaseName); var exceptionClassPath = ClassPathHelper.ExceptionsClassPath(testDirectory, ""); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(srcDirectory, featureName, entity.Plural, projectBaseName); var myProp = entity.Properties.Where(e => e.Type == "string" && e.CanManipulate).FirstOrDefault(); var lookupVal = $@"""Easily Identified Value For Test"""; // if no string properties, do one with an int if (myProp == null) { myProp = entity.Properties.Where(e => e.Type.Contains("int") && e.CanManipulate).FirstOrDefault(); lookupVal = "999999"; } if (myProp == null) { return("// no patch tests were created"); } var foreignEntityUsings = Utilities.GetForeignEntityUsings(testDirectory, entity, projectBaseName); return(@$ "namespace {classPath.ClassNamespace}; using {fakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionClassPath.ClassNamespace}; using {featuresClassPath.ClassNamespace}; using FluentAssertions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using Microsoft.AspNetCore.JsonPatch; using static {testFixtureName};{foreignEntityUsings}
public static void CreateCommand(string srcDirectory, string contextName, string projectBaseName, Feature newFeature) { var classPath = ClassPathHelper.FeaturesClassPath(srcDirectory, $"{newFeature.Name}.cs", newFeature.EntityPlural, projectBaseName); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { throw new FileAlreadyExistsException(classPath.FullClassPath); } using FileStream fs = File.Create(classPath.FullClassPath); var data = ""; data = GetCommandFileText(classPath.ClassNamespace, contextName, srcDirectory, projectBaseName, newFeature); fs.Write(Encoding.UTF8.GetBytes(data)); }
public static void CreateQuery(string solutionDirectory, string srcDirectory, Entity entity, string contextName, string projectBaseName) { var classPath = ClassPathHelper.FeaturesClassPath(srcDirectory, $"{Utilities.GetEntityFeatureClassName(entity.Name)}.cs", entity.Plural, projectBaseName); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { throw new FileAlreadyExistsException(classPath.FullClassPath); } using (FileStream fs = File.Create(classPath.FullClassPath)) { var data = ""; data = GetQueryFileText(classPath.ClassNamespace, entity, contextName, solutionDirectory, srcDirectory, projectBaseName); fs.Write(Encoding.UTF8.GetBytes(data)); } }
private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, string projectBaseName) { var featureName = Utilities.GetEntityFeatureClassName(entity.Name); var testFixtureName = Utilities.GetIntegrationTestFixtureName(); var queryName = Utilities.QueryRecordName(entity.Name); var testUtilClassPath = ClassPathHelper.IntegrationTestUtilitiesClassPath(solutionDirectory, projectBaseName, ""); var fakerClassPath = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName); var featuresClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, featureName, entity.Plural, projectBaseName); return(@$ "namespace {classPath.ClassNamespace}; using {fakerClassPath.ClassNamespace}; using {testUtilClassPath.ClassNamespace}; using FluentAssertions; using Exceptions; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System.Threading.Tasks; using {featuresClassPath.ClassNamespace}; using static {testFixtureName};
public static string GetControllerFileText(string classNamespace, string entityName, string entityPlural, string solutionDirectory, string projectBaseName) { // TODO create an attribute factory that can order them how i want and work more dynamically var endpointBase = Utilities.EndpointBaseGenerator(entityPlural); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entityName, projectBaseName); var wrapperClassPath = ClassPathHelper.WrappersClassPath(solutionDirectory, "", projectBaseName); var featureClassPath = ClassPathHelper.FeaturesClassPath(solutionDirectory, "", entityPlural, projectBaseName); return(@$ "namespace {classNamespace}; using {featureClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {wrapperClassPath.ClassNamespace}; using System.Text.Json; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using System.Threading.Tasks; using System.Threading; using MediatR;