public void Publish(DiagnosticResults results)
 {
     foreach (var listener in listeners)
     {
         listener.Receive(results);
     }
 }
        public void should_format_results()
        {
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
            var formatter = Mock<IDiagnosticResultsFormatter>.Create();
            var listener = new StringLambdaOutputListener(x => { });
            listener.SetFormatter(formatter);
            listener.Receive(results);

            formatter.AssertWasCalled(x => x.Format(results));
        }
        public void should_format_results()
        {
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
            var formatter = A.Fake<IDiagnosticResultsFormatter>();
            var listener = new StringLambdaOutputListener(x => { });
            listener.SetFormatter(formatter);
            listener.Receive(results);

            A.CallTo(() => formatter.Format(results)).MustHaveHappened();
        }
        public void should_raise_formatted_results()
        {
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
            var output = "formatted output";
            var receivedOutput = "";
            var formatter = A.Fake<IDiagnosticResultsFormatter>();
            A.CallTo(() => formatter.Format(results)).Returns(output);
            var listener = new StringLambdaOutputListener(x => { receivedOutput = x; });
            listener.SetFormatter(formatter);
            listener.Receive(results);

            receivedOutput.ShouldEqual(output);
        }
        public void should_publish_results_to_all_listeners()
        {
            var firstListener = Mock<IDiagnosticListener>.Create();
            var secondListener = Mock<IDiagnosticListener>.Create();
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);

            dispatcher.RegisterListener(firstListener);
            dispatcher.RegisterListener(secondListener);
            dispatcher.Publish(results);

            firstListener.AssertWasCalled(x => x.Receive(results));
            secondListener.AssertWasCalled(x => x.Receive(results));
        }
        public void Receive(DiagnosticResults results)
        {
            var output = formatter.Format(results);
            var outputDirectory = Path.GetDirectoryName(outputPath);

            if (string.IsNullOrEmpty(outputDirectory))
                throw new ArgumentException("Output directory is invalid", "outputPath");

            if (!Directory.Exists(outputDirectory))
                Directory.CreateDirectory(outputDirectory);

            File.WriteAllText(outputPath, output);
        }
        public void should_publish_results_to_all_listeners()
        {
            var firstListener = A.Fake<IDiagnosticListener>();
            var secondListener = A.Fake<IDiagnosticListener>();
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);

            dispatcher.RegisterListener(firstListener);
            dispatcher.RegisterListener(secondListener);
            dispatcher.Publish(results);

            A.CallTo(() => firstListener.Receive(results)).MustHaveHappened();
            A.CallTo(() => secondListener.Receive(results)).MustHaveHappened();
        }
        public void should_raise_formatted_results()
        {
            var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
            var output = "formatted output";
            var receivedOutput = "";
            var formatter = Stub<IDiagnosticResultsFormatter>.Create(sb =>
                sb.Stub(x => x.Format(results))
                    .Return(output));
            var listener = new StringLambdaOutputListener(x => { receivedOutput = x; });
            listener.SetFormatter(formatter);
            listener.Receive(results);

            receivedOutput.ShouldEqual(output);
        }
        public string Format(DiagnosticResults results)
        {
            var sb = new StringBuilder();

            OutputFluentMappings(sb, results);

            sb.AppendLine();

            OutputConventions(sb, results);

            sb.AppendLine();

            OutputAutomappings(sb, results);

            return(sb.ToString());
        }
        public string Format(DiagnosticResults results)
        {
            var sb = new StringBuilder();

            OutputFluentMappings(sb, results);

            sb.AppendLine();

            OutputConventions(sb, results);

            sb.AppendLine();

            OutputAutomappings(sb, results);

            return sb.ToString();
        }
        public void Receive(DiagnosticResults results)
        {
            var output          = formatter.Format(results);
            var outputDirectory = Path.GetDirectoryName(outputPath);

            if (string.IsNullOrEmpty(outputDirectory))
            {
                throw new ArgumentException("Output directory is invalid", "outputPath");
            }

            if (!Directory.Exists(outputDirectory))
            {
                Directory.CreateDirectory(outputDirectory);
            }

            File.WriteAllText(outputPath, output);
        }
        void OutputConventions(StringBuilder sb, DiagnosticResults results)
        {
            Title(sb, "Conventions");

            sb.AppendLine();
            sb.AppendLine("Sources scanned:");
            sb.AppendLine();

            var sources = results.ScannedSources
                          .Where(x => x.Phase == ScanPhase.Conventions)
                          .OrderBy(x => x.Identifier)
                          .Select(x => x.Identifier)
                          .ToArray();

            if (sources.Any())
            {
                List(sb, sources);

                sb.AppendLine();
                sb.AppendLine("Conventions discovered:");
                sb.AppendLine();

                if (results.Conventions.Any())
                {
                    var conventions = results.Conventions
                                      .OrderBy(x => x.Name)
                                      .ToArray();

                    Table(sb,
                          conventions.Select(x => x.Name),
                          conventions.Select(x => x.AssemblyQualifiedName));
                }
                else
                {
                    sb.AppendLine("  None found");
                }
            }
            else
            {
                sb.AppendLine("  None found");
            }
        }
        void OutputConventions(StringBuilder sb, DiagnosticResults results)
        {
            Title(sb, "Conventions");

            sb.AppendLine();
            sb.AppendLine("Sources scanned:");
            sb.AppendLine();

            var sources = results.ScannedSources
                    .Where(x => x.Phase == ScanPhase.Conventions)
                    .OrderBy(x => x.Identifier)
                    .Select(x => x.Identifier)
                    .ToArray();

            if (sources.Any())
            {
                List(sb, sources);

                sb.AppendLine();
                sb.AppendLine("Conventions discovered:");
                sb.AppendLine();

                if (results.Conventions.Any())
                {
                    var conventions = results.Conventions
                        .OrderBy(x => x.Name)
                        .ToArray();

                    Table(sb,
                        conventions.Select(x => x.Name),
                        conventions.Select(x => x.AssemblyQualifiedName));
                }
                else
                {
                    sb.AppendLine("  None found");
                }
            }
            else
            {
                sb.AppendLine("  None found");
            }
        }
        void OutputAutomappings(StringBuilder sb, DiagnosticResults results)
        {
            Title(sb, "Automapping");

            sb.AppendLine();
            sb.AppendLine("Skipped types:");
            sb.AppendLine();

            var skippedTypes = results.AutomappingSkippedTypes
                    .OrderBy(x => x.Type.Name)
                    .ToArray();

            if (skippedTypes.Any())
            {
                Table(sb,
                    skippedTypes.Select(x => x.Type.Name),
                    skippedTypes.Select(x => x.Reason),
                    skippedTypes.Select(x => x.Type.AssemblyQualifiedName));
            }
            else
            {
                sb.AppendLine("  None found");
            }

            sb.AppendLine();
            sb.AppendLine("Candidate types:");
            sb.AppendLine();

            var candidateTypes = results.AutomappingCandidateTypes
                    .OrderBy(x => x.Name)
                    .ToArray();

            if (candidateTypes.Any())
            {
                Table(sb,
                    candidateTypes.Select(x => x.Name),
                    candidateTypes.Select(x => x.AssemblyQualifiedName));

                sb.AppendLine();
                sb.AppendLine("Mapped types:");
                sb.AppendLine();

                var automappedTypes = results.AutomappedTypes
                    .Select(x => x.Type);

                if (automappedTypes.Any())
                {
                    Table(sb,
                       automappedTypes.Select(x => x.Name),
                       automappedTypes.Select(x => x.AssemblyQualifiedName));   
                }
                else
                {
                    sb.AppendLine("  None found");
                }
            }
            else
            {
                sb.AppendLine("  None found");
            }
        }
 public void Publish(DiagnosticResults results)
 {
     foreach (var listener in listeners)
         listener.Receive(results);
 }
        void OutputAutomappings(StringBuilder sb, DiagnosticResults results)
        {
            Title(sb, "Automapping");

            sb.AppendLine();
            sb.AppendLine("Skipped types:");
            sb.AppendLine();

            var skippedTypes = results.AutomappingSkippedTypes
                               .OrderBy(x => x.Type.Name)
                               .ToArray();

            if (skippedTypes.Any())
            {
                Table(sb,
                      skippedTypes.Select(x => x.Type.Name),
                      skippedTypes.Select(x => x.Reason),
                      skippedTypes.Select(x => x.Type.AssemblyQualifiedName));
            }
            else
            {
                sb.AppendLine("  None found");
            }

            sb.AppendLine();
            sb.AppendLine("Candidate types:");
            sb.AppendLine();

            var candidateTypes = results.AutomappingCandidateTypes
                                 .OrderBy(x => x.Name)
                                 .ToArray();

            if (candidateTypes.Any())
            {
                Table(sb,
                      candidateTypes.Select(x => x.Name),
                      candidateTypes.Select(x => x.AssemblyQualifiedName));

                sb.AppendLine();
                sb.AppendLine("Mapped types:");
                sb.AppendLine();

                var automappedTypes = results.AutomappedTypes
                                      .Select(x => x.Type);

                if (automappedTypes.Any())
                {
                    Table(sb,
                          automappedTypes.Select(x => x.Name),
                          automappedTypes.Select(x => x.AssemblyQualifiedName));
                }
                else
                {
                    sb.AppendLine("  None found");
                }
            }
            else
            {
                sb.AppendLine("  None found");
            }
        }
 public void Receive(DiagnosticResults results)
 {
     var output = this.formatter.Format(results);
     this.logger.Debug(output);
 }
        public void Receive(DiagnosticResults results)
        {
            var output = formatter.Format(results);

            Console.WriteLine(output);
        }
        public void should_produce_simple_format()
        {
            var formatter = new DefaultOutputFormatter();
            var results = new DiagnosticResults(new[]
                {
                    new ScannedSource
                    {
                        Identifier = typeof(One).Assembly.GetName().FullName,
                        Phase = ScanPhase.FluentMappings
                    },
                    new ScannedSource
                    {
                        Identifier = typeof(One).Assembly.GetName().FullName,
                        Phase = ScanPhase.Conventions
                    }
                },
                new[] { typeof(Two), typeof(One) },
                new[] { typeof(Two), typeof(One) },
                new[]
                {
                    new SkippedAutomappingType
                    {
                        Type = typeof(One),
                        Reason = "first reason"
                    },
                    new SkippedAutomappingType
                    {
                        Type = typeof(Two),
                        Reason = "second reason"
                    },
                },
                new[] { typeof(Two), typeof(One) },
                new[]
                {
                    new AutomappingType
                    {
                        Type = typeof(One)
                    },
                    new AutomappingType
                    {
                        Type = typeof(Two)
                    },
                });
            var output = formatter.Format(results);

            output.ShouldEqual(
                "Fluent Mappings\r\n" +
                "---------------\r\n\r\n" +
                "Sources scanned:\r\n\r\n" +
                "  " + typeof(One).Assembly.GetName().FullName + "\r\n" +
                "\r\n" +
                "Mappings discovered:\r\n\r\n" +
                "  " + typeof(One).Name + " | " + typeof(One).AssemblyQualifiedName + "\r\n" +
                "  " + typeof(Two).Name + " | " + typeof(Two).AssemblyQualifiedName + "\r\n" +
                "\r\n" +
                "Conventions\r\n" +
                "-----------\r\n\r\n" +
                "Sources scanned:\r\n\r\n" +
                "  " + typeof(One).Assembly.GetName().FullName + "\r\n" +
                "\r\n" +
                "Conventions discovered:\r\n\r\n" +
                "  " + typeof(One).Name + " | " + typeof(One).AssemblyQualifiedName + "\r\n" +
                "  " + typeof(Two).Name + " | " + typeof(Two).AssemblyQualifiedName + "\r\n" +
                "\r\n" +
                "Automapping\r\n" +
                "-----------\r\n\r\n" +
                "Skipped types:\r\n\r\n" + 
                "  " + typeof(One).Name + " | first reason  | " + typeof(One).AssemblyQualifiedName + "\r\n" +
                "  " + typeof(Two).Name + " | second reason | " + typeof(Two).AssemblyQualifiedName + "\r\n" +
                "\r\n" +
                "Candidate types:\r\n\r\n" +
                "  " + typeof(One).Name + " | " + typeof(One).AssemblyQualifiedName + "\r\n" +
                "  " + typeof(Two).Name + " | " + typeof(Two).AssemblyQualifiedName + "\r\n" +
                "\r\n" + 
                "Mapped types:\r\n\r\n" +
                "  " + typeof(One).Name + " | " + typeof(One).AssemblyQualifiedName + "\r\n" +
                "  " + typeof(Two).Name + " | " + typeof(Two).AssemblyQualifiedName + "\r\n"
            );
        }
        public void Receive(DiagnosticResults results)
        {
            var output = formatter.Format(results);

            Console.WriteLine(output);
        }
        public void Receive(DiagnosticResults results)
        {
            var output = outputFormatter.Format(results);

            raiseMessage(output);
        }
        public void Receive(DiagnosticResults results)
        {
            var output = outputFormatter.Format(results);

            raiseMessage(output);
        }