Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Completed re-write of MqMessageReader and MqMessageWriter.
Browse files Browse the repository at this point in the history
Reader and Writer now will use the specified encoding.
Char writing overhauled to use encoding.
Added overrides for char writing.
Added tests.
  • Loading branch information
DJGosnell committed Aug 22, 2016
1 parent 2cd4097 commit 0b0ef8a
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DtronixMessageQueue.Tests/DtronixMessageQueue.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<Compile Include="MqFrameBuilderTests.cs" />
<Compile Include="MqFrameTests.cs" />
<Compile Include="MqServerTests.cs" />
<Compile Include="MqMessageBuilderReaderTests.cs" />
<Compile Include="MqMessageWriterReaderTests.cs" />
<Compile Include="MqTestsBase.cs" />
<Compile Include="PerformanceTests.cs" />
<Compile Include="MqClientTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
using Assert = Xunit.Assert;

namespace DtronixMessageQueue.Tests {
public class MqMessageBuilderReaderTests {
public class MqMessageWriterReaderTests {
public ITestOutputHelper Output;
private MqMessageWriter message_builder;
private MqMessageReader message_reader;

private const string FillerText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

public MqMessageBuilderReaderTests(ITestOutputHelper output) {
public MqMessageWriterReaderTests(ITestOutputHelper output) {
this.Output = output;
message_builder = new MqMessageWriter();
message_reader = new MqMessageReader();
}

[Fact]
public void MessageBuilder_writes_bool_true() {
public void MessageWriter_writes_bool_true() {
var expected_value = (bool) true;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -30,7 +30,7 @@ public void MessageBuilder_writes_bool_true() {
}

[Fact]
public void MessageBuilder_writes_bool_false() {
public void MessageWriter_writes_bool_false() {
var expected_value = (bool)false;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -41,7 +41,7 @@ public void MessageBuilder_writes_bool_false() {
}

[Fact]
public void MessageBuilder_writes_byte() {
public void MessageWriter_writes_byte() {
var expected_value = (byte)221;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -53,7 +53,7 @@ public void MessageBuilder_writes_byte() {
}

[Fact]
public void MessageBuilder_writes_sbyte_positive() {
public void MessageWriter_writes_sbyte_positive() {
var expected_value = (sbyte)101;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -64,7 +64,7 @@ public void MessageBuilder_writes_sbyte_positive() {
}

[Fact]
public void MessageBuilder_writes_sbyte_negative() {
public void MessageWriter_writes_sbyte_negative() {
var expected_value = (sbyte)-101;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -75,18 +75,7 @@ public void MessageBuilder_writes_sbyte_negative() {
}

[Fact]
public void MessageBuilder_writes_char() {
var expected_value = (char)'D';
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
message_reader.Message = message;

Assert.Equal(expected_value, message_reader.ReadChar());
Assert.True(message_reader.IsAtEnd);
}

[Fact]
public void MessageBuilder_writes_short_positive() {
public void MessageWriter_writes_short_positive() {
var expected_value = (short)21457;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -97,7 +86,7 @@ public void MessageBuilder_writes_short_positive() {
}

[Fact]
public void MessageBuilder_writes_short_negative() {
public void MessageWriter_writes_short_negative() {
var expected_value = (short)-21457;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -108,7 +97,7 @@ public void MessageBuilder_writes_short_negative() {
}

[Fact]
public void MessageBuilder_writes_ushort() {
public void MessageWriter_writes_ushort() {
var expected_value = (ushort)51574;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -119,7 +108,7 @@ public void MessageBuilder_writes_ushort() {
}

[Fact]
public void MessageBuilder_writes_int_positive() {
public void MessageWriter_writes_int_positive() {
var expected_value = (int)515725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -130,7 +119,7 @@ public void MessageBuilder_writes_int_positive() {
}

[Fact]
public void MessageBuilder_writes_int_negative() {
public void MessageWriter_writes_int_negative() {
var expected_value = (int)-515725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -141,7 +130,7 @@ public void MessageBuilder_writes_int_negative() {
}

[Fact]
public void MessageBuilder_writes_uint() {
public void MessageWriter_writes_uint() {
var expected_value = (uint)1215725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -152,7 +141,7 @@ public void MessageBuilder_writes_uint() {
}

[Fact]
public void MessageBuilder_writes_long_positive() {
public void MessageWriter_writes_long_positive() {
var expected_value = (long)515352135236725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -163,7 +152,7 @@ public void MessageBuilder_writes_long_positive() {
}

[Fact]
public void MessageBuilder_writes_long_negative() {
public void MessageWriter_writes_long_negative() {
var expected_value = (long)-515352135236725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -174,7 +163,7 @@ public void MessageBuilder_writes_long_negative() {
}

[Fact]
public void MessageBuilder_writes_ulong() {
public void MessageWriter_writes_ulong() {
var expected_value = (ulong)12231512365365725234;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -185,7 +174,7 @@ public void MessageBuilder_writes_ulong() {
}

[Fact]
public void MessageBuilder_writes_float() {
public void MessageWriter_writes_float() {
var expected_value = (float)123.456;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -196,7 +185,7 @@ public void MessageBuilder_writes_float() {
}

[Fact]
public void MessageBuilder_writes_double() {
public void MessageWriter_writes_double() {
var expected_value = (double)12345.67891;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -207,7 +196,7 @@ public void MessageBuilder_writes_double() {
}

[Fact]
public void MessageBuilder_writes_decimal() {
public void MessageWriter_writes_decimal() {
var expected_value = (decimal)9123456789123456789.9123456789123456789;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand All @@ -218,7 +207,7 @@ public void MessageBuilder_writes_decimal() {
}

[Fact]
public void MessageBuilder_writes_multi_frame_byte_array() {
public void MessageWriter_writes_multi_frame_byte_array() {
var expected_value = new byte[1024*32];
var number = 0;
for (int i = 0; i < 1024 * 32; i++) {
Expand Down Expand Up @@ -254,7 +243,7 @@ private void VerifyMessageBytes(byte[] expected_value, MqMessage message) {
}

[Fact]
public void MessageBuilder_writes_multi_frame_string_bytes() {
public void MessageWriter_writes_multi_frame_string_bytes() {
var sb = new StringBuilder();

for (int i = 0; i < 100; i++) {
Expand Down Expand Up @@ -302,7 +291,7 @@ public void MessageReader_reads_multi_frame_byte_array() {


[Fact]
public void MessageBuilder_writes_string() {
public void MessageWriter_writes_string() {
var expected_value = FillerText;
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
Expand Down Expand Up @@ -339,6 +328,7 @@ public void MessageWriter_multiple_reads_writes() {
message_builder.Write(false);

message_builder.Write((char)'D');
message_builder.Write(new char[] { 'A', 'Y', 'X', '0', '9', '8'});

message_builder.Write((byte)214);
message_builder.Write((sbyte)125);
Expand Down Expand Up @@ -373,6 +363,8 @@ public void MessageWriter_multiple_reads_writes() {
Assert.Equal(false, message_reader.ReadBoolean());

Assert.Equal('D', message_reader.ReadChar());
Assert.Equal(new char[] { 'A', 'Y', 'X', '0', '9', '8' }, message_reader.ReadChars(6));


Assert.Equal((byte)214, message_reader.ReadByte());
Assert.Equal((sbyte)125, message_reader.ReadSByte());
Expand All @@ -399,7 +391,57 @@ public void MessageWriter_multiple_reads_writes() {
Assert.Equal(expected_byte_array, read_byte_array);

Assert.Equal(FillerText, message_reader.ReadString());
Assert.True(message_reader.IsAtEnd);
}


[Fact]
public void MessageWriter_writes_char() {
var expected_value = (char)'D';
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
message_reader.Message = message;

Assert.Equal(expected_value, message_reader.ReadChar());
Assert.True(message_reader.IsAtEnd);
}

[Fact]
public void MessageWriter_writes_char_array() {
var expected_value = new char[] {'A', 'B', 'C', '1', '2', '3'};
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
message_reader.Message = message;

Assert.Equal(expected_value, message_reader.ReadChars(expected_value.Length));
Assert.True(message_reader.IsAtEnd);
}

[Fact]
public void MessageWriter_writes_char_array_slice() {
var input_value = new char[] { 'A', 'B', 'C', '1', '2', '3' };
var expected_value = new char[] { 'B', 'C', '1', '2'};
message_builder.Write(input_value, 1, 4);
var message = message_builder.ToMessage();
message_reader.Message = message;

Assert.Equal(expected_value, message_reader.ReadChars(expected_value.Length));
Assert.True(message_reader.IsAtEnd);
}

[Fact]
public void MessageReader_peeks_char() {
var expected_value = new char[] { 'D', 'Z' };
message_builder.Write(expected_value);
var message = message_builder.ToMessage();
message_reader.Message = message;

Assert.Equal(expected_value[0], message_reader.PeekChar());
Assert.Equal(expected_value, message_reader.ReadChars(expected_value.Length));
Assert.True(message_reader.IsAtEnd);
}



}
}
Loading

0 comments on commit 0b0ef8a

Please sign in to comment.