diff --git a/test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs b/test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs new file mode 100644 index 0000000..accb17c --- /dev/null +++ b/test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Linq; +using System.Reflection; +using DotNetCore.CAP.Internal; +using Xunit; + +namespace DotNetCore.CAP.Test +{ + public class ModelBinderFactoryTest + { + IModelBinderFactory _factory; + + public ModelBinderFactoryTest() + { + _factory = new ModelBinderFactory(); + } + + [Theory] + [InlineData(nameof(Sample.DateTimeParam))] + [InlineData(nameof(Sample.StringParam))] + [InlineData(nameof(Sample.IntegerParam))] + [InlineData(nameof(Sample.GuidParam))] + [InlineData(nameof(Sample.UriParam))] + public void CreateSimpleTypeBinderTest(string methodName) + { + var datetimeMethod = typeof(Sample).GetRuntimeMethods().Single(x => x.Name == methodName); + var binder = _factory.CreateBinder(datetimeMethod.GetParameters()[0]); + Assert.NotNull(binder); + Assert.True(binder is SimpleTypeModelBinder); + Assert.False(binder is ComplexTypeModelBinder); + } + + [Theory] + [InlineData(nameof(Sample.ComplexTypeParam))] + public void CreateComplexTypeBinderTest(string methodName) + { + var datetimeMethod = typeof(Sample).GetRuntimeMethods().Single(x => x.Name == methodName); + var binder = _factory.CreateBinder(datetimeMethod.GetParameters()[0]); + Assert.NotNull(binder); + Assert.False(binder is SimpleTypeModelBinder); + Assert.True(binder is ComplexTypeModelBinder); + } + + } +} diff --git a/test/DotNetCore.CAP.Test/Sample.cs b/test/DotNetCore.CAP.Test/Sample.cs new file mode 100644 index 0000000..a383a1a --- /dev/null +++ b/test/DotNetCore.CAP.Test/Sample.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace DotNetCore.CAP.Test +{ + public class Sample + { + + public void DateTimeParam(DateTime dateTime) + { + + } + + public void StringParam(string @string) + { + + } + + public void GuidParam(Guid guid) + { + + } + + public void UriParam(Uri uri) + { + + } + + public void IntegerParam(int @int) + { + + } + + public void ComplexTypeParam(ComplexType complexType) + { + + } + } + + public class ComplexType + { + public DateTime Time { get; set; } + + public string String { get; set; } + + public Guid Guid { get; set; } + + public Person Person { get; set; } + } + + public class Person + { + public int Age { get; set; } + + public string Name { get; set; } + } +}