Beispiel #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"));
        }
Beispiel #2
0
        public void SafeNullable_ValueProperty_NotNullInstace_FunctionExecuted()
        {
            var notNull = new SafeSubject {
                ValueProperty = 3
            };

            Assert.That(notNull.SafeValue(o => o.ValueProperty), Is.EqualTo(3));
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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"));
        }
Beispiel #6
0
        public void SafeValue_NullableProperty_NotNullInstace_FunctionExecuted()
        {
            var notNull = new SafeSubject {
                NullableProperty = 3
            };

            Assert.That(notNull.SafeValue(o => o.NullableProperty), Is.EqualTo(3));

            // null is a valid proprety value
            notNull = new SafeSubject {
                NullableProperty = null
            };
            Assert.That(notNull.SafeValue(o => o.NullableProperty), Is.Null);
        }
Beispiel #7
0
        public void SafeValue_NullableProperty_NullInstace_Null()
        {
            SafeSubject @null = null;

            Assert.That(@null.SafeValue(o => o.NullableProperty), Is.Null);
        }
Beispiel #8
0
        public void Safe_NullInstance_Null()
        {
            SafeSubject @null = null;

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