public void ClassAttributeTest_NotSpecifyingTargetPropertyType_ResultsInAnException()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <ClassPropertyToDataTableColumnMapperTestData5>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.Fail("You should get an error for not specifying a TargetPropertyType!");
        }
Пример #2
0
        public void PropertyTest_ClassesMustBeMarkedWithIgnore_ResultsInAnException()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <PropertyMapClassTest>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.Fail($"You must mark properties with class types with the {nameof(ClassToDataTableAttribute)} Ignore property or you get an exception.");
        }
        public void InterfaceTest_ConvertersMustImplement_IClassToDataTableConverter_ResultsInAnException()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <ClassPropertyToDataTableColumnMapperTestData3>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.Fail("Converter must implement IClassToDataTableConverter!");
        }
        public void OutputTypeTest_CannotBeAClass_ResultsInAnException()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <ClassPropertyToDataTableColumnMapperTestData2>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.Fail("OutputType Cannot Be a class!");
        }
        public void ConverterOnClass_ValidConverterWorks_NoExceptions()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <ClassPropertyToDataTableColumnMapperTestData6>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.AreEqual(2, theTable.Columns.Count, "Column count is wrong in the DataTable");
            TestDataType(theTable, "SomeTestProperty", typeof(decimal));
            TestDataType(theTable, "SomeIntProperty", typeof(int));
        }
Пример #6
0
        public void PropertyTest_CanIgnoreClassProperty_DataTableDoesNotContainTheIgnoredField()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <PropertyMapIgnoreTest>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.AreEqual(1, theTable.Columns.Count, "Column count is wrong in the DataTable");
            TestColumn(theTable, "SomeIntProperty", typeof(int));
            Assert.IsNull(theTable.Columns["SomeIntArrayProperty"], "The SomeIntArrayProperty property should have been ignored!");
            Assert.IsNull(theTable.Columns["SomeClassProperty"], "The SomeClassProperty property should have been ignored!");
        }
        public void Map_ClassCanHaveClassPropertyTypeWithoutIgnoreIfConfiguratoinSetttingIsUsed_NoException()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <ClassPropertyToDataTableColumnMapperTestData8>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration()
            {
                IgnoreInvalidTypes = true
            });

            // Assert
            Assert.AreEqual(1, mapList.Count);
            TestDataType(theTable, "SomeIntProperty", typeof(int));
        }
Пример #8
0
        public void PropertyTest_CanMapPrimitiveTypesToDataTable_DataTableHasNonNullableVersionOfPrimitiveTypes()
        {
            // Arrange
            var theTable       = new DataTable();
            var classUnderTest = new ClassPropertyToDataTableColumnMapper <PropertyMapPrimitiveTest>();

            // Act
            List <ClassPropertyToDataTableColumnMap> mapList = classUnderTest.Map(theTable, new ClassToDataTableConfiguration());

            // Assert
            Assert.AreEqual(9, theTable.Columns.Count, "Column count is wrong in the DataTable");
            TestColumn(theTable, "SomeIntProperty", typeof(int));
            TestColumn(theTable, "SomeNullableIntProperty", typeof(int));  // Converted to underlying type!
            TestColumn(theTable, "SomeStringProperty", typeof(string));
            TestColumn(theTable, "SomeDoubleProperty", typeof(double));
            TestColumn(theTable, "SomeNullableDoubleProperty", typeof(double));   // Converted to underlying type!
            TestColumn(theTable, "SomeDecimalProperty", typeof(decimal));
            TestColumn(theTable, "SomeNullableDecimalProperty", typeof(decimal)); // Converted to underlying type!
            TestColumn(theTable, "SomeCharProperty", typeof(char));
            TestColumn(theTable, "SomeNullableCharProperty", typeof(char));       // Converted to underlying type!
        }