Пример #1
0
        private static string WriteTestFileText(string solutionDirectory, string srcDirectory, ClassPath classPath, Entity entity, bool isProtected, Feature feature, string projectBaseName)
        {
            var dtoUtilClassPath     = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName);
            var testUtilClassPath    = ClassPathHelper.FunctionalTestUtilitiesClassPath(srcDirectory, projectBaseName, "");
            var fakerClassPath       = ClassPathHelper.TestFakesClassPath(srcDirectory, "", entity.Name, projectBaseName);
            var parentFakerClassPath = ClassPathHelper.TestFakesClassPath(srcDirectory, "", feature.ParentEntity, projectBaseName);
            var permissionsClassPath = ClassPathHelper.PolicyDomainClassPath(srcDirectory, "", projectBaseName);
            var rolesClassPath       = ClassPathHelper.SharedKernelDomainClassPath(solutionDirectory, "");

            var permissionsUsing = isProtected
                ? $"{Environment.NewLine}using {permissionsClassPath.ClassNamespace};{Environment.NewLine}using {rolesClassPath.ClassNamespace};"
                : string.Empty;

            var authOnlyTests = isProtected ? $@"
            {CreateEntityTestUnauthorized(entity)}
            {CreateEntityTestForbidden(entity)}" : "";

            return(@$ "namespace {classPath.ClassNamespace};

using {dtoUtilClassPath.ClassNamespace};
using {fakerClassPath.ClassNamespace};
using {parentFakerClassPath.ClassNamespace};
using {testUtilClassPath.ClassNamespace};{permissionsUsing}
using FluentAssertions;
using NUnit.Framework;
using System.Net;
using System.Threading.Tasks;
Пример #2
0
        public static void Create(string solutionDirectory, string solutionName)
        {
            try
            {
                var classPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, solutionName, $"HttpClientExtensions.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath); // saves me from having to make a remover!
                }
                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = CreateHttpClientExtensionsText(classPath);
                    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;
            }
        }
Пример #3
0
        public static void CreateClass(string solutionDirectory, string projectBaseName, List <Entity> entities, IFileSystem fileSystem)
        {
            try
            {
                var classPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectBaseName, "ApiRoutes.cs");

                if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
                {
                    fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (fileSystem.File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (var fs = fileSystem.File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetBaseText(classPath.ClassNamespace, entities);
                    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;
            }
        }
Пример #4
0
        private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, string projectBaseName)
        {
            var testUtilClassPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectBaseName, "");

            return(@$ "namespace {classPath.ClassNamespace}
{{
    using {testUtilClassPath.ClassNamespace};
    using FluentAssertions;
    using NUnit.Framework;
    using System.Net.Http;
    using System.Threading.Tasks;
Пример #5
0
        private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, List <Policy> policies, string projectBaseName)
        {
            var testUtilClassPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectBaseName, "");
            var fakerClassPath    = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName);

            var hasRestrictedEndpoints = policies.Count > 0;
            var authOnlyTests          = hasRestrictedEndpoints ? $@"
            {DeleteEntityTestUnauthorized(entity)}
            {DeleteEntityTestForbidden(entity)}" : "";

            return(@$ "namespace {classPath.ClassNamespace};

using {fakerClassPath.ClassNamespace};
using {testUtilClassPath.ClassNamespace};
using FluentAssertions;
using NUnit.Framework;
using System.Net;
using System.Threading.Tasks;
Пример #6
0
        public static void Create(string solutionDirectory, string projectName)
        {
            var classPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectName, $"HttpClientExtensions.cs");

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                Directory.CreateDirectory(classPath.ClassDirectory);
            }

            if (File.Exists(classPath.FullClassPath))
            {
                File.Delete(classPath.FullClassPath); // saves me from having to make a remover!
            }
            using (FileStream fs = File.Create(classPath.FullClassPath))
            {
                var data = CreateHttpClientExtensionsText(classPath);
                fs.Write(Encoding.UTF8.GetBytes(data));
            }
        }
Пример #7
0
        public static void CreateClass(string testDirectory, string projectBaseName, IFileSystem fileSystem)
        {
            var classPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(testDirectory, projectBaseName, "ApiRoutes.cs");

            if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
            {
                fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
            }

            if (fileSystem.File.Exists(classPath.FullClassPath))
            {
                throw new FileAlreadyExistsException(classPath.FullClassPath);
            }

            using var fs = fileSystem.File.Create(classPath.FullClassPath);
            var data = "";

            data = GetBaseText(classPath.ClassNamespace);
            fs.Write(Encoding.UTF8.GetBytes(data));
        }
Пример #8
0
        private static string WriteTestFileText(string solutionDirectory, ClassPath classPath, Entity entity, List <Policy> policies, string projectBaseName)
        {
            var testUtilClassPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectBaseName, "");
            var fakerClassPath    = ClassPathHelper.TestFakesClassPath(solutionDirectory, "", entity.Name, projectBaseName);
            var dtoClassPath      = ClassPathHelper.DtoClassPath(solutionDirectory, "", entity.Name, projectBaseName);

            var restrictedPolicies     = Utilities.GetEndpointPolicies(policies, Endpoint.UpdatePartial, entity.Name);
            var hasRestrictedEndpoints = restrictedPolicies.Count > 0;
            var authOnlyTests          = hasRestrictedEndpoints ? $@"
            {EntityTestUnauthorized(entity)}
            {EntityTestForbidden(entity)}" : "";

            return(@$ "namespace {classPath.ClassNamespace}
{{
    using {fakerClassPath.ClassNamespace};
    using {dtoClassPath.ClassNamespace};
    using {testUtilClassPath.ClassNamespace};
    using Microsoft.AspNetCore.JsonPatch;
    using FluentAssertions;
    using NUnit.Framework;
    using System.Net.Http;
    using System.Threading.Tasks;
Пример #9
0
        public static void AddRoutes(string solutionDirectory, List <Entity> entities, string projectBaseName)
        {
            var classPath = ClassPathHelper.FunctionalTestUtilitiesClassPath(solutionDirectory, projectBaseName, "ApiRoutes.cs");

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                throw new DirectoryNotFoundException($"The `{classPath.ClassDirectory}` directory could not be found.");
            }

            if (!File.Exists(classPath.FullClassPath))
            {
                throw new FileNotFoundException($"The `{classPath.FullClassPath}` file could not be found.");
            }

            var entityRouteClasses = Utilities.CreateApiRouteClasses(entities);
            var tempPath           = $"{classPath.FullClassPath}temp";

            using (var input = File.OpenText(classPath.FullClassPath))
            {
                using (var output = new StreamWriter(tempPath))
                {
                    string line;
                    while (null != (line = input.ReadLine()))
                    {
                        var newText = $"{line}";
                        if (line.Contains($"new api route marker"))
                        {
                            newText += entityRouteClasses;
                        }

                        output.WriteLine(newText);
                    }
                }
            }

            // delete the old file and set the name of the new one to the original name
            File.Delete(classPath.FullClassPath);
            File.Move(tempPath, classPath.FullClassPath);
        }