Exemplo n.º 1
0
        private static string RenderUnitTestSourceCode(UnitTestCodeViewModel viewModel)
        {
            var templateText = GetUnitTestSourceCodeTemplate();

            var template = Handlebars.Compile(templateText);

            var unitTestSourceCode = template(viewModel);

            return(unitTestSourceCode);
        }
        public static UnitTestCodeViewModel GetViewModel(IEnumerable <UsingDirectiveSyntax> usings, NamespaceDeclarationSyntax namespaceNode, ClassDeclarationSyntax classNode, ConstructorDeclarationSyntax ctorNode)
        {
            var ctorParamList = GetMethodParamsViewModels(ctorNode?.ParameterList.Parameters ?? Enumerable.Empty <ParameterSyntax>());

            var methodsToTest = GetMethodViewModels(classNode.Members.OfType <MethodDeclarationSyntax>());

            var cutNamespace = namespaceNode.Name.ToString();

            var unitTestNamespace = UnitTestNamespaceGenerator.GenerateBasedOnCutNamespace(namespaceNode.Name.ToString());

            var viewModel =
                new UnitTestCodeViewModel
            {
                Usings        = usings.ToString(),
                CutName       = classNode.Identifier.Text,
                CutNamespace  = cutNamespace,
                CtorParams    = ctorParamList,
                MethodsToTest = methodsToTest,
                Namespace     = unitTestNamespace
            };

            return(viewModel);
        }