コード例 #1
0
        public void Safe_NotNullInstance_FunctionExecuted()
        {
            var notNull = new SafeSubject {
                ReferenceProperty = new Exception("msg")
            };

            Assert.That(notNull.Safe(o => o.ReferenceProperty.Message), Is.EqualTo("msg"));
        }
コード例 #2
0
        public void Safe_CustomSafetyNotFullfiled_ChainBreaks()
        {
            var subject = new SafeSubject {
                ReferenceProperty = new Exception("msg", new Exception("inner msg"))
            };

            string innerMostMessage = subject
                                      .Safe(s => s.ReferenceProperty)
                                      .Safe(p => p.InnerException, ex => ex.Message.Length > 3)
                                      .Safe(p => p.Message);

            Assert.That(innerMostMessage, Is.Null);
        }
コード例 #3
0
        public void Safe_SomeNullInChain_Null()
        {
            var subject = new SafeSubject {
                ReferenceProperty = new Exception("msg", null)
            };

            string innerMostMessage = subject
                                      .Safe(s => s.ReferenceProperty)
                                      .Safe(p => p.InnerException)
                                      .Safe(p => p.Message);

            Assert.That(innerMostMessage, Is.Null);
        }
コード例 #4
0
        public void Safe_NotNullChain_InnerMostValue()
        {
            var subject = new SafeSubject {
                ReferenceProperty = new Exception("msg", new Exception("inner msg"))
            };

            string innerMostMessage = subject
                                      .Safe(s => s.ReferenceProperty)
                                      .Safe(p => p.InnerException)
                                      .Safe(p => p.Message);

            Assert.That(innerMostMessage, Is.EqualTo("inner msg"));
        }
コード例 #5
0
        public void Safe_NullInstance_Null()
        {
            SafeSubject @null = null;

            Assert.That(@null.Safe(o => o.ReferenceProperty), Is.Null);
        }