public void AssertHeaderPrintsOnlyWhenRequested() { // Arrange var serializer = new Serializer { Settings = new CsvSettings { WriteHeaders = false } }; var person = new Person { FirstName = "Nate \"D\"", LastName = "Zaugg" }; var ms = new MemoryStream(); string expected = "\"Nate \"\"D\"\"\",Zaugg\r\n"; string actual; // Act serializer.Serialize(ms, person); actual = Encoding.UTF8.GetString(ms.ToArray()); // Assert Assert.AreEqual(expected, actual); }
public void AssertLinesEndWithCorrectLineEnding() { // Arrange var serializer = new Serializer { Settings = new CsvSettings { NewLineDelimeter = "\n" } }; var person = new Person { FirstName = "Nate \"D\"", LastName = "Zaugg" }; var ms = new MemoryStream(); string expected = "FirstName,LastName\n\"Nate \"\"D\"\"\",Zaugg\n"; string actual; // Act serializer.Serialize(ms, person); actual = Encoding.UTF8.GetString(ms.ToArray()); // Assert Assert.AreEqual(expected, actual); }
public void AssertValuesWithCamasReceiveQuotes() { // Arrange var serializer = new Serializer(); var person = new Person { FirstName = "Nate", LastName = "Dr, Zaugg" }; var ms = new MemoryStream(); string expected = "FirstName,LastName\r\nNate,\"Dr, Zaugg\"\r\n"; string actual; // Act serializer.Serialize(ms, person); actual = Encoding.UTF8.GetString(ms.ToArray()); // Assert Assert.AreEqual(expected, actual); }
public void AssertValuesWithLineEndingsDoTheRightThing() { // Arrange var serializer = new Serializer { Settings = new CsvSettings { RemoveLineBreaksInFields = false } }; var person = new Person { FirstName = "Nate", LastName = "Dr\r\n Zaugg" }; var ms = new MemoryStream(); string expected = "FirstName,LastName\r\nNate,\"Dr\r\n Zaugg\"\r\n"; string actual; // Act serializer.Serialize(ms, person); actual = Encoding.UTF8.GetString(ms.ToArray()); // Assert Assert.AreEqual(expected, actual); }
public void IntegrationTestSimpleObject() { // Arrange var serializer = new Serializer(); var person = new Person { FirstName = "Nate \"D\"", LastName = "Zaugg" }; var ms = new MemoryStream(); string expected = "FirstName,LastName\r\n\"Nate \"\"D\"\"\",Zaugg\r\n"; string actual; // Act serializer.Serialize(ms, person); actual = Encoding.UTF8.GetString(ms.ToArray()); // Assert Assert.AreEqual(expected, actual); }