public void Should_not_put_when_disposed() { sink.Dispose(); sink.Put(Stream, _ => {}); factory.ReceivedCalls().Should().BeEmpty(); }
public void Should_send_correct_binary_data_to_gateway() { var key1 = "intValue"; var key2 = "longValue"; var byteKey1 = Encoding.UTF8.GetBytes(key1); var byteKey2 = Encoding.UTF8.GetBytes(key2); var value1 = 100500; var value2 = (long)1e16 + 5; var timestamp = DateTime.UtcNow; var unixTimestamp = EpochHelper.ToUnixTimeUtcTicks(timestamp); var size = +sizeof(byte) // protocol version + sizeof(long) // timestamp + GuidSize // guid + sizeof(ushort) // tag count + sizeof(byte) // key length + byteKey1.Length // key + sizeof(byte) // type tag + sizeof(int) // value + sizeof(byte) // key length + byteKey2.Length // key + sizeof(byte) // type tag + sizeof(long); // value const byte EventProtocolVersion = 1; const byte IntegerTag = 4; const byte LongTag = 5; var writer = new BinaryBufferWriter(size) { Endianness = Endianness.Big }; writer.Write(EventProtocolVersion); writer.Write(unixTimestamp); writer.Write(Guid.Empty); writer.Write((ushort)2); // first tag writer.Write((byte)byteKey1.Length); writer.WriteWithoutLength(byteKey1); writer.Write(IntegerTag); writer.Write(value1); // second tag writer.Write((byte)byteKey2.Length); writer.WriteWithoutLength(byteKey2); writer.Write(LongTag); writer.Write(value2); var recordCountContent = new byte[] { 0, 0, 0, 1 }; var recordContent = writer.FilledSegment; sink.Put( "stream", builder => builder .SetTimestamp(timestamp) .AddValue(key1, value1) .AddValue(key2, value2)); new Action( () => { var content = lastRequest?.Content?.ToArray(); if (content != null) { // ReSharper disable once PossibleNullReferenceException // ReSharper disable once AssignNullToNotNullAttribute var targetLength = int.Parse(lastRequest.Headers[Constants.Compression.OriginalContentLengthHeaderName]); var target = new byte[targetLength]; LZ4Codec.Decode(content, 0, content.Length, target, 0, targetLength); content = target; } var actualRecordsCountContent = content?.Take(sizeof(int)).ToArray(); var actualRecordContent = content?.Skip(sizeof(int)).ToArray(); actualRecordContent.Should().NotBeNull(); EraseEventId(actualRecordContent); actualRecordsCountContent.Should().BeEquivalentTo(recordCountContent, c => c.WithStrictOrdering()); actualRecordContent.Should().BeEquivalentTo(recordContent, c => c.WithStrictOrdering()); }).ShouldPassIn(5.Seconds()); }