diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute')
46 files changed, 1787 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/AllowCommentsTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/AllowCommentsTests.cs new file mode 100644 index 0000000..e5fb1eb --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/AllowCommentsTests.cs @@ -0,0 +1,29 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class AllowCommentsTests + { + [Fact] + public void AllowCommentsTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(AllowCommentsTestClass)); + Assert.True(config.AllowComments); + } + + [AllowComments(true)] + private class AllowCommentsTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BooleanValuesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BooleanValuesTests.cs new file mode 100644 index 0000000..b2eefde --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BooleanValuesTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class BooleanValuesTests + { + [Fact] + public void BooleanValuesTest() + { + using (var reader = new StringReader("IsTrue,IsFalse\r\ntrue,false\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<BooleanValuesTestClass>().ToList(); + Assert.Equal(true, records[0].IsTrue); + Assert.Equal(false, records[0].IsFalse); + } + } + + private class BooleanValuesTestClass + { + [BooleanTrueValues("true")] + public bool? IsTrue { get; set; } + + [BooleanFalseValues("false")] + public bool? IsFalse { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BufferSizeTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BufferSizeTests.cs new file mode 100644 index 0000000..dd35498 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/BufferSizeTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class BufferSizeTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(2, config.BufferSize); + } + + [BufferSize(2)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CacheFieldsTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CacheFieldsTests.cs new file mode 100644 index 0000000..bfc1c52 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CacheFieldsTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class CacheFieldsTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.CacheFields); + } + + [CacheFields(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CommentTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CommentTests.cs new file mode 100644 index 0000000..64baf14 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CommentTests.cs @@ -0,0 +1,28 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class CommentTests + { + [Fact] + public void CommentTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(CommentTestClass)); + Assert.Equal('x', config.Comment); + } + + [Comment('x')] + private class CommentTestClass + { + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ConstantTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ConstantTests.cs new file mode 100644 index 0000000..5ab6381 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ConstantTests.cs @@ -0,0 +1,50 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class ConstantTests + { + [Fact] + public void ConstantTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<ConstantTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("two", records[0].Name); + } + } + + [Fact] + public void ConstantOnMissingFieldTest() + { + using (var reader = new StringReader("Id\r\n1\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<ConstantTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("two", records[0].Name); + } + } + + private class ConstantTestClass + { + public int Id { get; set; } + + [Constant("two")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CountBytesTest.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CountBytesTest.cs new file mode 100644 index 0000000..c4847cd --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/CountBytesTest.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class CountBytesTest + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.CountBytes); + } + + [CountBytes(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DateTimeStylesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DateTimeStylesTests.cs new file mode 100644 index 0000000..3e5a25d --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DateTimeStylesTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class DateTimeStylesTests + { + [Fact] + public void DateTimeStylesTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<DateTimeStylesTestClass>().ToList(); + var actual = csv.Context.Maps.Find<DateTimeStylesTestClass>().MemberMaps[1].Data.TypeConverterOptions.DateTimeStyle; + + Assert.Equal(DateTimeStyles.AdjustToUniversal, actual); + } + } + + private class DateTimeStylesTestClass + { + public int Id { get; set; } + + [DateTimeStyles(DateTimeStyles.AdjustToUniversal)] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DefaultTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DefaultTests.cs new file mode 100644 index 0000000..4718c66 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DefaultTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class DefaultTests + { + [Fact] + public void DefaultTest() + { + using (var reader = new StringReader("Id,Name\r\n1,\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<DefaultTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("one", records[0].Name); + } + } + + private class DefaultTestClass + { + public int Id { get; set; } + + [Default("one")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DelimiterTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DelimiterTests.cs new file mode 100644 index 0000000..3315126 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DelimiterTests.cs @@ -0,0 +1,32 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class DelimiterTests + { + [Fact] + public void DelimiterReaderTest() + { + var configuration = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(DelimiterTestClass)); + + Assert.Equal("§", configuration.Delimiter); + } + + [Delimiter("§")] + private class DelimiterTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectColumnCountChangesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectColumnCountChangesTests.cs new file mode 100644 index 0000000..4fad816 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectColumnCountChangesTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class DetectColumnCountChangesTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.DetectColumnCountChanges); + } + + [DetectColumnCountChanges(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterTests.cs new file mode 100644 index 0000000..1ccc0fb --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class DetectDelimiterTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.DetectDelimiter); + } + + [DetectDelimiter(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterValuesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterValuesTests.cs new file mode 100644 index 0000000..a160001 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterValuesTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class DetectDelimiterValuesTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(new[] { "a", "b" }, config.DetectDelimiterValues); + } + + [DetectDelimiterValues("a b")] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EncodingTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EncodingTests.cs new file mode 100644 index 0000000..557775b --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EncodingTests.cs @@ -0,0 +1,33 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class EncodingTests + { + [Fact] + public void EncodingTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(EncodingTestClass)); + + Assert.Equal(Encoding.ASCII, config.Encoding); + } + + [Encoding("ASCII")] + private class EncodingTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EnumIgnoreCaseTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EnumIgnoreCaseTests.cs new file mode 100644 index 0000000..e12f3cd --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EnumIgnoreCaseTests.cs @@ -0,0 +1,91 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using CsvHelper.TypeConversion; +using Xunit; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class EnumIgnoreCaseTests + { + [Fact] + public void GetRecords_UsingEnumIgnoreCaseFromClassMap_ReadsEnumValueWithDifferentCasing() + { + var s = new StringBuilder(); + s.Append("Id,Enum\r\n"); + s.Append("1,one"); + using (var reader = new StringReader(s.ToString())) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + csv.Context.RegisterClassMap<FooMap>(); + var records = csv.GetRecords<Foo>().ToList(); + } + } + + [Fact] + public void GetRecords_UsingEnumIgnoreCaseFromAttribute_ReadsEnumValueWithDifferentCasing() + { + var s = new StringBuilder(); + s.Append("Id,Enum\r\n"); + s.Append("1,one"); + using (var reader = new StringReader(s.ToString())) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<Bar>().ToList(); + } + } + + [Fact] + public void GetRecords_UsingEnumIgnoreCaseFromGlobal_ReadsEnumValueWithDifferentCasing() + { + var s = new StringBuilder(); + s.Append("Id,Enum\r\n"); + s.Append("1,one"); + using (var reader = new StringReader(s.ToString())) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + csv.Context.TypeConverterOptionsCache.AddOptions<TestEnum>(new TypeConverterOptions { EnumIgnoreCase = true }); + var records = csv.GetRecords<Foo>().ToList(); + } + } + + private class Foo + { + public int Id { get; set; } + public TestEnum Enum { get; set; } + } + + private class FooMap : ClassMap<Foo> + { + public FooMap() + { + Map(m => m.Id); + Map(m => m.Enum).TypeConverterOption.EnumIgnoreCase(); + } + } + + private class Bar + { + public int Id { get; set; } + [EnumIgnoreCase] + public TestEnum Enum { get; set; } + } + + private enum TestEnum + { + None = 0, + One = 1 + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EscapeTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EscapeTests.cs new file mode 100644 index 0000000..b3c3e7f --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/EscapeTests.cs @@ -0,0 +1,32 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class EscapeTests + { + [Fact] + public void EscapeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(EscapeTestClass)); + + Assert.Equal('x', config.Escape); + } + + [Escape('x')] + private class EscapeTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ExceptionMessagesContainRawDataTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ExceptionMessagesContainRawDataTests.cs new file mode 100644 index 0000000..ce3688e --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ExceptionMessagesContainRawDataTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class ExceptionMessagesContainRawDataTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.False(config.ExceptionMessagesContainRawData); + } + + [ExceptionMessagesContainRawData(false)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/FormatTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/FormatTests.cs new file mode 100644 index 0000000..c2e2b5f --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/FormatTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class FormatTests + { + [Fact] + public void FormatTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<FormatTestClass>().ToList(); + var actual = csv.Context.Maps.Find<FormatTestClass>().MemberMaps[1].Data.TypeConverterOptions.Formats[0]; + + Assert.Equal("abc", actual); + } + } + + private class FormatTestClass + { + public int Id { get; set; } + + [Format("abc")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HasHeaderRecordTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HasHeaderRecordTests.cs new file mode 100644 index 0000000..9fae872 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HasHeaderRecordTests.cs @@ -0,0 +1,30 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class HasHeaderRecordTests + { + [Fact] + public void HasHeaderRecordTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(HasHeaderRecordTestClass)); + + Assert.False(config.HasHeaderRecord); + } + + [HasHeaderRecord(false)] + private class HasHeaderRecordTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HeaderPrefixTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HeaderPrefixTests.cs new file mode 100644 index 0000000..fe5cb61 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/HeaderPrefixTests.cs @@ -0,0 +1,205 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class HeaderPrefixTests + { + [Fact] + public void WriteHeader_PrefixCustom_WritesCustomPrefixesOwnLevelOnly() + { + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteHeader<ACustom>(); + csv.Flush(); + + Assert.Equal("AId,b_BId,c_CId", writer.ToString()); + } + } + + [Fact] + public void WriteHeader_PrefixInherit_WritesPrefixesForEachLevel() + { + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteHeader<AInherit>(); + csv.Flush(); + + Assert.Equal("AId,B.BId,B.C.CId", writer.ToString()); + } + } + + [Fact] + public void WriteHeader_PrefixNoInherit_WritesPrefixesOwnLevelOnly() + { + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteHeader<ANoInherit>(); + csv.Flush(); + + Assert.Equal("AId,B.BId,C.CId", writer.ToString()); + } + } + + [Fact] + public void WriteHeader_PrefixDefaultInherit_WritesPrefixesOwnLevelOnly() + { + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteHeader<ADefaultInherit>(); + csv.Flush(); + + Assert.Equal("AId,B.BId,C.CId", writer.ToString()); + } + } + + [Fact] + public void GetRecords_PrefixCustom_ReadsCustomHeader() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + var s = new TestStringBuilder(config.NewLine); + s.AppendLine("AId,b_BId,c_CId"); + s.AppendLine("aid,bid,cid"); + using (var reader = new StringReader(s)) + using (var csv = new CsvReader(reader, config)) + { + var records = csv.GetRecords<ACustom>().ToList(); + + Assert.Single(records); + Assert.Equal("aid", records[0].AId); + Assert.Equal("bid", records[0].B.BId); + Assert.Equal("cid", records[0].B.C.CId); + } + } + + [Fact] + public void GetRecords_PrefixInherit_ReadsInheritedHeader() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + var s = new TestStringBuilder(config.NewLine); + s.AppendLine("AId,B.BId,B.C.CId"); + s.AppendLine("aid,bid,cid"); + using (var reader = new StringReader(s)) + using (var csv = new CsvReader(reader, config)) + { + var records = csv.GetRecords<AInherit>().ToList(); + + Assert.Single(records); + Assert.Equal("aid", records[0].AId); + Assert.Equal("bid", records[0].B.BId); + Assert.Equal("cid", records[0].B.C.CId); + } + } + + [Fact] + public void GetRecords_PrefixNoInherit_ReadsNonInheritedHeader() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + var s = new TestStringBuilder(config.NewLine); + s.AppendLine("AId,B.BId,C.CId"); + s.AppendLine("aid,bid,cid"); + using (var reader = new StringReader(s)) + using (var csv = new CsvReader(reader, config)) + { + var records = csv.GetRecords<ANoInherit>().ToList(); + + Assert.Single(records); + Assert.Equal("bid", records[0].B.BId); + Assert.Equal("aid", records[0].AId); + Assert.Equal("cid", records[0].B.C.CId); + } + } + + [Fact] + public void GetRecords_PrefixDefaultInherit_ReadsNonInheritedHeader() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + var s = new TestStringBuilder(config.NewLine); + s.AppendLine("AId,B.BId,C.CId"); + s.AppendLine("aid,bid,cid"); + using (var reader = new StringReader(s)) + using (var csv = new CsvReader(reader, config)) + { + var records = csv.GetRecords<ADefaultInherit>().ToList(); + + Assert.Single(records); + Assert.Equal("aid", records[0].AId); + Assert.Equal("bid", records[0].B.BId); + Assert.Equal("cid", records[0].B.C.CId); + } + } + + private class ACustom + { + public string AId { get; set; } + [HeaderPrefix("b_")] + public BCustom B { get; set; } + } + + private class BCustom + { + public string BId { get; set; } + [HeaderPrefix("c_")] + public C C { get; set; } + } + + private class AInherit + { + public string AId { get; set; } + [HeaderPrefix(true)] + public BInherit B { get; set; } + } + + private class BInherit + { + public string BId { get; set; } + [HeaderPrefix(true)] + public C C { get; set; } + } + + private class ANoInherit + { + public string AId { get; set; } + [HeaderPrefix(false)] + public BInherit B { get; set; } + } + + private class BNoInherit + { + public string BId { get; set; } + [HeaderPrefix(false)] + public C C { get; set; } + } + + private class ADefaultInherit + { + public string AId { get; set; } + [HeaderPrefix] + public BInherit B { get; set; } + } + + private class BDefaultInherit + { + public string BId { get; set; } + [HeaderPrefix] + public C C { get; set; } + } + + private class C + { + public string CId { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBaseTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBaseTests.cs new file mode 100644 index 0000000..9f49082 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBaseTests.cs @@ -0,0 +1,71 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class IgnoreBaseTests + { + [Fact] + public void GetRecordsWithProperties_IgnoreBaseAttribute_DoesNotMapBaseClass() + { + var map = new DefaultClassMap<ChildProperties>(); + map.AutoMap(CultureInfo.InvariantCulture); + + Assert.Single(map.MemberMaps); + Assert.Null(map.MemberMaps.Find<ChildProperties>(m => m.Id)); + Assert.NotNull(map.MemberMaps.Find<ChildProperties>(m => m.Name)); + } + + [Fact] + public void GetRecordsWithFields_IgnoreBaseAttribute_DoesNotMapBaseClass() + { + var map = new DefaultClassMap<ChildFields>(); + map.AutoMap(new CsvConfiguration(CultureInfo.InvariantCulture) + { + MemberTypes = MemberTypes.Fields, + }); + + Assert.Single(map.MemberMaps); + Assert.Null(map.MemberMaps.Find<ChildFields>(m => m.Id)); + Assert.NotNull(map.MemberMaps.Find<ChildFields>(m => m.Name)); + } + + private class ParentProperties + { + public int Id { get; set; } + } + + [IgnoreBase] + private class ChildProperties : ParentProperties + { + public string Name { get; set; } + } + + private class ParentFields + { +#pragma warning disable CS0649 + public int Id; +#pragma warning restore CS0649 + } + + [IgnoreBase] + private class ChildFields: ParentFields + { +#pragma warning disable CS0649 + public string Name; +#pragma warning restore CS0649 + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBlankLinesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBlankLinesTests.cs new file mode 100644 index 0000000..b2ec8e0 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBlankLinesTests.cs @@ -0,0 +1,36 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class IgnoreBlankLinesTests + { + [Fact] + public void IgnoreBlankLinesTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<IgnoreBlankLinesTestClass>().ToList(); + var actual = csv.Configuration.IgnoreBlankLines; + + Assert.True(actual); + } + } + + [IgnoreBlankLines(true)] + private class IgnoreBlankLinesTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreReferencesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreReferencesTests.cs new file mode 100644 index 0000000..f2839b6 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreReferencesTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class IgnoreReferencesTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.IgnoreReferences); + } + + [IgnoreReferences(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreTests.cs new file mode 100644 index 0000000..4849ad1 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreTests.cs @@ -0,0 +1,93 @@ +// Copyright 2009-2022 Josh Close +// 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 Xunit; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class IgnoreTests + { + [Fact] + public void IgnoreTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<Foo>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("one", records[0].Name); + } + } + + [Fact] + public void IgnoreReferenceTest() + { + var records = new List<Parent> + { + new Parent + { + Id = 1, + Child = new Child + { + Name = "one", + GrandChild = new GrandChild + { + Date = DateTimeOffset.Now + } + } + } + }; + + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteRecords(records); + + var expected = new TestStringBuilder(csv.Configuration.NewLine); + expected.AppendLine("Id"); + expected.AppendLine("1"); + + Assert.Equal(expected.ToString(), writer.ToString()); + } + } + + private class Foo + { + public int Id { get; set; } + + public string Name { get; set; } + + [CsvHelper.Configuration.Attributes.Ignore] + public DateTime Date { get; set; } + } + + private class Parent + { + public int Id { get; set; } + + [CsvHelper.Configuration.Attributes.Ignore] + public Child Child { get; set; } + } + + private class Child + { + public string Name { get; set; } + + public GrandChild GrandChild { get; set; } + } + + private class GrandChild + { + public DateTimeOffset Date { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IncludePrivateMembersTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IncludePrivateMembersTests.cs new file mode 100644 index 0000000..2b219dc --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IncludePrivateMembersTests.cs @@ -0,0 +1,29 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class IncludePrivateMembersTests + { + [Fact] + public void TrimOptionsTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(IncludePrivateMembersTestClass)); + Assert.True(config.IncludePrivateMembers); + } + + [IncludePrivateMembers(true)] + private class IncludePrivateMembersTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IndexTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IndexTests.cs new file mode 100644 index 0000000..1dc9112 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/IndexTests.cs @@ -0,0 +1,42 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class IndexTests + { + [Fact] + public void IndexTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture) + { + HasHeaderRecord = false, + }; + using (var reader = new StringReader("a,1,b,one,c\r\n")) + using (var csv = new CsvReader(reader, config)) + { + var records = csv.GetRecords<IndexTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("one", records[0].Name); + } + } + + private class IndexTestClass + { + [Index(1)] + public int Id { get; set; } + + [Index(3)] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionCharactersTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionCharactersTests.cs new file mode 100644 index 0000000..b4fc82c --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionCharactersTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class InjectionCharactersTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(new[] { 'a', 'b' }, config.InjectionCharacters); + } + + [InjectionCharacters("a b")] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionEscapeCharacterTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionEscapeCharacterTests.cs new file mode 100644 index 0000000..e118ea2 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionEscapeCharacterTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class InjectionEscapeCharacterTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal('a', config.InjectionEscapeCharacter); + } + + [InjectionEscapeCharacter('a')] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionOptionsTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionOptionsTests.cs new file mode 100644 index 0000000..7a03003 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/InjectionOptionsTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class InjectionOptionsTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(InjectionOptions.Escape, config.InjectionOptions); + } + + [InjectionOptions(InjectionOptions.Escape)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/LineBreakInQuotedFieldIsBadDataTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/LineBreakInQuotedFieldIsBadDataTests.cs new file mode 100644 index 0000000..b939780 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/LineBreakInQuotedFieldIsBadDataTests.cs @@ -0,0 +1,25 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class LineBreakInQuotedFieldIsBadDataTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.True(config.LineBreakInQuotedFieldIsBadData); + } + + [LineBreakInQuotedFieldIsBadData(true)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MaxFieldSizeTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MaxFieldSizeTests.cs new file mode 100644 index 0000000..b0a9231 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MaxFieldSizeTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class MaxFieldSizeTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(2, config.MaxFieldSize); + } + + [MaxFieldSize(2)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MemberTypesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MemberTypesTests.cs new file mode 100644 index 0000000..be21b32 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/MemberTypesTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class MemberTypesTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(MemberTypes.Fields, config.MemberTypes); + } + + [MemberTypes(MemberTypes.Fields)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ModeTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ModeTests.cs new file mode 100644 index 0000000..ca35863 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ModeTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class ModeTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(CsvMode.Escape, config.Mode); + } + + [Mode(CsvMode.Escape)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameIndexTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameIndexTests.cs new file mode 100644 index 0000000..07cda20 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameIndexTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class NameIndexTests + { + [Fact] + public void NameIndexTest() + { + using (var reader = new StringReader("Id,Name,Name\r\n1,one,two\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<NameIndexClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("two", records[0].Name); + } + } + + private class NameIndexClass + { + public int Id { get; set; } + + [NameIndex(1)] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameTests.cs new file mode 100644 index 0000000..3957442 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NameTests.cs @@ -0,0 +1,38 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class NameTests + { + [Fact] + public void NameTest() + { + using (var reader = new StringReader("id,name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<NameTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("one", records[0].Name); + } + } + + private class NameTestClass + { + [Name("id")] + public int Id { get; set; } + + [Name("name")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NewLineTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NewLineTests.cs new file mode 100644 index 0000000..5d9ba80 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NewLineTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class NewLineTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal("a", config.NewLine); + } + + [NewLine("a")] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NullValuesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NullValuesTests.cs new file mode 100644 index 0000000..8694172 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NullValuesTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class NullValuesTests + { + [Fact] + public void NullValuesTest() + { + using (var reader = new StringReader("Id,Name\r\nNULL,null\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<NullValuesTestClass>().ToList(); + Assert.Null(records[0].Id); + Assert.Null(records[0].Name); + } + } + + private class NullValuesTestClass + { + [NullValues("NULL")] + public int? Id { get; set; } + + [NullValues("null")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NumberStylesTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NumberStylesTests.cs new file mode 100644 index 0000000..3740f54 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/NumberStylesTests.cs @@ -0,0 +1,37 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class NumberStylesTests + { + [Fact] + public void DateTimeStylesTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<NumberStylesTestClass>().ToList(); + var actual = csv.Context.Maps.Find<NumberStylesTestClass>().MemberMaps[1].Data.TypeConverterOptions.NumberStyles; + + Assert.Equal(NumberStyles.AllowCurrencySymbol, actual); + } + } + + private class NumberStylesTestClass + { + public int Id { get; set; } + + [NumberStyles(NumberStyles.AllowCurrencySymbol)] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/OptionalTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/OptionalTests.cs new file mode 100644 index 0000000..466e6b5 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/OptionalTests.cs @@ -0,0 +1,41 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using CsvHelper.Tests.Mocks; +using Xunit; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class OptionalTests + { + [Fact] + public void OptionalTest() + { + var parser = new ParserMock + { + { "Id" }, + { "1" }, + }; + + using (var csv = new CsvReader(parser)) + { + var records = csv.GetRecords<OptionalTestClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Null(records[0].Name); + } + } + + private class OptionalTestClass + { + public int Id { get; set; } + + [Optional] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ProcessFieldBufferSizeTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ProcessFieldBufferSizeTests.cs new file mode 100644 index 0000000..63ea433 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ProcessFieldBufferSizeTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class ProcessFieldBufferSizeTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(2, config.ProcessFieldBufferSize); + } + + [ProcessFieldBufferSize(2)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/QuoteTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/QuoteTests.cs new file mode 100644 index 0000000..3b6fb41 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/QuoteTests.cs @@ -0,0 +1,29 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class QuoteTests + { + [Fact] + public void QuoteTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(QuoteTestClass)); + Assert.Equal('x', config.Quote); + } + + [Quote('x')] + private class QuoteTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ReferenceTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ReferenceTests.cs new file mode 100644 index 0000000..97c64a0 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/ReferenceTests.cs @@ -0,0 +1,43 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration.Attributes; +using Xunit; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class ReferenceTests + { + [Fact] + public void ReferenceTest() + { + using (var reader = new StringReader("id,name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<ReferenceTestClassA>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("one", records[0].B.Name); + } + } + + private class ReferenceTestClassA + { + [Name("id")] + public int Id { get; set; } + + public ReferenceTestClassB B { get; set; } + } + + private class ReferenceTestClassB + { + [Name("name")] + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TrimOptionsTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TrimOptionsTests.cs new file mode 100644 index 0000000..6e7595f --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TrimOptionsTests.cs @@ -0,0 +1,31 @@ +// Copyright 2009-2015 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. +// http://csvhelper.com +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using System.IO; +using System.Linq; +using Xunit; + +namespace CsvHelper.Tests.AttributeMapping +{ + public class TrimOptionsTests + { + [Fact] + public void TrimOptionsTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(TrimOptionsTestClass)); + Assert.Equal(TrimOptions.InsideQuotes, config.TrimOptions); + } + + [TrimOptions(TrimOptions.InsideQuotes)] + private class TrimOptionsTestClass + { + public int Id { get; set; } + + public string Name { get; set; } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TypeConverterTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TypeConverterTests.cs new file mode 100644 index 0000000..afa2cd9 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/TypeConverterTests.cs @@ -0,0 +1,125 @@ +// Copyright 2009-2022 Josh Close +// 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 CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using CsvHelper.TypeConversion; +using Xunit; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + + public class TypeConverterTests + { + [Fact] + public void TypeConverterTest() + { + using (var reader = new StringReader("Id,Name\r\n1,one\r\n")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords<TypeConverterClass>().ToList(); + + Assert.Equal(1, records[0].Id); + Assert.Equal("two", records[0].Name); + } + } + + [Fact] + public void TypeConverterOnClassReferenceTest() + { + var records = new List<AClass> + { + new AClass { Id = 1, Name = new BClass() }, + }; + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteRecords(records); + + var expected = "Id,Name\r\n1,two\r\n"; + + Assert.Equal(expected, writer.ToString()); + } + } + + [Fact] + public void TypeConverterOnStructReferenceTest() + { + var records = new List<AStruct> + { + new AStruct { Id = 1, Name = new BStruct() }, + }; + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteRecords(records); + + var expected = "Id,Name\r\n1,two\r\n"; + + Assert.Equal(expected, writer.ToString()); + } + } + + [Fact] + public void Constructor_TypeConverterWithConstructorArgs_Creates() + { + var attribute = new TypeConverterAttribute(typeof(TypeConverterWithConstructorArgs), 2); + Assert.IsType<TypeConverterWithConstructorArgs>(attribute.TypeConverter); + Assert.Equal(2, ((TypeConverterWithConstructorArgs)attribute.TypeConverter).Value); + } + + private class TypeConverterClass + { + public int Id { get; set; } + + [TypeConverter(typeof(StringTypeConverter))] + public string Name { get; set; } + } + + private class StringTypeConverter : ITypeConverter + { + public object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData) + { + return "two"; + } + + public string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData) + { + return "two"; + } + } + + private class AClass + { + public int Id { get; set; } + [TypeConverter(typeof(StringTypeConverter))] + public BClass Name { get; set; } + } + + private class BClass { } + + private class AStruct + { + public int Id { get; set; } + [TypeConverter(typeof(StringTypeConverter))] + public BStruct Name { get; set; } + } + + private class BStruct { } + + private class TypeConverterWithConstructorArgs : DefaultTypeConverter + { + public int Value { get; private set; } + + public TypeConverterWithConstructorArgs(int value) + { + Value = value; + } + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/UseNewObjectForNullReferenceMembersTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/UseNewObjectForNullReferenceMembersTests.cs new file mode 100644 index 0000000..d560872 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/UseNewObjectForNullReferenceMembersTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class UseNewObjectForNullReferenceMembersTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.False(config.UseNewObjectForNullReferenceMembers); + } + + [UseNewObjectForNullReferenceMembers(false)] + private class Foo { } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/WhiteSpaceCharsTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/WhiteSpaceCharsTests.cs new file mode 100644 index 0000000..3abb027 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mappings/Attribute/WhiteSpaceCharsTests.cs @@ -0,0 +1,20 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System.Globalization; +using Xunit; + +namespace CsvHelper.Tests.Mappings.Attribute +{ + public class WhiteSpaceCharsTests + { + [Fact] + public void ConstructorAttributeTest() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture, typeof(Foo)); + Assert.Equal(new[] { 'a', 'b' }, config.WhiteSpaceChars); + } + + [WhiteSpaceChars("a b")] + private class Foo { } + } +} |