SymbolRegistryTest.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Grpc.Reflection;
  17. using Grpc.Reflection.V1Alpha;
  18. using NUnit.Framework;
  19. namespace Grpc.Reflection.Tests
  20. {
  21. /// <summary>
  22. /// Tests for ReflectionServiceImpl
  23. /// </summary>
  24. public class SymbolRegistryTest
  25. {
  26. SymbolRegistry registry = SymbolRegistry.FromFiles(new[] { ReflectionReflection.Descriptor, Google.Protobuf.WellKnownTypes.Duration.Descriptor.File });
  27. [Test]
  28. public void FileByName()
  29. {
  30. Assert.AreSame(Google.Protobuf.WellKnownTypes.Duration.Descriptor.File, registry.FileByName("google/protobuf/duration.proto"));
  31. Assert.IsNull(registry.FileByName("somepackage/nonexistent.proto"));
  32. }
  33. [Test]
  34. public void FileContainingSymbol()
  35. {
  36. Assert.AreSame(Google.Protobuf.WellKnownTypes.Duration.Descriptor.File, registry.FileContainingSymbol("google.protobuf.Duration"));
  37. Assert.AreSame(ReflectionReflection.Descriptor, registry.FileContainingSymbol("grpc.reflection.v1alpha.ServerReflection.ServerReflectionInfo")); // method
  38. Assert.AreSame(ReflectionReflection.Descriptor, registry.FileContainingSymbol("grpc.reflection.v1alpha.ServerReflection")); // service
  39. Assert.AreSame(ReflectionReflection.Descriptor, registry.FileContainingSymbol("grpc.reflection.v1alpha.ServerReflectionRequest")); // message
  40. Assert.IsNull(registry.FileContainingSymbol("somepackage.Nonexistent"));
  41. }
  42. }
  43. }