예제 #1
0
        public void ReferenceMappingTest()
        {
            var parserMock = new ParserMock
            {
                {
                    "FirstName",
                    "LastName",
                    "HomeStreet",
                    "HomeCity",
                    "HomeState",
                    "HomeZip",
                    "WorkStreet",
                    "WorkCity",
                    "WorkState",
                    "WorkZip"
                },
            };
            var row = new[]
            {
                "John",
                "Doe",
                "1234 Home St",
                "Home Town",
                "Home State",
                "12345",
                "5678 Work Rd",
                "Work City",
                "Work State",
                "67890"
            };

            parserMock.Add(row);

            var reader = new CsvReader(parserMock);

            reader.Context.RegisterClassMap <PersonMap>();
            reader.Read();
            var person = reader.GetRecord <Person>();

            Assert.Equal(row[0], person.FirstName);
            Assert.Equal(row[1], person.LastName);
            Assert.Equal(row[2], person.HomeAddress.Street);
            Assert.Equal(row[3], person.HomeAddress.City);
            Assert.Equal(row[4], person.HomeAddress.State);
            Assert.Equal(row[5], person.HomeAddress.Zip);
            Assert.Equal(row[6], person.WorkAddress.Street);
            Assert.Equal(row[7], person.WorkAddress.City);
            Assert.Equal(row[8], person.WorkAddress.State);
            Assert.Equal(row[9], person.WorkAddress.Zip);
        }