PageRenderTime 47ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Bson.Tests/IO/TrieNameDecoderTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 69 lines | 44 code | 11 blank | 14 comment | 0 complexity | ea3bf33337abd78f6c68293cafad949f MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System.IO;
  16. using FluentAssertions;
  17. using MongoDB.Bson.IO;
  18. using Xunit;
  19. namespace MongoDB.Bson.Tests.IO
  20. {
  21. public class TrieNameDecoderTests
  22. {
  23. [Fact]
  24. public void Should_read_name_when_trie_does_not_know_about_the_name()
  25. {
  26. var trie = new BsonTrie<int>();
  27. trie.Add("known", 10);
  28. Assert(trie, "different");
  29. }
  30. [Fact]
  31. public void Should_read_name_when_trie_holds_a_longer_version_of_the_name()
  32. {
  33. var trie = new BsonTrie<int>();
  34. trie.Add("longer", 10);
  35. Assert(trie, "long");
  36. }
  37. [Fact]
  38. public void Should_read_name_when_trie_knows_about_the_name()
  39. {
  40. var trie = new BsonTrie<int>();
  41. trie.Add("known", 10);
  42. Assert(trie, "known");
  43. }
  44. private void Assert(BsonTrie<int> trie, string name)
  45. {
  46. var subject = new TrieNameDecoder<int>(trie);
  47. using (var memoryStream = new MemoryStream())
  48. using (var bsonStream = new BsonStreamAdapter(memoryStream))
  49. {
  50. bsonStream.WriteCString(name);
  51. bsonStream.WriteInt32(20);
  52. bsonStream.Position = 0;
  53. var result = subject.Decode(bsonStream, Utf8Encodings.Strict);
  54. result.Should().Be(name);
  55. }
  56. }
  57. }
  58. }