A database based on .net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.7 KiB

// Author: Gockner, Simon
// Created: 2020-02-14
// Copyright(c) 2020 SimonG. All Rights Reserved.
using System.Collections.Generic;
using GBase.Exceptions;
using GBase.Helpers;
using NUnit.Framework;
using Test.GBase.TestClasses;
namespace Test.GBase.Helpers
{
[TestFixture]
public class EnumerablesTest
{
[Test]
public void TestToGBaseStringStringList()
{
List<string> list = new List<string>()
{
"SomeString",
"AnotherString",
"ThirdString"
};
string expectedString = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(expectedString, list.ToGBaseString());
}
[Test]
public void TestToGBaseStringIntList()
{
List<int> list = new List<int>()
{
1,
2,
3
};
string expectedString = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(expectedString, list.ToGBaseString());
}
[Test]
public void TestToGBaseUserTypeList()
{
List<UserType> list = new List<UserType>()
{
new UserType(1),
new UserType(2),
new UserType(3)
};
string expectedString = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(expectedString, list.ToGBaseString());
}
[Test]
public void TestToGBaseUserTypeInterfaceList()
{
List<IUserType> list = new List<IUserType>()
{
new UserType(1),
new UserType(2),
new UserType(3)
};
string expectedString = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(expectedString, list.ToGBaseString());
}
[Test]
public void TestConvertToGBaseEnumerableStringList()
{
List<string> list = new List<string>()
{
"SomeString",
"AnotherString",
"ThirdString"
};
string @string = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(list, Enumerables.ConvertToGBaseEnumerable<List<string>>(@string));
}
[Test]
public void TestConvertToGBaseEnumerableIntList()
{
List<int> list = new List<int>()
{
1,
2,
3
};
string @string = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(list, Enumerables.ConvertToGBaseEnumerable<List<int>>(@string));
}
[Test]
public void TestConvertToGBaseEnumerableUserTypeList()
{
List<UserType> list = new List<UserType>()
{
new UserType(1),
new UserType(2),
new UserType(3)
};
string @string = $"{list[0]},{list[1]},{list[2]}";
Assert.AreEqual(list, Enumerables.ConvertToGBaseEnumerable<List<UserType>>(@string));
}
[Test]
public void TestConvertToGBaseEnumerableUserTypeInterfaceList()
{
List<IUserType> list = new List<IUserType>()
{
new UserType(1),
new UserType(2),
new UserType(3)
};
string @string = $"{list[0]},{list[1]},{list[2]}";
InterfaceEnumerablePassedException exception = Assert.Throws<InterfaceEnumerablePassedException>(() => Enumerables.ConvertToGBaseEnumerable<List<IUserType>>(@string));
Assert.AreEqual(typeof(IUserType), exception.InterfaceType);
}
}
}