PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Events/ReflectionEventSubscriberTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 73 lines | 43 code | 16 blank | 14 comment | 0 complexity | 2d2e91c18491051e5948f7ad54174e19 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-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;
  16. using FluentAssertions;
  17. using Xunit;
  18. namespace MongoDB.Driver.Core.Events
  19. {
  20. public class ReflectionEventSubscriberTests
  21. {
  22. [Fact]
  23. public void Should_match_all_methods_matching_the_required_signature()
  24. {
  25. var subject = new ReflectionEventSubscriber(new EventTest());
  26. Action<int> i;
  27. subject.TryGetEventHandler(out i).Should().BeTrue();
  28. Action<string> str;
  29. subject.TryGetEventHandler(out str).Should().BeTrue();
  30. Action<byte> b;
  31. subject.TryGetEventHandler(out b).Should().BeFalse();
  32. Action<bool> boolean;
  33. subject.TryGetEventHandler(out boolean).Should().BeFalse();
  34. Action<bool> c;
  35. subject.TryGetEventHandler(out c).Should().BeFalse();
  36. }
  37. private class EventTest
  38. {
  39. public void Handle(int i)
  40. {
  41. }
  42. public void Handle(string s)
  43. {
  44. }
  45. public void WrongName(byte b)
  46. {
  47. }
  48. public bool Handle(bool k) // wrong signature
  49. {
  50. return k;
  51. }
  52. private void Handle(char c) // not public
  53. {
  54. }
  55. }
  56. }
  57. }