Ejemplo n.º 1
0
        public void TestSafeCallWithNullInstance()
        {
            SomeDemoObject obj = null;

            Action act = () => obj.SafeCall(sdo => {
                sdo.Integer = 100;
                sdo.String  = "Hello world";
                sdo.Type    = "Demo";
            });

            act.ShouldNotThrow();
        }
Ejemplo n.º 2
0
        public void TestSafeCallReturnWithNullInstance()
        {
            SomeDemoObject obj    = null;
            string         retval = "vrk"; // just initializing to something, we are expecting this to be null after the safecall

            // implementation returns default(T) when called instance is null, so retval should be null
            retval = obj.SafeCall(sdo =>
            {
                return(sdo.ToString());
            });

            retval.Should().BeNull();
        }
Ejemplo n.º 3
0
        public void TestSafeCallReturnCalculation()
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 9,
                String  = "vrk",
                Type    = "demo"
            };

            int calcResult = obj.SafeCall(sdo =>
            {
                return(sdo.Integer + 1);
            });

            calcResult.Should().Be(10);
        }
Ejemplo n.º 4
0
        public void TestSafeCall()
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 9,
                String  = "vrk",
                Type    = "demo"
            };

            obj.SafeCall(sdo =>
            {
                sdo.Integer = 100;
            });

            obj.Integer.Should().Be(100);
        }
Ejemplo n.º 5
0
        public void TestSafeCallReturn()
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 9,
                String  = "vrk",
                Type    = "demo"
            };

            string str = obj.ToString();

            string strB = obj.SafeCall(sdo =>
            {
                return(sdo.ToString());
            });

            strB.Should().Be(str);
        }