Created
January 26, 2011 16:41
-
-
Save underwhelmed/796968 to your computer and use it in GitHub Desktop.
How I would implement storing the record line with the storage object using FileHelpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using FileHelpers; | |
using NUnit.Framework; | |
namespace FileHelpers.Tests.Converters | |
{ | |
[TestFixture] | |
public class RecordStringConverter.cs | |
{ | |
FileHelperEngine<UserRecord> engine = new FileHelperEngine<UserRecord>(); | |
[Test] | |
public void Test(); | |
{ | |
string sampleData = | |
@"123456;Phillip ;Fry | |
098765;Turanga ;Leela | |
110110;Bender ;Rodriguez | |
INVALID ID FOR MY DATA SET;Zapp ;Brannigan"; | |
UserRecord[] users = engine.ReadString(sampleData); | |
foreach (var user in users) | |
{ | |
int login; | |
if (!int.TryParse(user.LoginId, out login)) | |
{ | |
Assert.AreEqual("INVALID ID FOR MY DATA SET;Zapp ;Brannigan", user.RecordString) //NOTE the spaces | |
} | |
} | |
} | |
[DelimitedRecord(";")] | |
private class UserRecord | |
{ | |
[FieldTrim(TrimMode.Both)] | |
public string LoginId; | |
[FieldTrim(TrimMode.Both)] | |
public string FirstName; | |
[FieldTrim(TrimMode.Both)] | |
public string LastName; | |
//possible implementation | |
//[RecordString] | |
//public string RecordString; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment