using System.Collections.Generic;
namespace CustomCollection.Tests
public static void Main() {
var stringMap = new StringMap<TestClass>();
var exception = Record.Exception(() => result = stringMap.AddElement(null, new TestClass()));
Assert.IsType<ArgumentNullException>(exception);
exception = Record.Exception(() => result = stringMap.AddElement("test", null));
Assert.IsType<ArgumentNullException>(exception);
exception = Record.Exception(() => result = stringMap.AddElement("", new TestClass()));
Assert.IsType<ArgumentException>(exception);
exception = Record.Exception(() => result = stringMap.AddElement("test", new TestClass()));
exception = Record.Exception(() => result = stringMap.AddElement("test", new TestClass()));
exception = Record.Exception(() => result = stringMap.RemoveElement("notInCollection"));
exception = Record.Exception(() => result = stringMap.RemoveElement("test"));
Console.WriteLine("All passed");
public class StringMap<TValue> : IStringMap<TValue>
Dictionary<string, TValue> myMap = new Dictionary<string, TValue>();
public int Count => myMap.Count;
public TValue DefaultValue { get; set; }
public bool AddElement(string key, TValue value)
if(key == null || value == null){
throw new System.ArgumentNullException();
throw new System.ArgumentException();
}else if(myMap.ContainsKey(key)){
public bool RemoveElement(string key)
throw new System.ArgumentNullException();
throw new System.ArgumentException();
}else if(myMap.ContainsKey(key)){
public TValue GetValue(string key)
throw new System.ArgumentNullException();
throw new System.ArgumentException();
}else if(myMap.ContainsKey(key)){
public interface IStringMap<TValue> where TValue: class
TValue DefaultValue { get; set; }
bool AddElement(string key, TValue value);
bool RemoveElement(string key);
TValue GetValue(string key);