25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
1.6 KiB

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