mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:45:42 +00:00
Add tests for ToConnectionString/ToGetParameters
This commit is contained in:
parent
49e5482b8f
commit
14148f751a
@ -87,4 +87,103 @@ public class DictionaryTests
|
|||||||
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one"));
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, addValueFactory!, (_, _) => "one"));
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0));
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.AddOrUpdate(1, null!, (_, _, _) => "one", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToConnectionString_ShouldReturnConnectionString()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
["Data Source"] = "localhost", ["Initial Catalog"] = "test", ["Integrated Security"] = "True", ["Foobar"] = null
|
||||||
|
};
|
||||||
|
|
||||||
|
string connectionString = dictionary.ToConnectionString();
|
||||||
|
Assert.AreEqual("Data Source=localhost;Initial Catalog=test;Integrated Security=True;Foobar=", connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToConnectionString_ShouldReturnTransformedValueConnectionString()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
["Data Source"] = "localhost", ["Initial Catalog"] = "test", ["Integrated Security"] = "True", ["Foobar"] = null
|
||||||
|
};
|
||||||
|
|
||||||
|
string connectionString = dictionary.ToConnectionString(v => v?.ToUpperInvariant());
|
||||||
|
Assert.AreEqual("Data Source=LOCALHOST;Initial Catalog=TEST;Integrated Security=TRUE;Foobar=", connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToConnectionString_ShouldReturnTransformedKeyValueConnectionString()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
["Data Source"] = "localhost", ["Initial Catalog"] = "test", ["Integrated Security"] = "True", ["Foobar"] = null
|
||||||
|
};
|
||||||
|
|
||||||
|
string connectionString = dictionary.ToConnectionString(k => k.ToUpper(), v => v?.ToUpperInvariant());
|
||||||
|
Assert.AreEqual("DATA SOURCE=LOCALHOST;INITIAL CATALOG=TEST;INTEGRATED SECURITY=TRUE;FOOBAR=", connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToConnectionString_ShouldThrow_GivenNullSource()
|
||||||
|
{
|
||||||
|
Dictionary<string, string>? dictionary = null;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString());
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString(null!));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToConnectionString(null!, null!));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToConnectionString_ShouldThrow_GivenNullSelector()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string>();
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(null!));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(null!, _ => _));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToConnectionString(_ => _, null!));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToGetParameters_ShouldReturnParameters()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string> {["id"] = "1", ["user"] = "hello world", ["foo"] = "bar"};
|
||||||
|
|
||||||
|
string queryString = dictionary.ToGetParameters();
|
||||||
|
Assert.AreEqual("id=1&user=hello+world&foo=bar", queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToGetParameters_ShouldReturnTransformedValueParameters()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null};
|
||||||
|
|
||||||
|
string queryString = dictionary.ToGetParameters(v => v?.ToUpper());
|
||||||
|
Assert.AreEqual("id=1&user=HELLO+WORLD&foo=", queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToGetParameters_ShouldReturnTransformedKeyValueParameters()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string?> {["id"] = "1", ["user"] = "hello world", ["foo"] = null};
|
||||||
|
|
||||||
|
string queryString = dictionary.ToGetParameters(k => k.ToUpper(), v => v?.ToUpper());
|
||||||
|
Assert.AreEqual("ID=1&USER=HELLO+WORLD&FOO=", queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToGetParameters_ShouldThrow_GivenNullSource()
|
||||||
|
{
|
||||||
|
Dictionary<string, string>? dictionary = null;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters());
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters(null!));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary!.ToGetParameters(null!, null!));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToGetParameters_ShouldThrow_GivenNullSelector()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string>();
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(null!));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(null!, _ => _));
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => dictionary.ToGetParameters(_ => _, null!));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user