MetadataArraySafeHandleTest.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #region Copyright notice and license
  2. // Copyright 2015 gRPC authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using Grpc.Core;
  18. using Grpc.Core.Internal;
  19. using Grpc.Core.Utils;
  20. using NUnit.Framework;
  21. namespace Grpc.Core.Internal.Tests
  22. {
  23. public class MetadataArraySafeHandleTest
  24. {
  25. [Test]
  26. public void CreateEmptyAndDestroy()
  27. {
  28. var nativeMetadata = MetadataArraySafeHandle.Create(new Metadata());
  29. nativeMetadata.Dispose();
  30. }
  31. [Test]
  32. public void CreateAndDestroy()
  33. {
  34. var metadata = new Metadata
  35. {
  36. { "host", "somehost" },
  37. { "header2", "header value" },
  38. };
  39. var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
  40. nativeMetadata.Dispose();
  41. }
  42. [Test]
  43. public void ReadMetadataFromPtrUnsafe()
  44. {
  45. var metadata = new Metadata
  46. {
  47. { "host", "somehost" },
  48. { "header2", "header value" }
  49. };
  50. var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
  51. var copy = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(nativeMetadata.Handle);
  52. Assert.AreEqual(2, copy.Count);
  53. Assert.AreEqual("host", copy[0].Key);
  54. Assert.AreEqual("somehost", copy[0].Value);
  55. Assert.AreEqual("header2", copy[1].Key);
  56. Assert.AreEqual("header value", copy[1].Value);
  57. nativeMetadata.Dispose();
  58. }
  59. }
  60. }