I am trying to write a unit test for a method to add or update an IDictionary<string, string>
Here is the my add or update method:
public static class ExtensionMethods
{
public static void AddOrUpdate(IDictionary<string, string> Dictionary, string
Key, string Value)
{
if(Dictionary.Contains(Key)
{
Dictionary[Key] = Value;
}
else
{
Dictionary.Add(Key, Value);
}
}
}
Here is my unit test:
[TestMethod]
public void Checking_Dictionary_Is_Able_To_Update()
{
// Arrange
IDictionary inputDictionary = new Dictionary<string, string>();
inputDictionary.Add("key1", "someValueForKey1");
inputDictionary.Add("key2", "someValueForKey2");
string inputKeyValue = "key1";
string dataToUpdate = "updatedValueForKey1";
// Act
// The following method call produces a conversion error
ExtensionMethods.AddOrUpdate(inputDictionary, inputKeyValue, dataToUpdate);
}
The error that I am getting when I call the AddOrUpdate() is that I cannot convert a System.Collections.IDictionary to a System.Collections.Generic.IDictionary string, string
Can anyone point out what I might be doing wrong.