diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks')
4 files changed, 390 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/DynamicObjectMock.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/DynamicObjectMock.cs new file mode 100644 index 0000000..c54a1f3 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/DynamicObjectMock.cs @@ -0,0 +1,31 @@ +// 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 System.Collections.Generic; +using System.Dynamic; + +namespace CsvHelper.Tests.Mocks +{ + public class DynamicObjectMock : DynamicObject + { + private Dictionary<string, object> dictionary = new Dictionary<string, object>(); + + public override bool TryGetMember(GetMemberBinder binder, out object result) + { + return dictionary.TryGetValue(binder.Name, out result); + } + + public override bool TrySetMember(SetMemberBinder binder, object value) + { + dictionary[binder.Name] = value; + + return true; + } + + public override IEnumerable<string> GetDynamicMemberNames() + { + return dictionary.Keys; + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMock.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMock.cs new file mode 100644 index 0000000..3dba8b2 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMock.cs @@ -0,0 +1,96 @@ +// 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 System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using CsvHelper.Configuration; +using System.Threading.Tasks; +using System.Globalization; +using System.Linq; + +namespace CsvHelper.Tests.Mocks +{ + public class ParserMock : IParser, IEnumerable<string[]> + { + private readonly Queue<string[]> records = new Queue<string[]>(); + private string[] record; + private int row; + + public CsvContext Context { get; private set; } + + public IParserConfiguration Configuration { get; private set; } + + public int Count => record?.Length ?? 0; + + public string[] Record => record; + + public string RawRecord => string.Empty; + + public int Row => row; + + public int RawRow => row; + + public long ByteCount => 0; + + public long CharCount => 0; + + public string Delimiter => Configuration.Delimiter; + + public string this[int index] => record[index]; + + public ParserMock() : this(new CsvConfiguration(CultureInfo.InvariantCulture)) { } + + public ParserMock(CsvConfiguration configuration) + { + Configuration = configuration; + Context = new CsvContext(this); + } + + public bool Read() + { + if (records.Count == 0) + { + return false; + } + + row++; + record = records.Dequeue(); + + return true; + } + + public Task<bool> ReadAsync() + { + row++; + record = records.Dequeue(); + + return Task.FromResult(records.Count > 0); + } + + public void Dispose() + { + } + + #region Mock Methods + + public void Add(params string[] record) + { + records.Enqueue(record); + } + + public IEnumerator<string[]> GetEnumerator() + { + return records.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion Mock Methods + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMockTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMockTests.cs new file mode 100644 index 0000000..3b779c9 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ParserMockTests.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 Xunit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Tests.Mocks +{ + + public class ParserMockTests + { + [Fact] + public void Test() + { + var parser = new ParserMock + { + { "Id", "Name" }, + { "1", "one" }, + }; + Assert.True(parser.Read()); + Assert.Equal("Id", parser[0]); + Assert.Equal("Name", parser[1]); + + Assert.True(parser.Read()); + Assert.Equal("1", parser[0]); + Assert.Equal("one", parser[1]); + + Assert.False(parser.Read()); + Assert.False(parser.Read()); + } + } +} diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ReaderRowMock.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ReaderRowMock.cs new file mode 100644 index 0000000..b73c81e --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Mocks/ReaderRowMock.cs @@ -0,0 +1,226 @@ +// 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.TypeConversion; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Tests.Mocks +{ + public class ReaderRowMock : IReaderRow + { + public string this[int index] => throw new NotImplementedException(); + + public string this[string name] => throw new NotImplementedException(); + + public string this[string name, int index] => throw new NotImplementedException(); + + public int ColumnCount => throw new NotImplementedException(); + + public int CurrentIndex => throw new NotImplementedException(); + + public string[] HeaderRecord => throw new NotImplementedException(); + + public IParser Parser => throw new NotImplementedException(); + + public CsvContext Context => throw new NotImplementedException(); + + public IReaderConfiguration Configuration { get; private set; } + + public ReaderRowMock() + { + Configuration = new CsvConfiguration(CultureInfo.InvariantCulture); + } + + public ReaderRowMock(CsvConfiguration configuration) + { + Configuration = configuration; + } + + public string GetField(int index) + { + throw new NotImplementedException(); + } + + public string GetField(string name) + { + throw new NotImplementedException(); + } + + public string GetField(string name, int index) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, int index) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, string name) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, string name, int index) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, int index, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, string name, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public object GetField(Type type, string name, int index, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public T GetField<T>(int index) + { + throw new NotImplementedException(); + } + + public T GetField<T>(string name) + { + throw new NotImplementedException(); + } + + public T GetField<T>(string name, int index) + { + throw new NotImplementedException(); + } + + public T GetField<T>(int index, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public T GetField<T>(string name, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public T GetField<T>(string name, int index, ITypeConverter converter) + { + throw new NotImplementedException(); + } + + public T GetField<T, TConverter>(int index) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + + public T GetField<T, TConverter>(string name) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + + public T GetField<T, TConverter>(string name, int index) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + + public T GetRecord<T>() + { + throw new NotImplementedException(); + } + + public T GetRecord<T>(T anonymousTypeDefinition) + { + throw new NotImplementedException(); + } + + public object GetRecord(Type type) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, int index, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, string name, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, string name, int index, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, int index, ITypeConverter converter, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, string name, ITypeConverter converter, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField(Type type, string name, int index, ITypeConverter converter, out object field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(int index, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(string name, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(string name, int index, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(int index, ITypeConverter converter, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(string name, ITypeConverter converter, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T>(string name, int index, ITypeConverter converter, out T field) + { + throw new NotImplementedException(); + } + + public bool TryGetField<T, TConverter>(int index, out T field) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + + public bool TryGetField<T, TConverter>(string name, out T field) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + + public bool TryGetField<T, TConverter>(string name, int index, out T field) where TConverter : ITypeConverter + { + throw new NotImplementedException(); + } + } +} |