コード例 #1
0
        public void ShouldReturnNullWhenGetPropertyValueByRecursionFoundNoProperty()
        {
            var dummyObject = new EmptyDummy();
            var propertyReflection = new PropertyReflection();
            var result = propertyReflection.GetPropertyValue(dummyObject, "Doughnut", true);

            Assert.IsNull(result);
        }
コード例 #2
0
        public void ShouldGetPropertyValueSuccessfullyByRecursionOnParentObject()
        {
            var dummyObject = new DummyObject { Id = 5 };
            var propertyReflection = new PropertyReflection();
            var result = propertyReflection.GetPropertyValue(dummyObject, "Id", true);

            Assert.IsNotNull(result);
            Assert.AreEqual(5, Convert.ToInt32(result));
        }
コード例 #3
0
        public void ShouldGetPropertyValueSuccessfullyByRecursion()
        {
            var dummyObject = new DummyObjectComplex { Dummy = new DummyObject { Name = "Stars" } };
            var propertyReflection = new PropertyReflection();
            var result = propertyReflection.GetPropertyValue(dummyObject, "Name", true);

            Assert.IsNotNull(result);
            Assert.AreEqual("Stars", result.ToString());
        }
コード例 #4
0
        public void ShouldGetPropertyValueSuccessfully()
        {
            var dummyObject = new DummyObject { Name = "Stars" };
            var propertyReflection = new PropertyReflection();
            var result = propertyReflection.GetPropertyValue(dummyObject, "Name");

            Assert.IsNotNull(result);
            Assert.AreEqual(result, "Stars");
        }
コード例 #5
0
        public void GetPropertyValue()
        {
            //Arrange
            var person = CreatSut();
            //Act
            var result = PropertyReflection.GetPropertyValue <Person>(person,
                                                                      x => x.Address.Country.CountryName);

            //Assert
            Assert.Equal("USA", result);
        }
コード例 #6
0
        public void ShouldThrowExceptionWhenPropertyNotExistingOnGettingValue()
        {
            var dummyObject = new DummyObject();
            var propertyReflection = new PropertyReflection();
            var result = Assert.Throws<Exception>(() =>
                propertyReflection.GetPropertyValue(dummyObject, "Doughnut"));

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(Exception), result);
            Assert.AreEqual("Property Doughnut does not exist on DummyObject object", result.Message);
        }
コード例 #7
0
ファイル: CSV.cs プロジェクト: mav01981/Helper.Library
        private DataTable ConvertToDataTable <T>(IEnumerable <T> data,
                                                 params Expression <Func <T, object> >[] columnsFunc)
        {
            DataTable table = new DataTable();

            foreach (var column in columnsFunc)
            {
                string columnName = PropertyReflection.GetPropertyDisplayName <T>(column);
                table.Columns.Add(columnName);
            }

            foreach (T obj in data)
            {
                DataRow row = table.NewRow();

                for (int i = 0; i < table.Columns.Count; i++)
                {
                    row[table.Columns[i].ColumnName] = PropertyReflection.GetPropertyValue <T>(obj, columnsFunc[i]);
                }
                table.Rows.Add(row);
            }
            return(table);
        }