Skip to content

Instantly share code, notes, and snippets.

@matlus
Last active May 8, 2019 13:02
Show Gist options
  • Select an option

  • Save matlus/ddcb3895f0c3a073aa66511b5fc014b9 to your computer and use it in GitHub Desktop.

Select an option

Save matlus/ddcb3895f0c3a073aa66511b5fc014b9 to your computer and use it in GitHub Desktop.
OneToManyMap Test methods Skeleton
[TestClass]
public class OneToManyMapDictionaryTests
{
private static IOneToManyMap<TKey, TValue> InitializeOneToManyMap<TKey, TValue>(TKey key, TValue[] values)
{
var oneToManyMap = new OneToManyMapDictionary<TKey, TValue>();
oneToManyMap.AddOneToManyMapping(key, values);
return oneToManyMap;
}
////private static IOneToManyMap<string, string> InitializeOneToManyMap(string key, string[] values)
////{
//// var oneToManyMap = new OneToManyMapDictionary<string, string>();
//// oneToManyMap.AddOneToManyMapping(key, values);
//// return oneToManyMap;
////}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_Indexer_WhenProvidedWithAValueThatsBeenMappedToAKey_ReturnsTheKey()
{
// Arrange
// Act
// Assert
}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_Indexer_WhenProvidedWithAValueNotMappedToAKey_Throws()
{
// Arrange
// Act
try
{
}
catch (ValueNotMappedToKeyException e)
{
// Assert
var expectedSubstringInExceptionMessage = "has not been mapped to a Key";
Assert.IsTrue(e.Message.Contains($"value: {valueWithNoKeyMapping}"), $"An Exception of type ValueNotMappedToKeyException was thrown, however, the message was expected to contain the \"value\" {valueWithNoKeyMapping}, that has not been mapped to a key");
Assert.IsTrue(e.Message.Contains(expectedSubstringInExceptionMessage), "An Exception of type ValueNotMappedToKeyException was thrown, however, the message was expected to contain the substring: {expectedSubstringInExceptionMessage}");
}
}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_AddOneToManyMapping_WhenAddingANewValueToExistingKey_ShouldMapValueToKey()
{
// Arrange
// Act
// Assert
}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_AddOneToManyMapping_WhenValueHasPriorMapping_Throws()
{
// Arrange
// Act
try
{
}
catch (ValuesHasPriorMappingToKeyException e)
{
// Assert
Assert.IsTrue(e.Message.Contains($"value: {valueAlreadyMapped}"), "The Exception Message does not indicate what \"Value\" is already mapped");
Assert.IsTrue(e.Message.Contains("has a prior mapping"));
Assert.IsTrue(e.Message.Contains(preExistingKey), $"The Exception Message does not indicate the \"Key\" the Value: {valueAlreadyMapped} is already mapped to.");
}
}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_AddOneToManyMapping_WhenOneOrMoreValuesHavePriorMapping_MapRemainsUnchanged()
{
// Arrange
// Act
try
{
}
catch (ValuesHasPriorMappingToKeyException)
{
// Assert
// Those values that were in the map should remain unchanged
Assert.AreEqual(preExistingKey, oneToManyMap[irrelevantvalue1], $"The value: {irrelevantvalue1} was expected to be mapped to the pre-existing key: {preExistingKey}");
Assert.AreEqual(preExistingKey, oneToManyMap[irrelevantvalue2], $"The value: {irrelevantvalue2} was expected to be mapped to the pre-existing key: {preExistingKey}");
// Those values that were attempted to be added where not
AssertValueIsNotMapped(oneToManyMap, irrelevantValueToBeAdded1);
AssertValueIsNotMapped(oneToManyMap, irrelevantValueToBeAdded2);
}
}
private void AssertValueIsNotMapped(IOneToManyMap<string, string> oneToManyMap, string valueNotMapped)
{
// Act
try
{
var key = oneToManyMap[valueNotMapped];
Assert.Fail($"It appears that the value: {valueNotMapped} is mapped to the key: {key}. However, we were expecting an Exception of type ValueNotMappedToKeyException to be thrown, but no Exception was thrown.");
}
catch (ValueNotMappedToKeyException)
{
// Intentionally Ignoring this exception since we're expecting this exception
}
}
[TestMethod]
[TestCategory("Class Test")]
public void OneToManyMap_AddOneToManyMapping_WhenKeyExists_ShouldAddValuesToExistingKey()
{
// Arrange
// Act
// Assert
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment