public static string GetQueryFileText(string classNamespace, Entity entity, string contextName, string solutionDirectory, string srcDirectory, string projectBaseName) { var className = Utilities.GetEntityFeatureClassName(entity.Name); var queryRecordName = Utilities.QueryRecordName(entity.Name); var readDto = Utilities.GetDtoName(entity.Name, Dto.Read); var primaryKeyPropType = Entity.PrimaryKeyProperty.Type; var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var primaryKeyPropNameLowercase = primaryKeyPropName.LowercaseFirstLetter(); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, ""); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); return(@$ "namespace {classNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks;
public static string GetCommandFileText(string classNamespace, Entity entity, string contextName, string solutionDirectory, string srcDirectory, Feature feature, string projectBaseName) { var className = feature.Name; var addCommandName = feature.Command; var readDto = Utilities.GetDtoName(entity.Name, Dto.Read); readDto = $"IEnumerable<{readDto}>"; var createDto = Utilities.GetDtoName(entity.Name, Dto.Creation); createDto = $"IEnumerable<{createDto}>"; var featurePropNameLowerFirst = feature.BatchPropertyName.LowercaseFirstLetter(); var entityName = entity.Name; var entityNameLowercase = entity.Name.LowercaseFirstLetter(); var entityNameLowercaseListVar = $"{entity.Name.LowercaseFirstLetter()}List"; var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var commandProp = $"{entityName}ListToAdd"; var newEntityProp = $"{entityNameLowercaseListVar}ListToAdd"; var entityClassPath = ClassPathHelper.EntityClassPath(srcDirectory, "", entity.Plural, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, ""); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); var validatorsClassPath = ClassPathHelper.ValidationClassPath(srcDirectory, "", entity.Plural, projectBaseName); var batchFkCheck = !string.IsNullOrEmpty(feature.BatchPropertyDbSetName) ? @$ "var fkEntity = await _db.{feature.BatchPropertyDbSetName}.Where(x => x.Id == request.{feature.BatchPropertyName}).FirstOrDefaultAsync(cancellationToken); if (fkEntity == null) throw new NotFoundException($" "No {feature.BatchPropertyName} found with an id of '{{request.{feature.BatchPropertyName}}}'" ");{Environment.NewLine}{Environment.NewLine}"
public static string GetCommandFileText(string classNamespace, Entity entity, string contextName, string srcDirectory, string projectBaseName) { var className = Utilities.PatchEntityFeatureClassName(entity.Name); var patchCommandName = Utilities.CommandPatchName(entity.Name); var updateDto = Utilities.GetDtoName(entity.Name, Dto.Update); var manipulationValidator = Utilities.ValidatorNameGenerator(entity.Name, Validator.Manipulation); var primaryKeyPropType = Entity.PrimaryKeyProperty.Type; var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var entityNameLowercase = entity.Name.LowercaseFirstLetter(); var updatedEntityProp = $"{entityNameLowercase}ToUpdate"; var patchedEntityProp = $"{entityNameLowercase}ToPatch"; var entityClassPath = ClassPathHelper.EntityClassPath(srcDirectory, "", entity.Plural, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(srcDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, "", projectBaseName); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); var validatorsClassPath = ClassPathHelper.ValidationClassPath(srcDirectory, "", entity.Plural, projectBaseName); return(@$ "namespace {classNamespace}; using {entityClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using {validatorsClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using FluentValidation.Results; using MediatR; using Microsoft.AspNetCore.JsonPatch; using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks;
public static string GetCommandFileText(string classNamespace, string contextName, string srcDirectory, string projectBaseName, Feature newFeature) { var featureClassName = newFeature.Name; var commandName = newFeature.Command; var returnPropType = newFeature.ResponseType; var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, "", projectBaseName); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); var returnValue = GetReturnValue(returnPropType); var handlerCtor = $@"private readonly {contextName} _db; private readonly IMapper _mapper; public Handler({contextName} db, IMapper mapper) {{ _mapper = mapper; _db = db; }}"; return(@$ "namespace {classNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; using Microsoft.EntityFrameworkCore; using System; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic;
public static string GetQueryFileText(string classNamespace, Entity entity, string contextName, string solutionDirectory, string projectBaseName) { var className = Utilities.GetEntityListFeatureClassName(entity.Name); var queryListName = Utilities.QueryListName(entity.Name); var readDto = Utilities.GetDtoName(entity.Name, Dto.Read); var paramsDto = Utilities.GetDtoName(entity.Name, Dto.ReadParamaters); var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var entityClassPath = ClassPathHelper.EntityClassPath(solutionDirectory, "", entity.Plural, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(solutionDirectory, "", projectBaseName); var contextClassPath = ClassPathHelper.DbContextClassPath(solutionDirectory, "", projectBaseName); var wrapperClassPath = ClassPathHelper.WrappersClassPath(solutionDirectory, "", projectBaseName); return(@$ "namespace {classNamespace}; using {entityClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using {wrapperClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; using Sieve.Models; using Sieve.Services; using System.Threading; using System.Threading.Tasks;
public static string GetCommandFileText(string classNamespace, Entity entity, string contextName, string solutionDirectory, string srcDirectory, string projectBaseName) { var className = Utilities.AddEntityFeatureClassName(entity.Name); var addCommandName = Utilities.CommandAddName(entity.Name); var readDto = Utilities.GetDtoName(entity.Name, Dto.Read); var createDto = Utilities.GetDtoName(entity.Name, Dto.Creation); var manipulationValidator = Utilities.ValidatorNameGenerator(entity.Name, Validator.Manipulation); var entityName = entity.Name; var entityNameLowercase = entity.Name.LowercaseFirstLetter(); var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var commandProp = $"{entityName}ToAdd"; var newEntityProp = $"{entityNameLowercase}ToAdd"; var entityClassPath = ClassPathHelper.EntityClassPath(srcDirectory, "", entity.Plural, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, ""); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); var validatorsClassPath = ClassPathHelper.ValidationClassPath(srcDirectory, "", entity.Plural, projectBaseName); return(@$ "namespace {classNamespace}; using {entityClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using {validatorsClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks;
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 queryName = Utilities.QueryListName(entity.Name); var exceptionClassPath = ClassPathHelper.ExceptionsClassPath(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 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 {exceptionClassPath.ClassNamespace}; using {featuresClassPath.ClassNamespace}; using FluentAssertions; using NUnit.Framework; using System.Threading.Tasks; using static {testFixtureName};
public static string GetCommandFileText(string classNamespace, Entity entity, string contextName, string srcDirectory, string projectBaseName) { var className = Utilities.DeleteEntityFeatureClassName(entity.Name); var deleteCommandName = Utilities.CommandDeleteName(entity.Name); var primaryKeyPropType = Entity.PrimaryKeyProperty.Type; var primaryKeyPropName = Entity.PrimaryKeyProperty.Name; var entityNameLowercase = entity.Name.LowercaseFirstLetter(); var entityClassPath = ClassPathHelper.EntityClassPath(srcDirectory, "", entity.Plural, projectBaseName); var dtoClassPath = ClassPathHelper.DtoClassPath(srcDirectory, "", entity.Name, projectBaseName); var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, "", projectBaseName); var contextClassPath = ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName); return(@$ "namespace {classNamespace}; using {entityClassPath.ClassNamespace}; using {dtoClassPath.ClassNamespace}; using {exceptionsClassPath.ClassNamespace}; using {contextClassPath.ClassNamespace}; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks;
public static void CreateExceptions(string solutionDirectory, string projectBaseName, IFileSystem fileSystem) { var classPath = ClassPathHelper.ExceptionsClassPath(solutionDirectory, ""); if (!Directory.Exists(classPath.ClassDirectory)) Directory.CreateDirectory(classPath.ClassDirectory); CreateNotFoundException(solutionDirectory, projectBaseName, fileSystem); CreateValidationException(solutionDirectory, projectBaseName, fileSystem); CreateForbiddenException(solutionDirectory, projectBaseName, fileSystem); }
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}
private static void BuildWebApiProject(string solutionDirectory, string srcDirectory, string projectBaseName, bool useJwtAuth, string dbProvider, string dbName, IFileSystem fileSystem) { var solutionFolder = srcDirectory.GetSolutionFolder(solutionDirectory); var webApiProjectClassPath = ClassPathHelper.WebApiProjectClassPath(srcDirectory, projectBaseName); WebApiCsProjBuilder.CreateWebApiCsProj(srcDirectory, projectBaseName, dbProvider); Utilities.ExecuteProcess("dotnet", $@"sln add ""{webApiProjectClassPath.FullClassPath}"" --solution-folder {solutionFolder}", solutionDirectory); // base folders Directory.CreateDirectory(ClassPathHelper.ControllerClassPath(srcDirectory, "", projectBaseName, "v1").ClassDirectory); Directory.CreateDirectory(ClassPathHelper.WebApiServiceExtensionsClassPath(srcDirectory, "", projectBaseName).ClassDirectory); Directory.CreateDirectory(ClassPathHelper.WebApiMiddlewareClassPath(srcDirectory, "", projectBaseName).ClassDirectory); // additional from what was other projects Directory.CreateDirectory(ClassPathHelper.DtoClassPath(solutionDirectory, "", "", projectBaseName).ClassDirectory); Directory.CreateDirectory(ClassPathHelper.ExceptionsClassPath(srcDirectory, "").ClassDirectory); Directory.CreateDirectory(ClassPathHelper.WrappersClassPath(srcDirectory, "", projectBaseName).ClassDirectory); Directory.CreateDirectory(ClassPathHelper.SharedDtoClassPath(solutionDirectory, "").ClassDirectory); Directory.CreateDirectory(ClassPathHelper.DbContextClassPath(srcDirectory, "", projectBaseName).ClassDirectory); Directory.CreateDirectory(ClassPathHelper.DummySeederClassPath(srcDirectory, "", projectBaseName).ClassDirectory); WebApiServiceExtensionsBuilder.CreateApiVersioningServiceExtension(srcDirectory, projectBaseName, fileSystem); WebApiServiceExtensionsBuilder.CreateCorsServiceExtension(srcDirectory, projectBaseName, fileSystem); WebApiServiceExtensionsBuilder.CreateWebApiServiceExtension(srcDirectory, projectBaseName, fileSystem); ErrorHandlerFilterAttributeBuilder.CreateErrorHandlerFilterAttribute(srcDirectory, projectBaseName, fileSystem); AppSettingsBuilder.CreateWebApiAppSettings(srcDirectory, dbName, projectBaseName); WebApiLaunchSettingsBuilder.CreateLaunchSettings(srcDirectory, projectBaseName, fileSystem); ProgramBuilder.CreateWebApiProgram(srcDirectory, projectBaseName, fileSystem); StartupBuilder.CreateWebApiStartup(srcDirectory, useJwtAuth, projectBaseName, fileSystem); LocalConfigBuilder.CreateLocalConfig(srcDirectory, projectBaseName, fileSystem); LoggingConfigurationBuilder.CreateConfigFile(srcDirectory, projectBaseName, fileSystem); InfrastructureServiceRegistrationBuilder.CreateInfrastructureServiceExtension(srcDirectory, projectBaseName, fileSystem); BasePaginationParametersBuilder.CreateBasePaginationParameters(solutionDirectory, projectBaseName, fileSystem); PagedListBuilder.CreatePagedList(srcDirectory, projectBaseName, fileSystem); CoreExceptionsBuilder.CreateExceptions(solutionDirectory, projectBaseName, fileSystem); Utilities.AddProjectReference(webApiProjectClassPath, @"..\..\..\SharedKernel\SharedKernel.csproj"); }
public static void CreateForbiddenException(string solutionDirectory, string projectBaseName, IFileSystem fileSystem) { var classPath = ClassPathHelper.ExceptionsClassPath(solutionDirectory, $"ForbiddenException.cs"); var fileText = GetForbiddenExceptionFileText(classPath.ClassNamespace); Utilities.CreateFile(classPath, fileText, fileSystem); }
public static string GetErrorHandlerFilterAttributeText(string srcDirectory, string projectBaseName, string classNamespace) { var exceptionsClassPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, ""); return(@$ "// source: https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/WebUI/Filters/ApiExceptionFilterAttribute.cs
public static void CreateNotFoundException(string srcDirectory, string projectBaseName, IFileSystem fileSystem) { var classPath = ClassPathHelper.ExceptionsClassPath(srcDirectory, $"NotFoundException.cs", projectBaseName); var fileText = GetNotFoundExceptionFileText(classPath.ClassNamespace); Utilities.CreateFile(classPath, fileText, fileSystem); }