コード例 #1
0
        public void SpecialCallerInfoCase2()
        {
            Mock <ILog> mock    = new Mock <ILog>();
            bool        invoked = false;

            mock
            .Setup(x => x.Error(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.Error("Hello, World!",
                      callerName: default(string),
                      callerFilePath: "c:\abb\a.b",
                      callerLineNumber: default(int) - 1);
            Assert.That(invoked, Is.True);
        }
コード例 #2
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.Error(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.Error("Hello, World!", new Exception("Surpirse!!"));
            Assert.That(invoked, Is.True);
        }