-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify meaning of RedisValue.IsInteger (#2420)
* add passing (modified) test for #2418 * - clarify the meaning of RedisValue.IsInteger, and reduce the visibility - fix a typo * fix PR number
- Loading branch information
Showing
4 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace StackExchange.Redis.Tests.Issues; | ||
|
||
public class Issue2418 : TestBase | ||
{ | ||
public Issue2418(ITestOutputHelper output, SharedConnectionFixture? fixture = null) | ||
: base(output, fixture) { } | ||
|
||
[Fact] | ||
public async Task Execute() | ||
{ | ||
using var conn = Create(); | ||
var db = conn.GetDatabase(); | ||
|
||
RedisKey key = Me(); | ||
RedisValue someInt = 12; | ||
Assert.False(someInt.IsNullOrEmpty, nameof(someInt.IsNullOrEmpty) + " before"); | ||
Assert.True(someInt.IsInteger, nameof(someInt.IsInteger) + " before"); | ||
await db.HashSetAsync(key, new[] | ||
{ | ||
new HashEntry("some_int", someInt), | ||
// ... | ||
}); | ||
|
||
// check we can fetch it | ||
var entry = await db.HashGetAllAsync(key); | ||
Assert.NotEmpty(entry); | ||
Assert.Single(entry); | ||
foreach (var pair in entry) | ||
{ | ||
Log($"'{pair.Name}'='{pair.Value}'"); | ||
} | ||
|
||
|
||
// filter with LINQ | ||
Assert.True(entry.Any(x => x.Name == "some_int"), "Any"); | ||
someInt = entry.FirstOrDefault(x => x.Name == "some_int").Value; | ||
Log($"found via Any: '{someInt}'"); | ||
Assert.False(someInt.IsNullOrEmpty, nameof(someInt.IsNullOrEmpty) + " after"); | ||
Assert.True(someInt.TryParse(out int i)); | ||
Assert.Equal(12, i); | ||
Assert.Equal(12, (int)someInt); | ||
} | ||
} |