Files
laatzen/LaaProductionWeb/LaaProduction.Data.Cordonel.UnitTests/Mock/SentinelTestContextExtensions.cs
T

29 lines
906 B
C#

namespace LaaProduction.Data.Cordonel.UnitTests.Mock
{
using System;
using System.Collections.Generic;
internal static class SentinelTestContextExtensions
{
public static T TryGetValue<T>(this Dictionary<string, object> data, string key)
{
if (string.IsNullOrWhiteSpace(key))
{
throw new InvalidOperationException($"{nameof(key)} ist erforderlich");
}
else if (!data.TryGetValue(key, out var t))
{
throw new InvalidOperationException($"{nameof(key)}: {typeof(T).Name} ist nicht vorhanden");
}
else if (t is T _object)
{
return _object;
}
else
{
throw new InvalidOperationException($"{nameof(key)}: value ist nicht von typ {typeof(T).Name}");
}
}
}
}