Exemplo n.º 1
0
        public void should_build_logger_templates_and_discover_event_return_types()
        {
            var projectLoggerDiscoverBuilder = new ProjectLoggerDiscoverBuilder();

            projectLoggerDiscoverBuilder.SetLogMessage(Console.WriteLine);
            projectLoggerDiscoverBuilder.SetLogWarning(Console.WriteLine);
            projectLoggerDiscoverBuilder.SetLogError(Console.WriteLine);


            var project = new Project()
            {
                ProjectItems = new ProjectItem[]
                {
                    new ProjectItem <LoggerTemplateModel>(ProjectItemType.LoggerInterface,
                                                          @"C:\\Code\\CodeEffect\\CodeEffect.Diagnostics.EventSourceGenerator\\src\\ConsoleApplication1\\Loggers\\IDependencyLogger.cs", null, @"Loggers\\IDependencyLogger.cs"),
                    //new ProjectItem<LoggerTemplateModel>(ProjectItemType.LoggerInterface, @"C:\\Code\\CodeEffect\\CodeEffect.Diagnostics.EventSourceGenerator\\src\\ConsoleApplication1\\Loggers\\IConsoleLogger.cs", null, @"Loggers\\IConsoleLogger.cs"),
                    //new ProjectItem<LoggerTemplateModel>(ProjectItemType.LoggerInterface, @"C:\\Code\\CodeEffect\\CodeEffect.Diagnostics.EventSourceGenerator\\src\\ConsoleApplication1\\Loggers\\IConsoleRunnerLogger.cs", null, @"Loggers\\IConsoleRunnerLogger.cs"),
                },
                DynamicAssembly = typeof(IDependencyLogger).Assembly,
            };

            projectLoggerDiscoverBuilder.Build(project);

            project.Loggers.Should().HaveCount(1);

            var dependencyLogger = project.Loggers[0];

            dependencyLogger.Should().NotBeNull();

            var loggerEvent = dependencyLogger.Events[0];

            loggerEvent.Should().NotBeNull();

            loggerEvent.ReturnType.Should().Be(typeof(IDisposable).GetFriendlyName());
        }
        public void should_render_return_types_for_logger_event_implementations()
        {
            var projectLoggerDiscoverBuilder = new ProjectLoggerDiscoverBuilder();

            projectLoggerDiscoverBuilder.SetLogMessage(Console.WriteLine);
            projectLoggerDiscoverBuilder.SetLogWarning(Console.WriteLine);
            projectLoggerDiscoverBuilder.SetLogError(Console.WriteLine);

            var project = new Project()
            {
                ProjectItems = new ProjectItem[]
                {
                    new ProjectItem <LoggerTemplateModel>(ProjectItemType.LoggerInterface,
                                                          @"C:\\Code\\CodeEffect\\CodeEffect.Diagnostics.EventSourceGenerator\\src\\ConsoleApplication1\\Loggers\\IDependencyLogger.cs", null, @"Loggers\\IDependencyLogger.cs"),
                },
                DynamicAssembly = typeof(IDependencyLogger).Assembly,
                Extensions      = new IExtension[0]
            };

            projectLoggerDiscoverBuilder.Build(project);

            var eventSourceProjectItem = new ProjectItem <EventSourceModel>(ProjectItemType.EventSource, "sample", new EventSourceModel());

            project.AddProjectItem(eventSourceProjectItem);

            var projectItem = new ProjectItem <LoggerModel>(ProjectItemType.LoggerImplementation,
                                                            @"C:\\Code\\CodeEffect\\CodeEffect.Diagnostics.EventSourceGenerator\\src\\ConsoleApplication1\\Loggers\\DependencyLogger.cs", new LoggerModel()
            {
                ClassName = "DependencyLogger"
            },
                                                            @"Loggers\\DependencyLogger.cs")
            {
                DependentUpon = eventSourceProjectItem
            };

            project.AddProjectItem(projectItem);

            var loggerImplementationRenderer = new LoggerImplementationRenderer();

            loggerImplementationRenderer.SetLogMessage(Console.WriteLine);
            loggerImplementationRenderer.SetLogWarning(Console.WriteLine);
            loggerImplementationRenderer.SetLogError(Console.WriteLine);

            loggerImplementationRenderer.Render(project, projectItem);

            projectItem.Output.Should().Be(@"");

            //loggerImplementationRenderer.Render(project, );
        }