Unverified Commit 12e49f64 authored by Nick Craver's avatar Nick Craver Committed by GitHub

Fixes #229, bringing HasValue in parity with IsNullOrEmpty (#840)

It appears we just never use this property anywhere and never noticed, but users did long ago. See #229 for details.

Also adds some testing around this. While this may be considered a breaking change, I'm really going to err on the side of this is a plain on bug fix on a rarely used property. This doesn't impact any existing tests.
parent e7b4ab86
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Abstractions;
namespace StackExchange.Redis.Tests
{
public class Values : TestBase
{
public Values(ITestOutputHelper output) : base (output) { }
[Fact]
public void NullValueChecks()
{
RedisValue four = 4;
Assert.False(four.IsNull);
Assert.True(four.IsInteger);
Assert.True(four.HasValue);
Assert.False(four.IsNullOrEmpty);
RedisValue n = default(RedisValue);
Assert.True(n.IsNull);
Assert.False(n.IsInteger);
Assert.False(n.HasValue);
Assert.True(n.IsNullOrEmpty);
RedisValue emptyArr = new byte[0];
Assert.False(emptyArr.IsNull);
Assert.False(emptyArr.IsInteger);
Assert.False(emptyArr.HasValue);
Assert.True(emptyArr.IsNullOrEmpty);
}
}
}
...@@ -47,9 +47,9 @@ private RedisValue(long valueInt64, byte[] valueBlob) ...@@ -47,9 +47,9 @@ private RedisValue(long valueInt64, byte[] valueBlob)
public bool IsNullOrEmpty => valueBlob == null || (valueBlob.Length == 0 && !(valueBlob == IntegerSentinel)); public bool IsNullOrEmpty => valueBlob == null || (valueBlob.Length == 0 && !(valueBlob == IntegerSentinel));
/// <summary> /// <summary>
/// Indicates whether the value is greater than zero-length /// Indicates whether the value is greater than zero-length or has an integer value
/// </summary> /// </summary>
public bool HasValue => valueBlob?.Length > 0; public bool HasValue => !IsNullOrEmpty;
/// <summary> /// <summary>
/// Indicates whether two RedisValue values are equivalent /// Indicates whether two RedisValue values are equivalent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment