public async Task ShouldPackAndUnpackBytes() { // Given var byteArray = PackStreamBitConverter.GetBytes("hello, world"); // When var session = Server.Driver.AsyncSession(); try { var cursor = await session.RunAsync( "CREATE (a {value:{value}}) RETURN a.value", new Dictionary <string, object> { { "value", byteArray } }); var value = await cursor.SingleAsync(r => r["a.value"].As <byte[]>()); // Then value.Should().BeEquivalentTo(byteArray); } finally { await session.CloseAsync(); } }
public void ShouldThrowExceptionWhenReadBytes32ReturnsBytesSizeLonggerThanIntMax() { var mockInput = IOExtensions.CreateMockStream(PackStream.Bytes32, PackStreamBitConverter.GetBytes((int)-1)); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var ex = Xunit.Record.Exception(() => reader.ReadBytes()); ex.Should().BeOfType <ProtocolException>(); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2)); }
public void ShouldReadStruct16() { var mockInput = IOExtensions.CreateMockStream(PackStream.Struct16, PackStreamBitConverter.GetBytes((short)1)); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var header = reader.ReadStructHeader(); header.Should().Be(1); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once); }
public void ShouldReadString32() { var mockInput = IOExtensions.CreateMockStream(new byte[] { PackStream.String32 }, PackStreamBitConverter.GetBytes((int)1), new byte[] { 0x61 }); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var real = reader.ReadString(); real.Should().Be("a"); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3)); }
private static byte[] PackVersions(IEnumerable <int> versions) { var aLittleBitOfMagic = PackStreamBitConverter.GetBytes(BoltIdentifier); var bytes = new List <byte>(aLittleBitOfMagic); foreach (var version in versions) { bytes.AddRange(PackStreamBitConverter.GetBytes(version)); } return(bytes.ToArray()); }
public void ShouldReadBytes16() { var mockInput = IOExtensions.CreateMockStream(new byte[] { PackStream.Bytes16 }, PackStreamBitConverter.GetBytes((short)1), new byte[] { 0x61 }); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var real = reader.ReadBytes(); real.Length.Should().Be(1); real.Should().Contain(0x61); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3)); }
public async Task ShouldConnectServerAsync() { var bufferSettings = new BufferSettings(Config.Default); var version = new BoltProtocolVersion(4, 1); var connMock = new Mock <ITcpSocketClient>(); TcpSocketClientTestSetup.CreateReadStreamMock(connMock, PackStreamBitConverter.GetBytes(version.PackToInt())); TcpSocketClientTestSetup.CreateWriteStreamMock(connMock); PackStreamBitConverter.GetBytes((int)0x14); var client = new SocketClient(FakeUri, null, bufferSettings, socketClient: connMock.Object); await client.ConnectAsync(new Dictionary <string, string>()); // Then connMock.Verify(x => x.ConnectAsync(FakeUri), Times.Once); }
public void ShouldNotPackBytes() { // Given byte[] byteArray = PackStreamBitConverter.GetBytes("hello, world"); // When using (var session = Server.Driver.Session()) { var exception = Record.Exception(() => session.Run("CREATE (a {value:{value}})", new Dictionary <string, object> { { "value", byteArray } })); // Then exception.Should().BeOfType <ProtocolException>(); exception.Message.Should().Be("Cannot understand values with type System.Byte[]"); } }
public void ShouldPackAndUnpackBytes() { // Given byte[] byteArray = PackStreamBitConverter.GetBytes("hello, world"); // When using (var session = Server.Driver.Session()) { var result = session.Run( "CREATE (a {value:{value}}) RETURN a.value", new Dictionary <string, object> { { "value", byteArray } }); // Then foreach (var record in result) { var value = record["a.value"].ValueAs <byte[]>(); value.Should().BeEquivalentTo(byteArray); } } }
public void ShouldReadDoubleCorrectly() { const double expected = 1.12; var mockInput = IOExtensions.CreateMockStream(PackStream.Float64, PackStreamBitConverter.GetBytes(expected)); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var real = reader.ReadDouble(); real.Should().Be(expected); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2)); }
public void ShouldReadLongAsInt() { const int expected = 1024; var mockInput = IOExtensions.CreateMockStream(PackStream.Int32, PackStreamBitConverter.GetBytes(expected)); var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers); var real = reader.ReadLong(); real.Should().Be(expected); mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2)); }