public void GetJsonValueOrDefault_EmptyJsonAndDefaultNotSpecified_ReturnsDefaultValue(string json) { _internalSettings.GetValueOrDefault(_key, Arg.Any <string>()).Returns(json); var actualValue = _internalSettings.GetJsonValueOrDefault <TestObject>(_jsonSerializer, _key); _internalSettings.Received().GetValueOrDefault(_key, default(string)); _jsonSerializer.DidNotReceive().Deserialize <TestObject>(Arg.Any <string>()); Assert.Equal(_nullValue, actualValue); }
public static T GetJsonValueOrDefault <T>( this IInternalSettings internalSettings, IJsonSerializer jsonSerializer, string key, T defaultValue = default) { var json = internalSettings.GetValueOrDefault(key, default(string) !); return(string.IsNullOrEmpty(json) ? defaultValue : jsonSerializer.Deserialize <T>(json)); }