Commit af9d22ed authored by yangxiaodong's avatar yangxiaodong

add model binder tests.

parent 13274160
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);
}
}
}
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; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment