private void Assert(BsonTrie<int> trie, string name) { var subject = new TrieNameDecoder<int>(trie); using (var memoryStream = new MemoryStream()) using (var bsonStream = new BsonStreamAdapter(memoryStream)) { bsonStream.WriteCString(name); bsonStream.WriteInt32(20); bsonStream.Position = 0; var result = subject.Decode(bsonStream, Utf8Encodings.Strict); result.Should().Be(name); } }
public void WriteInt32_should_write_expected_bytes( [Values(-1, 0, 1, int.MaxValue, int.MinValue)] int value) { var stream = new MemoryStream(); var subject = new BsonStreamAdapter(stream); var expectedBytes = BitConverter.GetBytes(value); subject.WriteInt32(value); stream.ToArray().Should().Equal(expectedBytes); }
public void WriteInt32_should_throw_when_subject_is_disposed() { var stream = Substitute.For<Stream>(); var subject = new BsonStreamAdapter(stream); subject.Dispose(); Action action = () => subject.WriteInt32(1); action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter"); }
public void WriteInt32_should_be_little_endian() { var stream = new MemoryStream(); var subject = new BsonStreamAdapter(stream); var value = 0x01020304; var expectedBytes = new byte[] { 4, 3, 2, 1 }; subject.WriteInt32(value); stream.ToArray().Should().Equal(expectedBytes); }