Skip to content

Commit 6d08897

Browse files
committed
add missing key-prefix tests
1 parent b81ad62 commit 6d08897

2 files changed

Lines changed: 745 additions & 0 deletions

File tree

tests/StackExchange.Redis.Tests/KeyPrefixedDatabaseTests.cs

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,364 @@ public void StringSetRange()
14311431
prefixed.StringSetRange("key", 123, "value", CommandFlags.None);
14321432
mock.Received().StringSetRange("prefix:key", 123, "value", CommandFlags.None);
14331433
}
1434+
1435+
[Fact]
1436+
public void Execute_1()
1437+
{
1438+
prefixed.Execute("CUSTOM", "arg1", (RedisKey)"arg2");
1439+
mock.Received().Execute("CUSTOM", Arg.Is<object[]>(args => args.Length == 2 && args[0].Equals("arg1") && args[1].Equals((RedisKey)"prefix:arg2")), CommandFlags.None);
1440+
}
1441+
1442+
[Fact]
1443+
public void Execute_2()
1444+
{
1445+
var args = new List<object> { "arg1", (RedisKey)"arg2" };
1446+
prefixed.Execute("CUSTOM", args, CommandFlags.None);
1447+
mock.Received().Execute("CUSTOM", Arg.Is<ICollection<object>>(a => a.Count == 2 && a.ElementAt(0).Equals("arg1") && a.ElementAt(1).Equals((RedisKey)"prefix:arg2"))!, CommandFlags.None);
1448+
}
1449+
1450+
[Fact]
1451+
public void GeoAdd_1()
1452+
{
1453+
prefixed.GeoAdd("key", 1.23, 4.56, "member", CommandFlags.None);
1454+
mock.Received().GeoAdd("prefix:key", 1.23, 4.56, "member", CommandFlags.None);
1455+
}
1456+
1457+
[Fact]
1458+
public void GeoAdd_2()
1459+
{
1460+
var geoEntry = new GeoEntry(1.23, 4.56, "member");
1461+
prefixed.GeoAdd("key", geoEntry, CommandFlags.None);
1462+
mock.Received().GeoAdd("prefix:key", geoEntry, CommandFlags.None);
1463+
}
1464+
1465+
[Fact]
1466+
public void GeoAdd_3()
1467+
{
1468+
var geoEntries = new GeoEntry[] { new GeoEntry(1.23, 4.56, "member1") };
1469+
prefixed.GeoAdd("key", geoEntries, CommandFlags.None);
1470+
mock.Received().GeoAdd("prefix:key", geoEntries, CommandFlags.None);
1471+
}
1472+
1473+
[Fact]
1474+
public void GeoRemove()
1475+
{
1476+
prefixed.GeoRemove("key", "member", CommandFlags.None);
1477+
mock.Received().GeoRemove("prefix:key", "member", CommandFlags.None);
1478+
}
1479+
1480+
[Fact]
1481+
public void GeoDistance()
1482+
{
1483+
prefixed.GeoDistance("key", "member1", "member2", GeoUnit.Meters, CommandFlags.None);
1484+
mock.Received().GeoDistance("prefix:key", "member1", "member2", GeoUnit.Meters, CommandFlags.None);
1485+
}
1486+
1487+
[Fact]
1488+
public void GeoHash_1()
1489+
{
1490+
prefixed.GeoHash("key", "member", CommandFlags.None);
1491+
mock.Received().GeoHash("prefix:key", "member", CommandFlags.None);
1492+
}
1493+
1494+
[Fact]
1495+
public void GeoHash_2()
1496+
{
1497+
var members = new RedisValue[] { "member1", "member2" };
1498+
prefixed.GeoHash("key", members, CommandFlags.None);
1499+
mock.Received().GeoHash("prefix:key", members, CommandFlags.None);
1500+
}
1501+
1502+
[Fact]
1503+
public void GeoPosition_1()
1504+
{
1505+
prefixed.GeoPosition("key", "member", CommandFlags.None);
1506+
mock.Received().GeoPosition("prefix:key", "member", CommandFlags.None);
1507+
}
1508+
1509+
[Fact]
1510+
public void GeoPosition_2()
1511+
{
1512+
var members = new RedisValue[] { "member1", "member2" };
1513+
prefixed.GeoPosition("key", members, CommandFlags.None);
1514+
mock.Received().GeoPosition("prefix:key", members, CommandFlags.None);
1515+
}
1516+
1517+
[Fact]
1518+
public void GeoRadius_1()
1519+
{
1520+
prefixed.GeoRadius("key", "member", 100, GeoUnit.Meters, 10, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1521+
mock.Received().GeoRadius("prefix:key", "member", 100, GeoUnit.Meters, 10, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1522+
}
1523+
1524+
[Fact]
1525+
public void GeoRadius_2()
1526+
{
1527+
prefixed.GeoRadius("key", 1.23, 4.56, 100, GeoUnit.Meters, 10, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1528+
mock.Received().GeoRadius("prefix:key", 1.23, 4.56, 100, GeoUnit.Meters, 10, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1529+
}
1530+
1531+
[Fact]
1532+
public void GeoSearch_1()
1533+
{
1534+
var shape = new GeoSearchCircle(100, GeoUnit.Meters);
1535+
prefixed.GeoSearch("key", "member", shape, 10, true, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1536+
mock.Received().GeoSearch("prefix:key", "member", shape, 10, true, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1537+
}
1538+
1539+
[Fact]
1540+
public void GeoSearch_2()
1541+
{
1542+
var shape = new GeoSearchCircle(100, GeoUnit.Meters);
1543+
prefixed.GeoSearch("key", 1.23, 4.56, shape, 10, true, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1544+
mock.Received().GeoSearch("prefix:key", 1.23, 4.56, shape, 10, true, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);
1545+
}
1546+
1547+
[Fact]
1548+
public void GeoSearchAndStore_1()
1549+
{
1550+
var shape = new GeoSearchCircle(100, GeoUnit.Meters);
1551+
prefixed.GeoSearchAndStore("source", "destination", "member", shape, 10, true, Order.Ascending, false, CommandFlags.None);
1552+
mock.Received().GeoSearchAndStore("prefix:source", "prefix:destination", "member", shape, 10, true, Order.Ascending, false, CommandFlags.None);
1553+
}
1554+
1555+
[Fact]
1556+
public void GeoSearchAndStore_2()
1557+
{
1558+
var shape = new GeoSearchCircle(100, GeoUnit.Meters);
1559+
prefixed.GeoSearchAndStore("source", "destination", 1.23, 4.56, shape, 10, true, Order.Ascending, false, CommandFlags.None);
1560+
mock.Received().GeoSearchAndStore("prefix:source", "prefix:destination", 1.23, 4.56, shape, 10, true, Order.Ascending, false, CommandFlags.None);
1561+
}
1562+
1563+
[Fact]
1564+
public void HashFieldExpire_1()
1565+
{
1566+
var hashFields = new RedisValue[] { "field1", "field2" };
1567+
var expiry = TimeSpan.FromSeconds(60);
1568+
prefixed.HashFieldExpire("key", hashFields, expiry, ExpireWhen.Always, CommandFlags.None);
1569+
mock.Received().HashFieldExpire("prefix:key", hashFields, expiry, ExpireWhen.Always, CommandFlags.None);
1570+
}
1571+
1572+
[Fact]
1573+
public void HashFieldExpire_2()
1574+
{
1575+
var hashFields = new RedisValue[] { "field1", "field2" };
1576+
var expiry = DateTime.Now.AddMinutes(1);
1577+
prefixed.HashFieldExpire("key", hashFields, expiry, ExpireWhen.Always, CommandFlags.None);
1578+
mock.Received().HashFieldExpire("prefix:key", hashFields, expiry, ExpireWhen.Always, CommandFlags.None);
1579+
}
1580+
1581+
[Fact]
1582+
public void HashFieldGetExpireDateTime()
1583+
{
1584+
var hashFields = new RedisValue[] { "field1", "field2" };
1585+
prefixed.HashFieldGetExpireDateTime("key", hashFields, CommandFlags.None);
1586+
mock.Received().HashFieldGetExpireDateTime("prefix:key", hashFields, CommandFlags.None);
1587+
}
1588+
1589+
[Fact]
1590+
public void HashFieldPersist()
1591+
{
1592+
var hashFields = new RedisValue[] { "field1", "field2" };
1593+
prefixed.HashFieldPersist("key", hashFields, CommandFlags.None);
1594+
mock.Received().HashFieldPersist("prefix:key", hashFields, CommandFlags.None);
1595+
}
1596+
1597+
[Fact]
1598+
public void HashFieldGetTimeToLive()
1599+
{
1600+
var hashFields = new RedisValue[] { "field1", "field2" };
1601+
prefixed.HashFieldGetTimeToLive("key", hashFields, CommandFlags.None);
1602+
mock.Received().HashFieldGetTimeToLive("prefix:key", hashFields, CommandFlags.None);
1603+
}
1604+
1605+
[Fact]
1606+
public void HashGetLease()
1607+
{
1608+
prefixed.HashGetLease("key", "field", CommandFlags.None);
1609+
mock.Received().HashGetLease("prefix:key", "field", CommandFlags.None);
1610+
}
1611+
1612+
[Fact]
1613+
public void HashFieldGetAndDelete_1()
1614+
{
1615+
prefixed.HashFieldGetAndDelete("key", "field", CommandFlags.None);
1616+
mock.Received().HashFieldGetAndDelete("prefix:key", "field", CommandFlags.None);
1617+
}
1618+
1619+
[Fact]
1620+
public void HashFieldGetAndDelete_2()
1621+
{
1622+
var hashFields = new RedisValue[] { "field1", "field2" };
1623+
prefixed.HashFieldGetAndDelete("key", hashFields, CommandFlags.None);
1624+
mock.Received().HashFieldGetAndDelete("prefix:key", hashFields, CommandFlags.None);
1625+
}
1626+
1627+
[Fact]
1628+
public void HashFieldGetLeaseAndDelete()
1629+
{
1630+
prefixed.HashFieldGetLeaseAndDelete("key", "field", CommandFlags.None);
1631+
mock.Received().HashFieldGetLeaseAndDelete("prefix:key", "field", CommandFlags.None);
1632+
}
1633+
1634+
[Fact]
1635+
public void HashFieldGetAndSetExpiry_1()
1636+
{
1637+
var expiry = TimeSpan.FromMinutes(5);
1638+
prefixed.HashFieldGetAndSetExpiry("key", "field", expiry, false, CommandFlags.None);
1639+
mock.Received().HashFieldGetAndSetExpiry("prefix:key", "field", expiry, false, CommandFlags.None);
1640+
}
1641+
1642+
[Fact]
1643+
public void HashFieldGetAndSetExpiry_2()
1644+
{
1645+
var expiry = DateTime.Now.AddMinutes(5);
1646+
prefixed.HashFieldGetAndSetExpiry("key", "field", expiry, CommandFlags.None);
1647+
mock.Received().HashFieldGetAndSetExpiry("prefix:key", "field", expiry, CommandFlags.None);
1648+
}
1649+
1650+
[Fact]
1651+
public void HashFieldGetLeaseAndSetExpiry_1()
1652+
{
1653+
var expiry = TimeSpan.FromMinutes(5);
1654+
prefixed.HashFieldGetLeaseAndSetExpiry("key", "field", expiry, false, CommandFlags.None);
1655+
mock.Received().HashFieldGetLeaseAndSetExpiry("prefix:key", "field", expiry, false, CommandFlags.None);
1656+
}
1657+
1658+
[Fact]
1659+
public void HashFieldGetLeaseAndSetExpiry_2()
1660+
{
1661+
var expiry = DateTime.Now.AddMinutes(5);
1662+
prefixed.HashFieldGetLeaseAndSetExpiry("key", "field", expiry, CommandFlags.None);
1663+
mock.Received().HashFieldGetLeaseAndSetExpiry("prefix:key", "field", expiry, CommandFlags.None);
1664+
}
1665+
[Fact]
1666+
public void StringGetLease()
1667+
{
1668+
prefixed.StringGetLease("key", CommandFlags.None);
1669+
mock.Received().StringGetLease("prefix:key", CommandFlags.None);
1670+
}
1671+
1672+
[Fact]
1673+
public void StringGetSetExpiry_1()
1674+
{
1675+
var expiry = TimeSpan.FromMinutes(5);
1676+
prefixed.StringGetSetExpiry("key", expiry, CommandFlags.None);
1677+
mock.Received().StringGetSetExpiry("prefix:key", expiry, CommandFlags.None);
1678+
}
1679+
1680+
[Fact]
1681+
public void StringGetSetExpiry_2()
1682+
{
1683+
var expiry = DateTime.Now.AddMinutes(5);
1684+
prefixed.StringGetSetExpiry("key", expiry, CommandFlags.None);
1685+
mock.Received().StringGetSetExpiry("prefix:key", expiry, CommandFlags.None);
1686+
}
1687+
1688+
[Fact]
1689+
public void StringSetAndGet_1()
1690+
{
1691+
var expiry = TimeSpan.FromMinutes(5);
1692+
prefixed.StringSetAndGet("key", "value", expiry, When.Always, CommandFlags.None);
1693+
mock.Received().StringSetAndGet("prefix:key", "value", expiry, When.Always, CommandFlags.None);
1694+
}
1695+
1696+
[Fact]
1697+
public void StringSetAndGet_2()
1698+
{
1699+
var expiry = TimeSpan.FromMinutes(5);
1700+
prefixed.StringSetAndGet("key", "value", expiry, false, When.Always, CommandFlags.None);
1701+
mock.Received().StringSetAndGet("prefix:key", "value", expiry, false, When.Always, CommandFlags.None);
1702+
}
1703+
[Fact]
1704+
public void StringLongestCommonSubsequence()
1705+
{
1706+
prefixed.StringLongestCommonSubsequence("key1", "key2", CommandFlags.None);
1707+
mock.Received().StringLongestCommonSubsequence("prefix:key1", "prefix:key2", CommandFlags.None);
1708+
}
1709+
1710+
[Fact]
1711+
public void StringLongestCommonSubsequenceLength()
1712+
{
1713+
prefixed.StringLongestCommonSubsequenceLength("key1", "key2", CommandFlags.None);
1714+
mock.Received().StringLongestCommonSubsequenceLength("prefix:key1", "prefix:key2", CommandFlags.None);
1715+
}
1716+
1717+
[Fact]
1718+
public void StringLongestCommonSubsequenceWithMatches()
1719+
{
1720+
prefixed.StringLongestCommonSubsequenceWithMatches("key1", "key2", 5, CommandFlags.None);
1721+
mock.Received().StringLongestCommonSubsequenceWithMatches("prefix:key1", "prefix:key2", 5, CommandFlags.None);
1722+
}
1723+
[Fact]
1724+
public void IsConnected()
1725+
{
1726+
prefixed.IsConnected("key", CommandFlags.None);
1727+
mock.Received().IsConnected("prefix:key", CommandFlags.None);
1728+
}
1729+
[Fact]
1730+
public void StreamAdd_WithTrimMode_1()
1731+
{
1732+
prefixed.StreamAdd("key", "field", "value", "*", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1733+
mock.Received().StreamAdd("prefix:key", "field", "value", "*", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1734+
}
1735+
1736+
[Fact]
1737+
public void StreamAdd_WithTrimMode_2()
1738+
{
1739+
var fields = new NameValueEntry[] { new NameValueEntry("field", "value") };
1740+
prefixed.StreamAdd("key", fields, "*", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1741+
mock.Received().StreamAdd("prefix:key", fields, "*", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1742+
}
1743+
1744+
[Fact]
1745+
public void StreamTrim_WithMode()
1746+
{
1747+
prefixed.StreamTrim("key", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1748+
mock.Received().StreamTrim("prefix:key", 1000, false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1749+
}
1750+
1751+
[Fact]
1752+
public void StreamTrimByMinId_WithMode()
1753+
{
1754+
prefixed.StreamTrimByMinId("key", "1111111111", false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1755+
mock.Received().StreamTrimByMinId("prefix:key", "1111111111", false, 100, StreamTrimMode.KeepReferences, CommandFlags.None);
1756+
}
1757+
1758+
[Fact]
1759+
public void StreamReadGroup_WithNoAck_1()
1760+
{
1761+
prefixed.StreamReadGroup("key", "group", "consumer", "0-0", 10, true, CommandFlags.None);
1762+
mock.Received().StreamReadGroup("prefix:key", "group", "consumer", "0-0", 10, true, CommandFlags.None);
1763+
}
1764+
1765+
[Fact]
1766+
public void StreamReadGroup_WithNoAck_2()
1767+
{
1768+
var streamPositions = new StreamPosition[] { new StreamPosition("key", "0-0") };
1769+
prefixed.StreamReadGroup(streamPositions, "group", "consumer", 10, true, CommandFlags.None);
1770+
mock.Received().StreamReadGroup(streamPositions, "group", "consumer", 10, true, CommandFlags.None);
1771+
}
1772+
1773+
[Fact]
1774+
public void StreamTrim_Simple()
1775+
{
1776+
prefixed.StreamTrim("key", 1000, true, CommandFlags.None);
1777+
mock.Received().StreamTrim("prefix:key", 1000, true, CommandFlags.None);
1778+
}
1779+
1780+
[Fact]
1781+
public void StreamReadGroup_Simple_1()
1782+
{
1783+
prefixed.StreamReadGroup("key", "group", "consumer", "0-0", 10, CommandFlags.None);
1784+
mock.Received().StreamReadGroup("prefix:key", "group", "consumer", "0-0", 10, CommandFlags.None);
1785+
}
1786+
1787+
[Fact]
1788+
public void StreamReadGroup_Simple_2()
1789+
{
1790+
var streamPositions = new StreamPosition[] { new StreamPosition("key", "0-0") };
1791+
prefixed.StreamReadGroup(streamPositions, "group", "consumer", 10, CommandFlags.None);
1792+
mock.Received().StreamReadGroup(streamPositions, "group", "consumer", 10, CommandFlags.None);
1793+
}
14341794
}

0 commit comments

Comments
 (0)