예제 #1
0
        public void PropertyAndExplisitCastChain_InvalidCast()
        {
            // Arange
            var employee = new Employee { Person = new Person { Pet = new Cat() } };

            // Act
            var result = employee.NullSafeChain(x => ((Dog)x.Person.Pet).Collar);
        }
예제 #2
0
        public void PropertyAndMethodCallChain_CallMethodWithParam_TheMethodReturnsNull()
        {
            // Arange
            var employee = new Employee { Manages = { new Employee { Person = new Person { Pet = new Cat() }, Name = "john" } } };

            // Act
            var result = employee.NullSafeChain(x => x.GetEmployeeByName("Jain").Person);

            // Assert
            Assert.Null(result);
        }
예제 #3
0
        public void PropertyAndMethodCallChain_CallExtensionMethod_TheMethodReturnsNull()
        {
            // Arange
            var employee = new Employee();

            // Act
            var result = employee.NullSafeChain(x => x.Manages.FirstOrDefault().Person);

            // Assert
            Assert.Null(result);
        }
예제 #4
0
        public void PropertyAndMethodCallChain_CallExtensionMethod_GetTheLastElement()
        {
            // Arange
            var employee = new Employee { Manages = { new Employee { Person = new Person { Pet = new Cat() } } } };

            // Act
            var result = employee.NullSafeChain(x => x.Manages.FirstOrDefault().Person);

            // Assert
            Assert.NotNull(result);
        }
예제 #5
0
        public void PropertyAndExplisitCastChain_GetTheLastElement()
        {
            // Arange
            var employee = new Employee { Person = new Person { Pet = new Dog { Collar = new Collar() } } };

            // Act
            var result = employee.NullSafeChain(x => ((Dog)x.Person.Pet).Collar);

            // Assert
            Assert.NotNull(result);
        }
예제 #6
0
        public void PropertyAndMethodCallChain_CallMethod_GetTheLastElement()
        {
            // Arange
            var employee = new Employee { Manages = { new Employee { Person = new Person { Pet = new Cat() }, Name = "Jain" } } };

            // Act
            var result = employee.NullSafeChain(x => x.GetFirstEmployee().Person);

            // Assert
            Assert.NotNull(result);
        }
예제 #7
0
        public void PropertyChain_TheThirdElementIsNull()
        {
            // Arange
            var employee = new Employee { Person = new Person() };

            // Act
            var result = employee.NullSafeChain(x => x.Person.Address.City);

            // Assert
            Assert.Null(result);
        }
예제 #8
0
        public void PropertyChain_GetTheLastElement()
        {
            // Arange
            var employee = new Employee { Person = new Person { Address = new Address { City = new City() } } };

            // Act
            var result = employee.NullSafeChain(x => x.Person.Address.City);

            // Assert
            Assert.NotNull(result);
        }
예제 #9
0
        public void PropertyAndTypeAsCastChain_TheAsReturnsNull()
        {
            // Arange
            var employee = new Employee { Person = new Person { Pet = new Cat() } };

            // Act
            var result = employee.NullSafeChain(x => (x.Person.Pet as Dog).Collar);

            // Assert
            Assert.Null(result);
        }
예제 #10
0
        public void PropertyAndMethodCallChain_CallMethod_TheMethodReturnsNull()
        {
            // Arange
            var employee = new Employee();

            // Act
            var result = employee.NullSafeChain(x => x.GetFirstEmployee().Person);

            // Assert
            Assert.Null(result);
        }