Bläddra i källkod

add model binder tests.

master
yangxiaodong 7 år sedan
förälder
incheckning
af9d22edaf
2 ändrade filer med 105 tillägg och 0 borttagningar
  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 Visa fil

@@ -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 Visa fil

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

Laddar…
Avbryt
Spara