Ejemplo n.º 1
0
        public string Render(DalTestStrategy strategy = DalTestStrategy.Semantic)
        {
            var sb = new StringBuilder();

            foreach (var usingDirective in GetUsings())
            {
                sb.AppendLine($@"using {usingDirective};");
            }

            var methodCall = $@"new {this.Item.DalClassName}().{this.Item.DalMethodName}({this.Item.FlatParams})";
            var methodTest =
                strategy == DalTestStrategy.Semantic ?
                $@"this.CheckDalSyntax(() => {methodCall});" : // Test sémantique : on enveloppe l'appel pour attraper les exceptions liées aux données.
                $@"{methodCall};";                             // Test standard

            sb.Append(
                $@"
namespace {this.Item.DalAssemblyName}.Test.{this.Item.DalClassName}Test {{

    [TestClass]
    public class {this.Item.DalMethodName}Test : DalTest {{

        [TestMethod]
        public void Check_{this.Item.DalMethodName}_Ok() {{

            // Act
            {methodTest}
        }}
    }}
}}");
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        private Solution AddUnitTestAsync(Document document, MethodDeclarationSyntax methDecl, IMethodSymbol methSymbol, ClassDeclarationSyntax classDecl, DalTestStrategy strategy, CancellationToken cancellationToken)
        {
            var solution = document.Project.Solution;

            /* Trouver le projet de test. */
            var testProjetName = document.Project.Name + ".Test";
            var testProject    = solution.Projects.FirstOrDefault(x => x.Name == testProjetName);

            if (testProject == null)
            {
                return(solution);
            }

            /* Dossier du document. */
            var classTestDir = classDecl.GetClassName() + "Test";

            /* Nom du document. */
            var methTestFile = methSymbol.Name + "Test";

            /* Contenu du document. */
            var             classSymbol     = methSymbol.ContainingType;
            var             applicationName = classSymbol.ContainingAssembly.GetApplicationName();
            DalTestTemplate template        = new DalTestTemplate(new DalMethodItem {
                DalClassName    = classSymbol.Name,
                DalMethodName   = methSymbol.Name,
                DalAssemblyName = classSymbol.ContainingAssembly.Name,
                DalNamespace    = classDecl.GetNameSpaceFullName(),
                Params          = methSymbol.Parameters.Select(x => GetParameter(x)).ToList(),
                SpecificUsings  = new List <string> {
                    $"{applicationName}.TestUtils.Templates", "Kinetix.TestUtils.Helpers"
                }
            });
            string content = template.Render(strategy);

            /* Création du document. */
            var newDoc = testProject.AddDocument(methTestFile, content, new List <string> {
                classTestDir
            });

            /* Retourne la solution modifiée. */
            return(newDoc.Project.Solution);
        }