public void ShouldParseBulkString() { var source = new DummySocketReader("11\r\nHello world\r\nblahblahblah"); RESPBulkString str = RESPBulkString.Load(source); Assert.AreEqual("Hello world", str.Value); }
public void ShouldParseNegativeInteger() { var source = new DummySocketReader("-5\r\nblahblahblah"); RESPInteger integer = RESPInteger.Load(source); Assert.AreEqual(-5L, integer.Value); }
public void ShouldParseBulkStringWithLineBreakAtTheEnd() { var source = new DummySocketReader("14\r\nHello\r\nworld\r\n\r\n"); RESPBulkString str = RESPBulkString.Load(source); Assert.AreEqual("Hello\r\nworld\r\n", str.Value); }
public void ShouldParseEmptyBulkString() { var source = new DummySocketReader("0\r\n\r\n"); RESPBulkString str = RESPBulkString.Load(source); Assert.AreEqual(String.Empty, str.Value); }
public void ShouldParseNullBulkString() { var source = new DummySocketReader("-1\r\n"); RESPBulkString str = RESPBulkString.Load(source); Assert.AreEqual(null, str.Value); }
public void IgnoresExistingProcedures() { var bydigest = new Dictionary <String, ProcedureDefinition> { { "digest1", new ProcedureDefinition() { Body = "digestBody1" } }, { "digest2", new ProcedureDefinition() { Body = "digestBody2" } } }; var byalias = new Dictionary <String, ProcedureDefinition>(); var procedures = new ProcedureCollection(byalias, bydigest); var initializer = new ProcedureInitializer(procedures, NoLogger.Instance); var writtingStream = new MemoryStream(); var reader = new DummySocketReader("*2\r\n:1\r\n:1\r\n"); var writer = new DummySocketWriter(writtingStream); initializer.Initialize(reader, writer); writer.Flush(); writtingStream.Seek(0, SeekOrigin.Begin); Assert.AreEqual("*4\r\n$6\r\nSCRIPT\r\n$6\r\nexists\r\n$7\r\ndigest1\r\n$7\r\ndigest2\r\n", new StreamReader(writtingStream).ReadToEnd()); }
public void CanParseEmptyArray() { var source = new DummySocketReader("0\r\n"); RESPArray array = RESPArray.Load(source); Assert.AreEqual(0, array.Count); }
public void ShouldParseErrorWithOnlyPrefix() { var source = new DummySocketReader("ERR\r\nblahblahblah"); RESPError err = RESPError.Load(source); Assert.AreEqual("ERR", err.Prefix); Assert.IsNull(err.Message); }
public void ShouldParseError() { var source = new DummySocketReader("ERR Message\r\nblahblahblah"); RESPError err = RESPError.Load(source); Assert.AreEqual("ERR", err.Prefix); Assert.AreEqual("Message", err.Message); }
public void IgnoresNoInitialization() { var initializer = new ConnectionInitializer(new RedisClientOptions()); var writtingStream = new MemoryStream(); var reader = new DummySocketReader(null); var writer = new DummySocketWriter(writtingStream); initializer.Initialize(reader, writer); }
public void DetectMissingResponseErrors() { var options = new RedisClientOptions(); options.InitializationCommands.Add(new PreInitializationCommand("auth vtortola")); var initializer = new ConnectionInitializer(options); var writtingStream = new MemoryStream(); var reader = new DummySocketReader(null); var writer = new DummySocketWriter(writtingStream); initializer.Initialize(reader, writer); }
public void CanParseArrayOfArrays() { var source = new DummySocketReader("2\r\n*3\r\n+This is level 1\r\n$16\r\nNested\r\nArray\r\n1\r\n:1\r\n*3\r\n+This is level 2\r\n$16\r\nNested\r\nArray\r\n2\r\n:2\r\n"); RESPArray array = RESPArray.Load(source); Assert.AreEqual(2, array.Count); var nested1 = array.ElementAt <RESPArray>(0); Assert.AreEqual(3, nested1.Count); var nested2 = array.ElementAt <RESPArray>(1); Assert.AreEqual(3, nested2.Count); }
public void IgnoresNoInitialization() { var procedures = new ProcedureCollection(); var initializer = new ProcedureInitializer(procedures, NoLogger.Instance); var writtingStream = new MemoryStream(); var reader = new DummySocketReader(null); var writer = new DummySocketWriter(writtingStream); initializer.Initialize(reader, writer); writer.Flush(); writtingStream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(0, writtingStream.Position); }
public void InitializesWithCommands() { var options = new RedisClientOptions(); options.InitializationCommands.Add(new PreInitializationCommand("auth vtortola")); var initializer = new ConnectionInitializer(options); var writtingStream = new MemoryStream(); var reader = new DummySocketReader("+OK\r\n"); var writer = new DummySocketWriter(writtingStream); initializer.Initialize(reader, writer); writtingStream.Seek(0, SeekOrigin.Begin); Assert.AreEqual("*2\r\n$4\r\nAUTH\r\n$8\r\nvtortola\r\n", new StreamReader(writtingStream).ReadToEnd()); }
public void CanParseArrayWithNullElement() { var source = new DummySocketReader("3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n"); RESPArray array = RESPArray.Load(source); Assert.AreEqual(3, array.Count); var item1 = array.ElementAt <RESPBulkString>(0); Assert.AreEqual("foo", item1.Value); var item2 = array.ElementAt <RESPBulkString>(1); Assert.AreEqual(null, item2.Value); var item3 = array.ElementAt <RESPBulkString>(2); Assert.AreEqual("bar", item3.Value); }
public void CanParseArrayWithBreaks() { var source = new DummySocketReader("3\r\n+Hello\r\n$12\r\nBig\r\nWorld\r\n\r\n:1\r\n"); RESPArray array = RESPArray.Load(source); Assert.AreEqual(3, array.Count); var item1 = array.ElementAt <RESPSimpleString>(0); Assert.AreEqual("Hello", item1.Value); var item2 = array.ElementAt <RESPBulkString>(1); Assert.AreEqual("Big\r\nWorld\r\n", item2.Value); var item3 = array.ElementAt <RESPInteger>(2); Assert.AreEqual(1L, item3.Value); }
public void CombinedResponses() { var str = ":45\r\n+OK\r\n$0\r\n\r\n$5\r\nhello\r\n$-1\r\n*0\r\n*-1\r\n+OK\r\n"; for (int i = 1; i < str.Length + 10; i++) { var source = new DummySocketReader(str, i); Assert.AreEqual(45, RESPObject.Read <RESPInteger>(source).Value); Assert.AreEqual("OK", RESPObject.Read <RESPSimpleString>(source).Value); Assert.AreEqual(String.Empty, RESPObject.Read <RESPBulkString>(source).Value); Assert.AreEqual("hello", RESPObject.Read <RESPBulkString>(source).Value); Assert.AreEqual(null, RESPObject.Read <RESPBulkString>(source).Value); Assert.AreEqual(0, RESPObject.Read <RESPArray>(source).Count); Assert.AreEqual(0, RESPObject.Read <RESPArray>(source).Count); Assert.AreEqual("OK", RESPObject.Read <RESPSimpleString>(source).Value); } }