Example #1
0
        public void GetNearestCSharpProject_finds_project_from_project_path()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\UtilitiesTests.csproj";
            var file = FileSupport.GetNearestCSharpProject(path);

            Assert.IsTrue(file.EndsWith(@"\UtilitiesTests.csproj"));
        }
Example #2
0
        public void GetNearestCSharpProject_returns_null_for_no_project()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\..";
            var file = FileSupport.GetNearestCSharpProject(path);

            Assert.IsNull(file);
        }
        public IDictionary <string, string> CreateOutputStringsFromProject(string relativePath, string outputRootDirectory, bool whatIf = false)
        {
            var startDirectory = Path.Combine(FileSupport.ProjectPath(AppDomain.CurrentDomain.BaseDirectory), relativePath);

            startDirectory = Path.GetFullPath(startDirectory);
            var ws          = MSBuildWorkspace.Create();
            var projectPath = FileSupport.GetNearestCSharpProject(startDirectory);
            // For now: wait for the result
            var project = ws.OpenProjectAsync(projectPath).Result;

            return(CreateOutputStringsFromProject(project, outputRootDirectory, whatIf));
        }
Example #4
0
            public void Should_create_domain_file_from_project()
            {
                var runner         = new ExpansionFirstCSharpRunner <CodeFirstClassGroup>(domainTemplateDirectory);
                var startDirectory = Path.Combine(FileSupport.ProjectPath(AppDomain.CurrentDomain.BaseDirectory),
                                                  "..\\DomainGenerationMetadata");

                startDirectory = Path.GetFullPath(startDirectory);
                var ws          = MSBuildWorkspace.Create();
                var projectPath = FileSupport.GetNearestCSharpProject(startDirectory);
                // For testing: wait for the result
                var project = ws.OpenProjectAsync(projectPath).Result;
                var dict    = runner.CreateOutputStringsFromProject(project, "..\\Output");

                AssertCreation(dict, Tuple.Create("customer.g.cs", expected1), Tuple.Create("customerSuperSimple.g.cs", expected2));
            }
        public void Should_create_file_from_semantic_log_from_project()
        {
            var runner         = new T4TemplateRunner();
            var startDirectory = Path.Combine(FileSupport.ProjectPath(AppDomain.CurrentDomain.BaseDirectory), "..\\SemanticLogGenerationMetadata");

            startDirectory = Path.GetFullPath(startDirectory);
            var ws          = MSBuildWorkspace.Create();
            var projectPath = FileSupport.GetNearestCSharpProject(startDirectory);
            // For now: wait for the result
            var project = ws.OpenProjectAsync(projectPath).Result;
            var dict    = runner.CreateOutputStringsFromProject(project, "..\\Output");

            Assert.AreEqual(1, dict.Count());
            var actual = dict.First().Value;

            actual = StringUtilities.RemoveFileHeaderComments(actual);
            Assert.AreEqual(expected, actual);
        }
        static void Main(string[] args)
        {
            var provider       = new ServiceProvider();
            var runner         = new T4TemplateRunner(provider);
            var startDirectory = Path.Combine(FileSupport.ProjectPath(AppDomain.CurrentDomain.BaseDirectory), "..\\DiagnosticsGeneration\\DiagnosticsGenerationMetadata");

            startDirectory = Path.GetFullPath(startDirectory);
            var ws          = MSBuildWorkspace.Create();
            var projectPath = FileSupport.GetNearestCSharpProject(startDirectory);
            // For now: wait for the result
            var project = ws.OpenProjectAsync(projectPath).Result;
            var dict    = runner.CreateOutputStringsFromProject(project, "..\\Output");

            foreach (var pair in dict)
            {
                File.WriteAllText(pair.Key, pair.Value);
            }

            //string[] outFiles;
            //var templateMaps = new List<TemplateMap>();
            //var provider = new Provider();
            //var entryPoints = provider.GetServices<ICodeFirstEntry>();

            //foreach (var entryPoint in entryPoints)
            //{
            //   var metadataLoader = provider.GetService<IMetadataLoader>(x=>x.ReturnType == entryPoint.GetType());
            //   templateMaps.Add(entryPoint.AttributeId, new CodeFirstMetadataLoader<CodeFirstDiagnosticGroup>(),
            //    new T4TemplateRunner(),
            //    new DiagnosticTemplate(),
            //    metadataDirectory: @"DiagnosticsGeneration\DiagnosticsGenerationMetadata",
            //    inputExtension: ".cs"))
            //}



            //templateMaps.Add(new TemplateMap<CodeFirstSemanticLogGroup, EventSourceTemplate>
            //   ("SemanticLog",
            //    new CodeFirstMetadataLoader<CodeFirstSemanticLogGroup>(),
            //    new T4TemplateRunner(),
            //    new EventSourceTemplate()));

            //templateMaps.Add(new TemplateMap<CodeFirstClassGroup, PropertyChangedTemplate>
            //   ("NotifyPropertyChanged",
            //    new CodeFirstMetadataLoader<CodeFirstClassGroup>(),
            //    new T4TemplateRunner(),
            //    new PropertyChangedTemplate()));

            //templateMaps.Add(new TemplateMap<CodeFirstDiagnosticGroup, DiagnosticTemplate>
            //   ("DiagnosticAndCodeFix",
            //    new CodeFirstMetadataLoader<CodeFirstDiagnosticGroup>(),
            //    new T4TemplateRunner(),
            //    new DiagnosticTemplate(),
            //    metadataDirectory: @"DiagnosticsGeneration\DiagnosticsGenerationMetadata",
            //    inputExtension: ".cs"));

            //templateMaps.Add(new TemplateMap<CodeFirstDiagnosticGroup, DiagnosticTemplate>
            //   (
            //    new CodeFirstMetadataLoader<CodeFirstDiagnosticGroup>(),
            //    new T4TemplateRunner(),
            //    new DiagnosticTemplate(),
            //    metadataDirectory: @"DiagnosticsGeneration\DiagnosticsGenerationMetadata",
            //    inputExtension: ".cs"));

            //var startDirectory = FileSupport.ProjectPath(AppDomain.CurrentDomain.BaseDirectory);
            //var ws = MSBuildWorkspace.Create();
            //foreach (var templateMap in templateMaps)
            //{
            //   var sourceDirectory = Path.Combine(startDirectory, "..");
            //   var sources = templateMap.GetFileNames(sourceDirectory);
            //   var firstSource = sources.FirstOrDefault();
            //   if (firstSource != null)
            //   {
            //      var projectPath = FileSupport.GetNearestCSharpProject(firstSource);
            //      // For now: wait for the result
            //      var project = ws.OpenProjectAsync(projectPath).Result;
            //      var rootGroup = RDom.CSharp.LoadGroup(project);
            //      var output = templateMap.OutputToFiles(out outFiles, rootGroup, sources.ToArray());
            //   }
            //}

            Console.Write("You're done. Adjacent to your generated file (temp location) you'll find a generated file to include in your project");
            Console.Read();
        }