public async Task Test_Unsubscribe() { var dutPublisher = new AsyncRedisClient(); var dutSubscriber = new AsyncRedisSubscriptionClient(); await dutPublisher.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dutSubscriber.Connect(LocalHostDefaultPort.AsConnectionSettings()); string receivedChannel = null; string receivedMessage = null; dutSubscriber.OnMessageReceived += (ch, msg) => { receivedChannel = ch; receivedMessage = msg; }; await dutSubscriber.Subscribe(Channel); await dutPublisher.Publish(Channel, Message); Thread.Sleep(100); await dutSubscriber.Unsubscribe(Channel); await dutPublisher.Publish(Channel, SecondMessage); Thread.Sleep(100); Assert.AreEqual(Channel, receivedChannel); Assert.AreEqual(Message, receivedMessage); }
public async Task Test_MultipleSubscribe() { var dutPublisher = new AsyncRedisClient(); var dutSubscriber = new AsyncRedisSubscriptionClient(); await dutPublisher.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dutSubscriber.Connect(LocalHostDefaultPort.AsConnectionSettings()); var received = new List <Tuple <string, string> >(); dutSubscriber.OnMessageReceived += (ch, msg) => { received.Add(Tuple.Create(ch, msg)); }; await dutSubscriber.Subscribe(new[] { Channel, OtherChannel }); await dutPublisher.Publish(Channel, Message); Thread.Sleep(100); await dutPublisher.Publish(OtherChannel, OtherMessage); Thread.Sleep(100); Assert.AreEqual(2, received.Count); Assert.AreEqual(Channel, received[0].Item1); Assert.AreEqual(Message, received[0].Item2); Assert.AreEqual(OtherChannel, received[1].Item1); Assert.AreEqual(OtherMessage, received[1].Item2); }
public async Task Cleanup() { try { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Select(0); await dut.Del(Key); await dut.Del(Key2); await dut.Select(7); await dut.Del(Key); await dut.Del(Key2); } catch (Exception ex) { Console.WriteLine($"Error during cleanup: {ex}"); throw; } }
public async Task TestScriptLoadAndRun_ListInList() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); var sha = await dut.LoadScript(ScriptWithListInListResult); Console.WriteLine(sha); var result = (await dut.EvalSha(sha, new string[0])).ToArray(); Assert.AreEqual(2, result?.Length); var embeddedArray1 = result[0] as object[]; var embeddedArray2 = result[1] as object[]; Assert.AreEqual("10", embeddedArray1?[0]?.ToString()); Assert.AreEqual("20", embeddedArray1?[1]?.ToString()); Assert.AreEqual("30", embeddedArray1?[2]?.ToString()); Assert.AreEqual("40", embeddedArray1?[3]?.ToString()); Assert.AreEqual("10", embeddedArray2?[0]?.ToString()); Assert.AreEqual("20", embeddedArray2?[1]?.ToString()); Assert.AreEqual("30", embeddedArray2?[2]?.ToString()); Assert.AreEqual("40", embeddedArray2?[3]?.ToString()); }
public async Task Cleanup() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Del(ListKey); }
public async Task Test_GetAllHash_Null() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); var res = await dut.HGetAll(_keys[3]); Assert.AreEqual(0, res.Count); }
public async Task Test_RPush() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.RPush(ListKey, ListItems); var result = (await dut.LRange(ListKey, 0, 100)).ToList(); Assert.IsTrue(ListItems.SequenceEqual(result)); }
public async Task Test_SetAndGetHash() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.HSet(_keys[0], Field1, Value1); var res = await dut.HGet(_keys[0], Field1); Assert.AreEqual(Value1, res); }
public async Task Test_GeHash_Null() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); var res = (await dut.HMGet(_keys[3], new[] { Field1, Field2 })).ToList(); Assert.AreEqual(2, res.Count); Assert.IsNull(res[0]); Assert.IsNull(res[1]); }
public async Task Test_Set_Get() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Set(Key, Value); var res = await dut.Get(Key); Assert.AreEqual(Value, res); }
public async Task DbSize_ReturnsValueCorrectly() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Set(Key, Value); await underTest.Set(Key2, Value2); var result = await underTest.DbSize(); result.Should().Be(2); }
public async Task Test_LRange() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.RPush(ListKey, ListItems); var result = (await dut.LRange(ListKey, 1, 2)).ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(ListItems[1], result[0]); Assert.AreEqual(ListItems[2], result[1]); }
public async Task Exists_ReturnsValueCorrectly() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Set(Key, Value); var result1 = await underTest.Exists(Key); var result2 = await underTest.Exists("NotPresentKey"); result1.Should().BeTrue(); result2.Should().BeFalse(); }
public async Task Del_DeletedSuccessfully() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Set(Key, Value); var result1 = await underTest.Get(Key); await underTest.Del(Key); var result2 = await underTest.Get(Key); result1.Should().Be(Value); result2.Should().BeNull(); }
public async Task TestScriptLoadAndRun_SingleString() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); var sha = await dut.LoadScript(ScriptWithoutParameter); Assert.AreEqual(ShaLength, sha.Length); var res = (await dut.EvalSha(sha, new string[0])).ToList(); var resString = res[0]; Assert.AreEqual("it works", resString); }
public async Task Connect_ConnectsSuccessfully() { Exception thrownException = null; var underTest = new AsyncRedisClient(); try { await underTest.Connect(LocalHostDefaultPort.AsConnectionSettings()); } catch (Exception ex) { thrownException = ex; } thrownException.Should().BeNull(); }
public async Task SwapWithWrongDbNumbers_ThrowsException() { Exception thrownException = null; var underTest = LocalHostDefaultPort.CreateAndConnectClient(); try { await underTest.SwapDb(int.MaxValue, int.MaxValue - 1); } catch (Exception ex) { thrownException = ex; } thrownException.Should().NotBeNull().And.BeOfType <RedisException>(); }
public async Task Cleanup() { try { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Select(0); _keys.ForEach(k => dut.Del(k).GetAwaiter().GetResult()); } catch (Exception ex) { Console.WriteLine($"Error during cleanup: {ex}"); throw; } }
public async Task Select_ClientSelectsNewDb() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Select(7); await underTest.Set(Key, Value); var result1 = await underTest.Get(Key); await underTest.Select(8); var result2 = await underTest.Get(Key); result1.Should().Be(Value); result2.Should().BeNull(); }
public async Task Test_GetMultipleHash() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.HSet(_keys[2], Field1, Value1); await dut.HSet(_keys[2], Field2, Value2); await dut.HSet(_keys[2], Field3, Value3); var res = (await dut.HMGet(_keys[2], new[] { Field1, Field2, Field3 })).ToList(); Assert.AreEqual(Value1, res[0]); Assert.AreEqual(Value2, res[1]); Assert.AreEqual(Value3, res[2]); }
public async Task Test_ConnectWithSubscriptionClient() { Exception thrownException = null; var dut = new AsyncRedisSubscriptionClient(); try { await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); } catch (Exception ex) { thrownException = ex; } Assert.IsNull(thrownException); }
public async Task FlushDb_DbFlushedSuccessfully() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Set(Key, Value); await underTest.Set(Key2, Value2); await underTest.FlushDb(); var result1 = await underTest.Get(Key); var result2 = await underTest.Get(Key2); result1.Should().BeNull(); result2.Should().BeNull(); }
public async Task CallingClientAfterDispose_ThrowsException() { Exception thrownException = null; var underTest = LocalHostDefaultPort.CreateAndConnectClient(); underTest.Dispose(); try { await underTest.Set(Key, Value); } catch (Exception ex) { thrownException = ex; } thrownException.Should().NotBeNull().And.BeOfType <InvalidOperationException>(); }
public async Task ConnectCalledTwice_ThrowsException() { Exception thrownException = null; var underTest = new AsyncRedisClient(); try { await underTest.Connect(LocalHostDefaultPort.AsConnectionSettings()); await underTest.Connect(LocalHostDefaultPort.AsConnectionSettings()); } catch (Exception ex) { thrownException = ex; } thrownException.Should().NotBeNull().And.BeOfType <InvalidOperationException>(); }
public async Task Test_Ping() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); Exception thrownException = null; try { await dut.Ping(); } catch (Exception ex) { thrownException = ex; } Assert.IsNull(thrownException); }
public async Task Test_GetAllHash() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.HSet(_keys[3], Field1, Value1); await dut.HSet(_keys[3], Field2, Value2); await dut.HSet(_keys[3], Field3, Value3); var res = await dut.HGetAll(_keys[3]); Assert.AreEqual(3, res.Count); Assert.AreEqual(Value1, res[Field1]); Assert.AreEqual(Value2, res[Field2]); Assert.AreEqual(Value3, res[Field3]); }
public async Task TestScriptLoadAndRun_List() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); var sha = await dut.LoadScript(ScriptWithListResult); Console.WriteLine(sha); var res = await dut.EvalSha(sha, new string[0]); var resList = res as object[]; Assert.AreEqual(2, resList?.Length); Assert.AreEqual("one", resList?[0] as string); Assert.AreEqual("two", resList?[1] as string); }
public async Task SwapDb_ClientConnectedToCorrectDb() { var underTest = LocalHostDefaultPort.CreateAndConnectClient(); await underTest.Select(0); await underTest.Set(Key, Value); await underTest.SwapDb(0, 7); var existsOnDb0 = await underTest.Exists(Key); await underTest.Select(7); var readValueFromDb7 = await underTest.Get(Key); existsOnDb0.Should().BeFalse(); readValueFromDb7.Should().Be(Value); }
public async Task TestWrongDbIndex_SelectWithSubscriptionClientThrowsException() { Exception thrownException = null; var dut = new AsyncRedisSubscriptionClient(); try { await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Select(int.MaxValue); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsInstanceOfType(thrownException, typeof(RedisException)); }
public async Task TestNotSubscribed_UnsubscribeThrowsException() { Exception thrownException = null; var dut = new AsyncRedisSubscriptionClient(); try { await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Unsubscribe("channel"); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsInstanceOfType(thrownException, typeof(InvalidOperationException)); }