예제 #1
0
        public void MapperReturnsObject()
        {
            // Arrange
            var id            = MapperTestHelpers.CreateImportDefinition();
            var ir            = MapperTestHelpers.CreateImportResult();
            var substitutions = MapperTestHelpers.CreateSubstitutions();

            var mapper = new ToClass <ToClassTestClass>(id);

            // Act
            var result = mapper.Map(ir, substitutions);

            // Assert
            Assert.AreEqual(1, result.Count);
            var item = result[0];

            Assert.IsTrue(item.ABoolean);
            Assert.AreEqual(1, item.AByte);
            Assert.AreEqual('z', item.ACharacter);
            Assert.AreEqual(new DateTime(1929, 06, 12, 11, 30, 15, DateTimeKind.Utc), item.ADateTime);
            Assert.AreEqual(654.321m, item.ADecimal);
            Assert.AreEqual(-123.456d, Math.Round(item.ADouble, 3));
            Assert.AreEqual(Guid.Parse("C506A057-9EAD-422D-BADE-C5E3E1A97F62"), item.AGuid);
            Assert.AreEqual(-32768, item.AnInt16);
            Assert.AreEqual(-2147483648, item.AnInt32);
            Assert.AreEqual(-9223372036854775808, item.AnInt64);
            Assert.AreEqual("This is an imported string.", item.AString);

            Assert.AreEqual(true, item.DestinationBoolean);
            Assert.AreEqual(254, item.DestinationByte);
            Assert.AreEqual('a', item.DestinationChar);
            Assert.AreEqual(new DateTime(2018, 01, 01, 05, 00, 00, DateTimeKind.Utc), item.DestinationDateTime);
            Assert.AreEqual(123.456m, item.DestinationDecimal);
            Assert.AreEqual(1.23d, Math.Round(item.DestinationDouble, 2));
            Assert.AreEqual(Guid.Parse("4732B277-11B3-440D-9327-1E2E6613746C"), item.DestinationGuid);
            Assert.AreEqual(32767, item.DestinationINT16);
            Assert.AreEqual(2147483647, item.DestinationINT32);
            Assert.AreEqual(9223372036854775807, item.DestinationINT64);
            Assert.AreEqual("This is a string.", item.DestinationString);

            Assert.AreEqual(true, item.DestinationSubstituteBoolean);
            Assert.AreEqual(100, item.DestinationSubstituteByte);
            Assert.AreEqual('G', item.DestinationSubstituteChar);
            Assert.AreEqual(new DateTime(1776, 07, 04, 12, 00, 00, DateTimeKind.Utc), item.DestinationSubstituteDateTime);
            Assert.AreEqual(987.123m, item.DestinationSubstituteDecimal);
            Assert.AreEqual(852.147d, Math.Round(item.DestinationSubstituteDouble, 3));
            Assert.AreEqual(Guid.Parse("C02070CE-698B-4DC3-8D67-C182A772AE7D"), item.DestinationSubstituteGuid);
            Assert.AreEqual(32000, item.DestinationSubstituteInt16);
            Assert.AreEqual(2147483000, item.DestinationSubstituteInt32);
            Assert.AreEqual(9223372036000000000, item.DestinationSubstituteInt64);
            Assert.AreEqual("This is a substituted string.", item.DestinationSubstituteString);

            Assert.IsTrue(item.DestinationGenerateGuid != Guid.Empty);
            Assert.IsTrue(item.DestinationGenerateDateOnly != DateTime.MinValue);
            Assert.IsTrue(item.DestinationGenerateDateTime != DateTime.MinValue);
        }
예제 #2
0
        public void MapReturnsDataSet()
        {
            // Arrange
            var id            = MapperTestHelpers.CreateImportDefinition();
            var ir            = MapperTestHelpers.CreateImportResult();
            var substitutions = MapperTestHelpers.CreateSubstitutions();

            var mapper = new ToDataSet(id);

            // Act
            var result = mapper.Map(ir, substitutions);

            // Assert
            Assert.AreEqual(1, result.Rows.Count);
            var dr = result.Rows[0];

            Assert.AreEqual(dr["ABoolean"], true);
            Assert.AreEqual(dr["ABoolean"].GetType(), typeof(bool));
            Assert.AreEqual((byte)dr["AByte"], 1);
            Assert.AreEqual(dr["AByte"].GetType(), typeof(byte));
            Assert.AreEqual((char)dr["ACharacter"], 'z');
            Assert.AreEqual(dr["ACharacter"].GetType(), typeof(char));
            Assert.AreEqual((DateTime)dr["ADateTime"], new DateTime(1929, 06, 12, 11, 30, 15, DateTimeKind.Utc));
            Assert.AreEqual(dr["ADateTime"].GetType(), typeof(DateTime));
            Assert.AreEqual((Decimal)dr["ADecimal"], 654.321m);
            Assert.AreEqual(dr["ADecimal"].GetType(), typeof(decimal));
            Assert.AreEqual(Math.Round((double)dr["ADouble"], 3), Math.Round(-123.456f, 3));
            Assert.AreEqual(dr["ADouble"].GetType(), typeof(double));
            Assert.AreEqual((Guid)dr["AGuid"], Guid.Parse("C506A057-9EAD-422D-BADE-C5E3E1A97F62"));
            Assert.AreEqual(dr["AGuid"].GetType(), typeof(Guid));
            Assert.AreEqual((Int16)dr["AnInt16"], -32768);
            Assert.AreEqual(dr["AnInt16"].GetType(), typeof(Int16));
            Assert.AreEqual((Int32)dr["AnInt32"], -2147483648);
            Assert.AreEqual(dr["AnInt32"].GetType(), typeof(Int32));
            Assert.AreEqual((Int64)dr["AnInt64"], -9223372036854775808);
            Assert.AreEqual(dr["AnInt64"].GetType(), typeof(Int64));
            Assert.AreEqual((string)dr["AString"], "This is an imported string.");
            Assert.AreEqual(dr["AString"].GetType(), typeof(string));

            Assert.AreEqual((bool)dr["DestinationBoolean"], true);
            Assert.AreEqual(dr["DestinationBoolean"].GetType(), typeof(bool));
            Assert.AreEqual((byte)dr["DestinationByte"], 254);
            Assert.AreEqual(dr["DestinationByte"].GetType(), typeof(byte));
            Assert.AreEqual((char)dr["DestinationChar"], 'a');
            Assert.AreEqual(dr["DestinationChar"].GetType(), typeof(char));
            Assert.AreEqual((DateTime)dr["DestinationDateTime"], new DateTime(2018, 01, 01, 05, 00, 00, DateTimeKind.Utc));
            Assert.AreEqual(dr["DestinationDateTime"].GetType(), typeof(DateTime));
            Assert.AreEqual((Decimal)dr["DestinationDecimal"], 123.456m);
            Assert.AreEqual(dr["DestinationDecimal"].GetType(), typeof(Decimal));
            Assert.AreEqual(Math.Round((double)dr["DestinationDouble"], 2), Math.Round(1.23f, 2));
            Assert.AreEqual(dr["DestinationDouble"].GetType(), typeof(Double));
            Assert.AreEqual((Guid)dr["DestinationGuid"], Guid.Parse("4732B277-11B3-440D-9327-1E2E6613746C"));
            Assert.AreEqual(dr["DestinationGuid"].GetType(), typeof(Guid));
            Assert.AreEqual((Int16)dr["DestinationINT16"], 32767);
            Assert.AreEqual(dr["DestinationINT16"].GetType(), typeof(Int16));
            Assert.AreEqual((Int32)dr["DestinationINT32"], 2147483647);
            Assert.AreEqual(dr["DestinationINT32"].GetType(), typeof(Int32));
            Assert.AreEqual((Int64)dr["DestinationINT64"], 9223372036854775807);
            Assert.AreEqual(dr["DestinationINT64"].GetType(), typeof(Int64));
            Assert.AreEqual((string)dr["DestinationString"], "This is a string.");
            Assert.AreEqual(dr["DestinationString"].GetType(), typeof(string));

            Assert.AreNotEqual((Guid)dr["DestinationGenerateGuid"], Guid.Empty);
            Assert.AreEqual(dr["DestinationGenerateGuid"].GetType(), typeof(Guid));
            Assert.AreNotEqual((DateTime)dr["DestinationGenerateDateOnly"], DateTime.MinValue);
            Assert.AreEqual(dr["DestinationGenerateDateOnly"].GetType(), typeof(DateTime));
            Assert.AreNotEqual((DateTime)dr["DestinationGenerateDateTime"], DateTime.MinValue);
            Assert.AreEqual(dr["DestinationGenerateDateTime"].GetType(), typeof(DateTime));
        }