You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModelBinderFactoryTest.cs 1.5 KiB

7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Linq;
  2. using System.Reflection;
  3. using DotNetCore.CAP.Internal;
  4. using Xunit;
  5. namespace DotNetCore.CAP.Test
  6. {
  7. public class ModelBinderFactoryTest
  8. {
  9. private IModelBinderFactory _factory;
  10. public ModelBinderFactoryTest()
  11. {
  12. _factory = new ModelBinderFactory();
  13. }
  14. [Theory]
  15. [InlineData(nameof(Sample.DateTimeParam))]
  16. [InlineData(nameof(Sample.StringParam))]
  17. [InlineData(nameof(Sample.IntegerParam))]
  18. [InlineData(nameof(Sample.GuidParam))]
  19. [InlineData(nameof(Sample.UriParam))]
  20. public void CreateSimpleTypeBinderTest(string methodName)
  21. {
  22. var methodInfo = typeof(Sample).GetRuntimeMethods().Single(x => x.Name == methodName);
  23. var binder = _factory.CreateBinder(methodInfo.GetParameters()[0]);
  24. Assert.NotNull(binder);
  25. Assert.True(binder is SimpleTypeModelBinder);
  26. Assert.False(binder is ComplexTypeModelBinder);
  27. }
  28. [Theory]
  29. [InlineData(nameof(Sample.ComplexTypeParam))]
  30. public void CreateComplexTypeBinderTest(string methodName)
  31. {
  32. var methodInfo = typeof(Sample).GetRuntimeMethods().Single(x => x.Name == methodName);
  33. var binder = _factory.CreateBinder(methodInfo.GetParameters()[0]);
  34. Assert.NotNull(binder);
  35. Assert.False(binder is SimpleTypeModelBinder);
  36. Assert.True(binder is ComplexTypeModelBinder);
  37. }
  38. }
  39. }