コード例 #1
0
        public void WithoutCultureArg12()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! \u00a41.00\u00a42.00\u00a43.00\u00a44.00\u00a45.00\u00a46.00\u00a47.00\u00a48.123.142014-01-2212:33:53-9,000"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                "Hello, World! {0:C}{1:C}{2:C}{3:C}{4:C}{5:C}{6:C}{7:C}{8:#0.00}{9:yyyy-MM-dd}{10}{11:#,##0}",
                1, 2, 3, 4, 5, 6, 7, 8.12m, Math.PI, new DateTime(2014, 1, 22), new TimeSpan(12, 33, 53), -9000);
            Assert.That(invoked, Is.True);
        }
コード例 #2
0
        public void SpecialCallerInfoCase2()
        {
            Mock <ILog> mock    = new Mock <ILog>();
            bool        invoked = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining("invalid file path:")
                            .And.StringContaining("unknown member,")
                            .And.StringMatching(":0")
                            .And.StringEnding("Hello, World!"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.Info("Hello, World!",
                     callerName: default(string),
                     callerFilePath: "c:\abb\a.b",
                     callerLineNumber: default(int) - 1);
            Assert.That(invoked, Is.True);
        }
コード例 #3
0
        public void WithoutCultureArg9()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! \u00a41.00\u00a42.00\u00a43.00\u00a44.00\u00a45.00\u00a46.00\u00a47.00\u00a48.123.14"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                "Hello, World! {0:C}{1:C}{2:C}{3:C}{4:C}{5:C}{6:C}{7:C}{8:#0.00}",
                1, 2, 3, 4, 5, 6, 7, 8.12m, Math.PI);
            Assert.That(invoked, Is.True);
        }
コード例 #4
0
        public void WithCultureArgs()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! $1.00$2.00$3.00$4.00$5.00$6.00$7.00$8.123.142014-01-2212:33:53-9,000abcd123&"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                CultureInfo.GetCultureInfo("en-US"),
                "Hello, World! {0:C}{1:C}{2:C}{3:C}{4:C}{5:C}{6:C}{7:C}{8:#0.00}{9:yyyy-MM-dd}{10}{11:#,##0}{12}{13}{14}{15}{16}",
                new object[] { 1, 2, 3, 4, 5, 6, 7, 8.12m, Math.PI, new DateTime(2014, 1, 22), new TimeSpan(12, 33, 53), -9000, 'a', 'b', "cd", "123", '&' });
            Assert.That(invoked, Is.True);
        }
コード例 #5
0
        public void WithoutCultureArg1()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! \u00a41.00"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                "Hello, World! {0:C}",
                1);
            Assert.That(invoked, Is.True);
        }
コード例 #6
0
        public void WithCultureArg10()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! $1.00$2.00$3.00$4.00$5.00$6.00$7.00$8.123.142014-01-22"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                CultureInfo.GetCultureInfo("en-US"),
                "Hello, World! {0:C}{1:C}{2:C}{3:C}{4:C}{5:C}{6:C}{7:C}{8:#0.00}{9:yyyy-MM-dd}",
                1, 2, 3, 4, 5, 6, 7, 8.12m, Math.PI, new DateTime(2014, 1, 22));
            Assert.That(invoked, Is.True);
        }
コード例 #7
0
        public void WithCultureArg5()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World! $1.00$2.00$3.00$4.00$5.00"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.InfoFormat(
                CultureInfo.GetCultureInfo("en-US"),
                "Hello, World! {0:C}{1:C}{2:C}{3:C}{4:C}",
                1, 2, 3, 4, 5);
            Assert.That(invoked, Is.True);
        }
コード例 #8
0
        public void MessageAndException()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Info(It.IsAny <object>(), It.IsAny <Exception>()))
            .Callback <object, Exception>((x, y) =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World!"));
                Assert.That(y, Is
                            .Not.Null
                            .And.Property("Message").EqualTo("Surpirse!!"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.Info("Hello, World!", new Exception("Surpirse!!"));
            Assert.That(invoked, Is.True);
        }
コード例 #9
0
        public void Message()
        {
            Mock <ILog> mock           = new Mock <ILog>();
            string      callerName     = this.ObtainCallerName();
            string      callerFilePath = Path.GetFileName(this.ObtainCallerFilePath());
            bool        invoked        = false;

            mock
            .Setup(x => x.Debug(It.IsAny <object>()))
            .Callback <object>(x =>
            {
                Assert.That(x, Is
                            .Not.Null
                            .And.StringContaining(callerName)
                            .And.StringContaining(callerFilePath)
                            .And.StringMatching(":[0-9]+")
                            .And.StringEnding("Hello, World!"));
                invoked = true;
            });

            CallerInfoLog log = new CallerInfoLog(mock.Object);

            log.Debug("Hello, World!");
            Assert.That(invoked, Is.True);
        }
コード例 #10
0
 public void NullReferenceTest()
 {
     CallerInfoLog log = new CallerInfoLog(null);
 }