Beispiel #1
0
        public void GetMatchingFiles_doesnt_crash_on_no_files()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;

            Assert.AreEqual(0, FileSupport.GetMatchingFiles("*.xadman", FileSupport.ProjectPath(path), true).Count());
            Assert.AreEqual(0, FileSupport.GetMatchingFiles("*.xadman", FileSupport.ProjectPath(path), false).Count());
        }
Beispiel #2
0
        public void ProjectPath_finds_project_in_higher_directory()
        {
            // This test expects current file structure
            var path = AppDomain.CurrentDomain.BaseDirectory;

            Assert.IsNotNull(FileSupport.ProjectPath(path));
        }
Beispiel #3
0
        public void ProjectPath_finds_project_in_parent_directory()
        {
            // This test expects current file structure
            var path = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

            Assert.IsNotNull(FileSupport.ProjectPath(path));
        }
Beispiel #4
0
        public void ProjectPath_returns_null_if_no_project_in_directory_hierarchy()
        {
            // This test is vulnerable to issues with directory structure, specifically, an extra csproj or vbproj file can lead to test failure
            var path = Path.GetDirectoryName(
                Path.GetDirectoryName(
                    Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)));

            Assert.IsNull(FileSupport.ProjectPath(path));
        }
Beispiel #5
0
        public void GetMatchingFiles_finds_files()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;

            Assert.AreEqual(3, FileSupport.GetMatchingFiles("*.kadcs", FileSupport.ProjectPath(path), true).Count());
            Assert.AreEqual(1, FileSupport.GetMatchingFiles("*.kadcs", FileSupport.ProjectPath(path), false).Count());
            var pattern = Path.Combine("..\\..", "*.kadcs");

            Assert.AreEqual(3, FileSupport.GetMatchingFiles("*.kadcs", FileSupport.ProjectPath(path), true).Count());
            Assert.AreEqual(1, FileSupport.GetMatchingFiles("*.kadcs", FileSupport.ProjectPath(path), false).Count());
            Assert.AreEqual(1, FileSupport.GetMatchingFiles("*.kadcs", FileSupport.ProjectPath(path)).Count());
        }
        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));
        }
Beispiel #7
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();
        }