-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
BooleanConverterTests.cs
69 lines (58 loc) · 2.64 KB
/
BooleanConverterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2009-2017 Josh Close and Contributors
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
using System.Globalization;
using CsvHelper.Configuration;
using CsvHelper.TypeConversion;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace CsvHelper.Tests.TypeConversion
{
[TestClass]
public class BooleanConverterTests
{
[TestMethod]
public void ConvertToStringTest()
{
var converter = new BooleanConverter();
var propertyMapData = new MemberMapData( null )
{
TypeConverter = converter,
TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture }
};
Assert.AreEqual( "True", converter.ConvertToString( true, null, propertyMapData ) );
Assert.AreEqual( "False", converter.ConvertToString( false, null, propertyMapData ) );
Assert.AreEqual( "", converter.ConvertToString( null, null, propertyMapData ) );
Assert.AreEqual( "1", converter.ConvertToString( 1, null, propertyMapData ) );
}
[TestMethod]
public void ConvertFromStringTest()
{
var converter = new BooleanConverter();
var propertyMapData = new MemberMapData( null );
propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture;
var mockRow = new Mock<IReaderRow>();
Assert.IsTrue( (bool)converter.ConvertFromString( "true", null, propertyMapData ) );
Assert.IsTrue( (bool)converter.ConvertFromString( "True", null, propertyMapData ) );
Assert.IsTrue( (bool)converter.ConvertFromString( "TRUE", null, propertyMapData ) );
Assert.IsTrue( (bool)converter.ConvertFromString( "1", null, propertyMapData ) );
Assert.IsTrue( (bool)converter.ConvertFromString( " true ", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( "false", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( "False", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( "FALSE", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( "0", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( " false ", null, propertyMapData ) );
Assert.IsFalse( (bool)converter.ConvertFromString( " 0 ", null, propertyMapData ) );
try
{
converter.ConvertFromString( null, mockRow.Object, propertyMapData );
Assert.Fail();
}
catch( TypeConverterException )
{
}
}
}
}