Exemplo n.º 1
0
        public static GenerationUnit GenerateDrt(string src, string defaultProjNamespace, string filePath)
        {
            Code.NotNull(src, nameof(src));
            Code.NotNullNorWhiteSpace(filePath, nameof(filePath));

            RefTable.Instance.TryRemoveTestRefs(filePath);
            var cUnit   = Compiler.Instance.CompileTestOnFly(src, filePath);
            var cErrors = cUnit.Errors.Select(err => err.Flatten()).AsReadOnly();

            if (cErrors.Count > 0)
            {
                return(GenerationUnit.Error(cErrors, filePath));
            }

            var testDefs = cUnit
                           .OnlyValidTests()
                           .ValidTests
                           .Select(x => new TestDefinition(
                                       x.Name,
                                       x.BoolFlag1Values.Length > 0 && x.BoolFlag1Values.First().Value,
                                       x.BoolFlag2Values.Length > 0 && x.BoolFlag2Values.First().Value,
                                       x.ClassRegistrations.Select(y => new DependencyRegistration(y.Dependency, y.Implementation)).AsReadOnly(),
                                       x.RegisteredModules.Select(y => new ModuleRegistration(y.Name)).AsReadOnly()))
                           .AsReadOnly();
            var templateModel = new TestTemplateModel(defaultProjNamespace, testDefs);
            var template      = new TestTemplate(templateModel);
            var csSrc         = template.TransformText();

            return(GenerationUnit.Complete(Encoding.UTF8.GetBytes(csSrc), filePath));
        }
Exemplo n.º 2
0
        public TestTemplate(TestTemplateModel model)
        {
            Code.NotNull(model, nameof(model));

            Model = model;
        }