Beispiel #1
0
        public override string GetClassName(CodeNames codeNames)
        {
            PolicyScopeServiceSelectorGenerator policyScopeServiceSelectorGenerator =
                new PolicyScopeServiceSelectorGenerator();

            return(policyScopeServiceSelectorGenerator.GetClassName(codeNames) + "Mock");
        }
Beispiel #2
0
        public string CreateClassCode(CodeNames codeNameBase, int maxServiceCount)
        {
            PolicyScopeResultSelectorMockGenerator policyScopeResultSelectorMockGenerator =
                new PolicyScopeResultSelectorMockGenerator();
            PolicyScopeServiceSelectorGenerator policyScopeServiceSelectorGenerator =
                new PolicyScopeServiceSelectorGenerator();
            PolicyScopeResultSelectorGenerator servicePolicyScopeBuilderGenerator =
                new PolicyScopeResultSelectorGenerator();

            StringBuilder sb = new StringBuilder();

            sb.Append(
                $@"    internal class {GetClassNameAndTemplateParamaters(codeNameBase)} : {policyScopeServiceSelectorGenerator.GetInterfaceNameAndTemplateParamaters(codeNameBase)}
    {{
        internal {GetClassName(codeNameBase)}(IEnumerable<PolicyScopeMockConfiguration> configurations)
        {{
             Configurations = configurations;
        }}

        internal IEnumerable<PolicyScopeMockConfiguration> Configurations {{ get; }}

");

            for (int serviceCount = 0; serviceCount <= maxServiceCount; serviceCount++)
            {
                if (serviceCount != 0)
                {
                    sb.AppendLine();
                }
                CodeNames codeNames = new CodeNames(serviceCount, false, codeNameBase.IsAsync);

                sb.Append(
                    $@"        public {servicePolicyScopeBuilderGenerator.GetInterfaceNameAndTemplateParamaters(codeNames)} {codeNames.FunctionWithServicesName}{codeNames.TemplateParameters}()
        {{
            var configurations = Configurations
                                    .Where(conf => conf.ServiceTypes.Count() == {codeNames.ServiceCount})");

                for (int i = 0; i < codeNames.ServiceCount; i++)
                {
                    sb.Append(
                        $@"
                                    .Where(conf => typeof({codeNames.ServicesTypes[i]}).IsAssignableFrom(conf.ServiceTypes[{i}]))"
                        );
                }


                sb.AppendLine(
                    $@";

            if(!configurations.Any())
            {{
                string errorMessage = ""Found no configuration with {codeNames.ServiceCount} {(codeNames.ServiceCount == 1 ? "service" : "services")}"";");

                for (int i = 0; i < codeNames.ServiceCount; i++)
                {
                    sb.AppendLine(
                        $@"                errorMessage += Environment.NewLine + "" and service {i} is "" + typeof({codeNames.ServicesTypes[i]});"
                        );
                }

                sb.AppendLine(
                    $@"                errorMessage += ""."";

                throw new PolicyScopeMockException(errorMessage, Configurations);
            }}

            return new {policyScopeResultSelectorMockGenerator.GetClassNameAndTemplateParamaters(codeNames)}(configurations);
        }}");
            }

            sb.AppendLine(
                $@"    }}");

            return(sb.ToString());
        }
Beispiel #3
0
        static int Main(string[] args)
        {
            int maxServiceCount = 4;

            if (args.Length >= 1)
            {
                Common.CodeGeneratorBase.BaseDirectory = args.Last();
                Console.WriteLine("Using base directory: " + Common.CodeGeneratorBase.BaseDirectory);
            }

            int fileUpdateCount = 0;

            Console.WriteLine("Autogenerating code for main library...");

            PolicyScopeResultSelectorGenerator servicePolicyScopeBuilderGenerator
                = new PolicyScopeResultSelectorGenerator();

            fileUpdateCount += servicePolicyScopeBuilderGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeRunnerGenerator policyRunnerGenerator
                = new PolicyScopeRunnerGenerator();

            fileUpdateCount += policyRunnerGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeServiceSelectorGenerator policyScopeServiceSelectorGenerator =
                new PolicyScopeServiceSelectorGenerator();

            fileUpdateCount += policyScopeServiceSelectorGenerator.WriteAllFiles(maxServiceCount);

            Console.WriteLine();
            Console.WriteLine("Autogenerating code for mock library...");

            PolicyScopeResultSelectorMockBuilderGenerator policyScopeResultSelectorMockBuilderGenerator =
                new PolicyScopeResultSelectorMockBuilderGenerator();

            fileUpdateCount += policyScopeResultSelectorMockBuilderGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeResultSelectorMockGenerator policyScopeResultSelectorMockGenerator =
                new PolicyScopeResultSelectorMockGenerator();

            fileUpdateCount += policyScopeResultSelectorMockGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeRunnerMockGenerator policyScopeRunnerMockGenerator
                = new PolicyScopeRunnerMockGenerator();

            fileUpdateCount += policyScopeRunnerMockGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeServiceSelectorMockBuilderGenerator policyScopeServiceSelectorMockBuilderGenerator =
                new PolicyScopeServiceSelectorMockBuilderGenerator();

            fileUpdateCount += policyScopeServiceSelectorMockBuilderGenerator.WriteAllFiles(maxServiceCount);

            PolicyScopeServiceSelectorMockGenerator policyScopeServiceSelectorMockGenerator =
                new PolicyScopeServiceSelectorMockGenerator();

            fileUpdateCount += policyScopeServiceSelectorMockGenerator.WriteAllFiles(maxServiceCount);

            Console.WriteLine();
            Console.WriteLine("Autogenerating code for logic test...");

            LogicGenerator logicGenerator =
                new LogicGenerator();

            fileUpdateCount += logicGenerator.WriteAllFiles(maxServiceCount);

            WorkerGenerator workerGenerator =
                new WorkerGenerator();

            fileUpdateCount += workerGenerator.WriteAllFiles(maxServiceCount);

            Console.WriteLine();
            Console.WriteLine("Autogenerating code for test...");

            UnitTestLogicGenerator unitTestLogicGenerator =
                new UnitTestLogicGenerator();

            fileUpdateCount += unitTestLogicGenerator.WriteAllFiles(maxServiceCount);

            UnitTestResourceNotFoundGenerator unitTestResourceNotFoundGenerator =
                new UnitTestResourceNotFoundGenerator();

            fileUpdateCount += unitTestResourceNotFoundGenerator.WriteAllFiles(maxServiceCount);

            UnitTestServiceNotFoundGenerator unitTestServiceNotFoundGenerator =
                new UnitTestServiceNotFoundGenerator();

            fileUpdateCount += unitTestServiceNotFoundGenerator.WriteAllFiles(maxServiceCount);

            Console.WriteLine();
            Console.WriteLine($"Autogenerating completed. {fileUpdateCount} files updated.");

            return(fileUpdateCount);
        }