예제 #1
0
        public void LoggerOk()
        {
            var logger  = new SomeLogger("MegaLogger");
            var message = MessageEx.Default(Severity.Fatal, logger: logger);

            Assert.Equal("MegaLogger", message.Get(MessageTokens.Logger));
        }
예제 #2
0
        public void MessageFormatOk()
        {
            var logger = new SomeLogger("test");

            logger.Log(Severity.Fatal, "{2} {0} {1}", "Message", "is cool", "Test");
            var message = logger.LastMessage;

            Assert.Equal("Test Message is cool", message.Get(MessageTokens.Message));
        }
예제 #3
0
        public void Reuse_func_arguments_in_nested_dependencies()
        {
            var container = new Container();

            container.Register <AA>();
            container.Register <BB>();

            var getAA = container.Resolve <Func <ILogger, AA> >();

            var logger = new SomeLogger();
            var aa     = getAA(logger);

            Assert.AreSame(logger, aa.Logger);
            Assert.AreSame(aa.Bb.Logger, aa.Logger);
        }
예제 #4
0
        public void Should_not_reuse_func_arguments_in_the_same_service()
        {
            var container = new Container();

            container.Register <AA>();
            container.Register <BB, BBB>(Made.Of(() => new BBB(Arg.Of <ILogger>(), Arg.Of <ILogger>(IfUnresolved.ReturnDefault))));

            var getAA = container.Resolve <Func <ILogger, AA> >();

            var logger = new SomeLogger();
            var aa     = getAA(logger);

            Assert.IsNull(((BBB)aa.Bb).OtherLogger);
            Assert.AreSame(logger, aa.Logger);
            Assert.AreSame(aa.Bb.Logger, aa.Logger);
        }
예제 #5
0
        public void For_singleton_can_use_func_without_args_or_just_resolve_after_func_with_args()
        {
            var container = new Container();

            container.Register <BB>(Reuse.Singleton);

            var logger = new SomeLogger();
            var bb     = container.Resolve <Func <ILogger, BB> >().Invoke(logger);

            var bb2 = container.Resolve <Func <BB> >().Invoke();

            Assert.AreSame(bb, bb2);

            var bb3 = container.Resolve <BB>();

            Assert.AreSame(bb, bb3);
        }
예제 #6
0
        public void FormatMessagesWorks()
        {
            var l = new SomeLogger();

            l.Log(Severity.Fatal, "test{0}", 1);
            l.LastWas(Severity.Fatal, "test1");
            l.Debug("test{0}", "D");
            l.LastWas(Severity.Debug, "testD");
            l.Info("test{0}", "I");
            l.LastWas(Severity.Info, "testI");
            l.Warning("test{0}", "W");
            l.LastWas(Severity.Warn, "testW");
            l.Error("test{0}", "E");
            l.LastWas(Severity.Error, "testE");
            l.Fatal("test{0}", "F");
            l.LastWas(Severity.Fatal, "testF");
        }