Skip to content

Instantly share code, notes, and snippets.

@SuperJMN
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuperJMN/66d0ca15c04d8efaa0a5 to your computer and use it in GitHub Desktop.
Save SuperJMN/66d0ca15c04d8efaa0a5 to your computer and use it in GitHub Desktop.
ServiceStack.Text testing separator issue
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ServiceStack.Text;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
private readonly List<Person> people = new List<Person>
{
new Person
{
Age = new decimal(33.45),
Name = "José Manuel",
}
};
// both differ only in the separator.
private const string ExpectedTest2 = "Age;Name\r\n33.45;José Manuel\r\n";
private const string ExpectedTest1 = "Age;Name\r\n33,45;José Manuel\r\n";
[TestInitialize]
public void TestInitilize()
{
CsvConfig.Reset();
}
/// <summary>
/// THIS FAILS!
/// </summary>
[TestMethod]
public void UseCommaAsDecimalSeparator_ModifyingSerializeFn()
{
CsvConfig.ItemSeperatorString = ";";
JsConfig<decimal>.SerializeFn = d => d.ToString("0.00");
var serializationResult = CsvSerializer.SerializeToCsv(people);
Assert.AreEqual(ExpectedTest1, serializationResult);
}
/// <summary>
/// This behaves correctly
/// </summary>
[TestMethod]
public void WantToUsePointAsDecimalSeparator_NotModifyingDefaultBehavior()
{
CsvConfig.ItemSeperatorString = ";";
var serializationResult = CsvSerializer.SerializeToCsv(people);
Assert.AreEqual(ExpectedTest2, serializationResult);
}
}
internal class Person
{
public decimal Age { get; set; }
public string Name { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment