public void should_add_skipped_automap_types_to_result()
        {
            var despatcher = Mock <IDiagnosticMessageDespatcher> .Create();

            var logger = new DefaultDiagnosticLogger(despatcher);

            logger.AutomappingSkippedType(typeof(object), "reason");
            logger.Flush();

            DiagnosticResults result = null;

            despatcher.AssertWasCalled(x => x.Publish(Arg <DiagnosticResults> .Is.Anything),
                                       c => c.Callback <DiagnosticResults>(x =>
            {
                result = x;
                return(true);
            }));

            result.AutomappingSkippedTypes
            .ShouldContain(new SkippedAutomappingType
            {
                Type   = typeof(object),
                Reason = "reason"
            });
        }
        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_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_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_add_conventions_to_result()
        {
            var dispatcher = A.Fake <IDiagnosticMessageDispatcher>();
            var logger     = new DefaultDiagnosticLogger(dispatcher);

            DiagnosticResults result = null;

            A.CallTo(() => dispatcher.Publish(A <DiagnosticResults> ._))
            .Invokes(a => { result = (DiagnosticResults)a.Arguments.First(); });

            logger.ConventionDiscovered(typeof(SomeConvention));
            logger.Flush();

            result.Conventions.ShouldContain(typeof(SomeConvention));
        }
        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);
        }
Ejemplo n.º 7
0
        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 should_add_automapping_candidates()
        {
            var dispatcher = A.Fake <IDiagnosticMessageDispatcher>();
            var logger     = new DefaultDiagnosticLogger(dispatcher);

            DiagnosticResults result = null;

            A.CallTo(() => dispatcher.Publish(A <DiagnosticResults> ._))
            .Invokes(a => { result = (DiagnosticResults)a.Arguments.First(); });

            logger.AutomappingCandidateTypes(new[] { typeof(object) });
            logger.Flush();

            result.AutomappingCandidateTypes
            .ShouldContain(typeof(object));
        }
        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 void should_add_automapping_type_with_begin()
        {
            var dispatcher = A.Fake <IDiagnosticMessageDispatcher>();
            var logger     = new DefaultDiagnosticLogger(dispatcher);

            DiagnosticResults result = null;

            A.CallTo(() => dispatcher.Publish(A <DiagnosticResults> ._))
            .Invokes(a => { result = (DiagnosticResults)a.Arguments.First(); });

            logger.BeginAutomappingType(typeof(object));
            logger.Flush();

            result.AutomappedTypes
            .Select(x => x.Type)
            .ShouldContain(typeof(object));
        }
        public void should_add_scanned_convention_sources_to_result()
        {
            var dispatcher = A.Fake <IDiagnosticMessageDispatcher> ();
            var logger     = new DefaultDiagnosticLogger(dispatcher);

            DiagnosticResults result = null;

            A.CallTo(() => dispatcher.Publish(A <DiagnosticResults> ._))
            .Invokes(a => { result = (DiagnosticResults)a.Arguments.First(); });

            logger.LoadedConventionsFromSource(new StubTypeSource());
            logger.Flush();

            result.ScannedSources
            .Where(x => x.Phase == ScanPhase.Conventions)
            .Select(x => x.Identifier)
            .ShouldContain("StubTypeSource");
        }
        public void should_add_skipped_automap_types_to_result()
        {
            var dispatcher = A.Fake <IDiagnosticMessageDispatcher>();
            var logger     = new DefaultDiagnosticLogger(dispatcher);

            DiagnosticResults result = null;

            A.CallTo(() => dispatcher.Publish(A <DiagnosticResults> ._))
            .Invokes(a => { result = (DiagnosticResults)a.Arguments.First(); });

            logger.AutomappingSkippedType(typeof(object), "reason");
            logger.Flush();

            result.AutomappingSkippedTypes
            .ShouldContain(new SkippedAutomappingType
            {
                Type   = typeof(object),
                Reason = "reason"
            });
        }
        public void should_add_conventions_to_result()
        {
            var despatcher = Mock <IDiagnosticMessageDespatcher> .Create();

            var logger = new DefaultDiagnosticLogger(despatcher);

            logger.ConventionDiscovered(typeof(SomeConvention));
            logger.Flush();

            DiagnosticResults result = null;

            despatcher.AssertWasCalled(x => x.Publish(Arg <DiagnosticResults> .Is.Anything),
                                       c => c.Callback <DiagnosticResults>(x =>
            {
                result = x;
                return(true);
            }));

            result.Conventions.ShouldContain(typeof(SomeConvention));
        }
        public void should_add_automapping_candidates()
        {
            var despatcher = Mock <IDiagnosticMessageDespatcher> .Create();

            var logger = new DefaultDiagnosticLogger(despatcher);

            logger.AutomappingCandidateTypes(new[] { typeof(object) });
            logger.Flush();

            DiagnosticResults result = null;

            despatcher.AssertWasCalled(x => x.Publish(Arg <DiagnosticResults> .Is.Anything),
                                       c => c.Callback <DiagnosticResults>(x =>
            {
                result = x;
                return(true);
            }));

            result.AutomappingCandidateTypes
            .ShouldContain(typeof(object));
        }
        public void should_add_automapping_type_with_begin()
        {
            var despatcher = Mock <IDiagnosticMessageDespatcher> .Create();

            var logger = new DefaultDiagnosticLogger(despatcher);

            logger.BeginAutomappingType(typeof(object));
            logger.Flush();

            DiagnosticResults result = null;

            despatcher.AssertWasCalled(x => x.Publish(Arg <DiagnosticResults> .Is.Anything),
                                       c => c.Callback <DiagnosticResults>(x =>
            {
                result = x;
                return(true);
            }));

            result.AutomappedTypes
            .Select(x => x.Type)
            .ShouldContain(typeof(object));
        }
        public void should_add_scanned_fluent_mapping_sources_to_result()
        {
            var despatcher = Mock <IDiagnosticMessageDespatcher> .Create();

            var logger = new DefaultDiagnosticLogger(despatcher);

            logger.LoadedFluentMappingsFromSource(new StubTypeSource());
            logger.Flush();

            DiagnosticResults result = null;

            despatcher.AssertWasCalled(x => x.Publish(Arg <DiagnosticResults> .Is.Anything),
                                       c => c.Callback <DiagnosticResults>(x =>
            {
                result = x;
                return(true);
            }));

            result.ScannedSources
            .Where(x => x.Phase == ScanPhase.FluentMappings)
            .Select(x => x.Identifier)
            .ShouldContain("StubTypeSource");
        }
            public void Receive(DiagnosticResults results)
            {
                var output = this.formatter.Format(results);

                this.logger.Debug(output);
            }
Ejemplo n.º 18
0
 public void Receive(DiagnosticResults results)
 {
     receiver(results);
 }
        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"
                );
        }