Browse Source

add model binder tests.

master
yangxiaodong 7 years ago
parent
commit
af9d22edaf
2 changed files with 105 additions and 0 deletions
  1. +47
    -0
      test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs
  2. +58
    -0
      test/DotNetCore.CAP.Test/Sample.cs

+ 47
- 0
test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs View File

@@ -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);
}

}
}

+ 58
- 0
test/DotNetCore.CAP.Test/Sample.cs View File

@@ -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; }
}
}

Loading…
Cancel
Save