parent
f0c2d7ed25
commit
ca62719f9d
|
|
@ -8,6 +8,7 @@ using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Diagnostics.Entity.Views;
|
using Microsoft.AspNet.Diagnostics.Entity.Views;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Data.Entity
|
namespace Microsoft.Data.Entity
|
||||||
|
|
@ -25,21 +26,22 @@ namespace Microsoft.Data.Entity
|
||||||
protected const BindingFlags AnyInstance
|
protected const BindingFlags AnyInstance
|
||||||
= BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
= BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact(Skip = "Skipping until we update to mono")]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public void Public_inheritable_apis_should_be_virtual()
|
public void Public_inheritable_apis_should_be_virtual()
|
||||||
{
|
{
|
||||||
var nonVirtualMethods
|
var nonVirtualMethods
|
||||||
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
||||||
where type.IsVisible
|
where type.IsVisible
|
||||||
&& !type.IsSealed
|
&& !type.IsSealed
|
||||||
&& type.DeclaredConstructors.Any(c => c.IsPublic || c.IsFamily || c.IsFamilyOrAssembly)
|
&& type.DeclaredConstructors.Any(c => c.IsPublic || c.IsFamily || c.IsFamilyOrAssembly)
|
||||||
&& type.Namespace != null
|
&& type.Namespace != null
|
||||||
&& !type.Namespace.EndsWith(".Compiled")
|
&& !type.Namespace.EndsWith(".Compiled")
|
||||||
&& !_typesToSkip.Contains(type)
|
&& !_typesToSkip.Contains(type)
|
||||||
from method in type.DeclaredMethods.Where(m => m.IsPublic && !m.IsStatic)
|
from method in type.DeclaredMethods.Where(m => m.IsPublic && !m.IsStatic)
|
||||||
where method.DeclaringType.GetTypeInfo() == type
|
where method.DeclaringType.GetTypeInfo() == type
|
||||||
&& !(method.IsVirtual && !method.IsFinal)
|
&& !(method.IsVirtual && !method.IsFinal)
|
||||||
select type.FullName + "." + method.Name)
|
select type.FullName + "." + method.Name)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
Assert.False(
|
Assert.False(
|
||||||
|
|
@ -47,26 +49,27 @@ namespace Microsoft.Data.Entity
|
||||||
"\r\n-- Missing virtual APIs --\r\n" + string.Join("\r\n", nonVirtualMethods));
|
"\r\n-- Missing virtual APIs --\r\n" + string.Join("\r\n", nonVirtualMethods));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact(Skip = "Skipping until we update to mono")]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public void Public_api_arguments_should_have_not_null_annotation()
|
public void Public_api_arguments_should_have_not_null_annotation()
|
||||||
{
|
{
|
||||||
var parametersMissingAttribute
|
var parametersMissingAttribute
|
||||||
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
||||||
where type.IsVisible && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(type) && !_typesToSkip.Contains(type)
|
where type.IsVisible && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(type) && !_typesToSkip.Contains(type)
|
||||||
let interfaceMappings = type.ImplementedInterfaces.Select(type.GetRuntimeInterfaceMap)
|
let interfaceMappings = type.ImplementedInterfaces.Select(type.GetRuntimeInterfaceMap)
|
||||||
let events = type.DeclaredEvents
|
let events = type.DeclaredEvents
|
||||||
from method in type.DeclaredMethods.Where(m => m.IsPublic)
|
from method in type.DeclaredMethods.Where(m => m.IsPublic)
|
||||||
.Concat<MethodBase>(type.DeclaredConstructors)
|
.Concat<MethodBase>(type.DeclaredConstructors)
|
||||||
where method.DeclaringType.GetTypeInfo() == type
|
where method.DeclaringType.GetTypeInfo() == type
|
||||||
where type.IsInterface || !interfaceMappings.Any(im => im.TargetMethods.Contains(method))
|
where type.IsInterface || !interfaceMappings.Any(im => im.TargetMethods.Contains(method))
|
||||||
where !events.Any(e => e.AddMethod == method || e.RemoveMethod == method)
|
where !events.Any(e => e.AddMethod == method || e.RemoveMethod == method)
|
||||||
from parameter in method.GetParameters()
|
from parameter in method.GetParameters()
|
||||||
where !parameter.ParameterType.GetTypeInfo().IsValueType
|
where !parameter.ParameterType.GetTypeInfo().IsValueType
|
||||||
&& !parameter.GetCustomAttributes()
|
&& !parameter.GetCustomAttributes()
|
||||||
.Any(
|
.Any(
|
||||||
a => a.GetType().Name == "NotNullAttribute"
|
a => a.GetType().Name == "NotNullAttribute"
|
||||||
|| a.GetType().Name == "CanBeNullAttribute")
|
|| a.GetType().Name == "CanBeNullAttribute")
|
||||||
select type.FullName + "." + method.Name + "[" + parameter.Name + "]")
|
select type.FullName + "." + method.Name + "[" + parameter.Name + "]")
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
Assert.False(
|
Assert.False(
|
||||||
|
|
@ -74,34 +77,35 @@ namespace Microsoft.Data.Entity
|
||||||
"\r\n-- Missing NotNull annotations --\r\n" + string.Join("\r\n", parametersMissingAttribute));
|
"\r\n-- Missing NotNull annotations --\r\n" + string.Join("\r\n", parametersMissingAttribute));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact(Skip = "Skipping until we update to mono")]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||||
public void Async_methods_should_have_overload_with_cancellation_token_and_end_with_async_suffix()
|
public void Async_methods_should_have_overload_with_cancellation_token_and_end_with_async_suffix()
|
||||||
{
|
{
|
||||||
var asyncMethods
|
var asyncMethods
|
||||||
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
|
||||||
where type.IsVisible
|
where type.IsVisible
|
||||||
from method in type.DeclaredMethods.Where(m => m.IsPublic)
|
from method in type.DeclaredMethods.Where(m => m.IsPublic)
|
||||||
where method.DeclaringType.GetTypeInfo() == type
|
where method.DeclaringType.GetTypeInfo() == type
|
||||||
where typeof(Task).IsAssignableFrom(method.ReturnType)
|
where typeof(Task).IsAssignableFrom(method.ReturnType)
|
||||||
select method).ToList();
|
select method).ToList();
|
||||||
|
|
||||||
var asyncMethodsWithToken
|
var asyncMethodsWithToken
|
||||||
= (from method in asyncMethods
|
= (from method in asyncMethods
|
||||||
where method.GetParameters().Any(pi => pi.ParameterType == typeof(CancellationToken))
|
where method.GetParameters().Any(pi => pi.ParameterType == typeof(CancellationToken))
|
||||||
select method).ToList();
|
select method).ToList();
|
||||||
|
|
||||||
var asyncMethodsWithoutToken
|
var asyncMethodsWithoutToken
|
||||||
= (from method in asyncMethods
|
= (from method in asyncMethods
|
||||||
where method.GetParameters().All(pi => pi.ParameterType != typeof(CancellationToken))
|
where method.GetParameters().All(pi => pi.ParameterType != typeof(CancellationToken))
|
||||||
select method).ToList();
|
select method).ToList();
|
||||||
|
|
||||||
var missingOverloads
|
var missingOverloads
|
||||||
= (from methodWithoutToken in asyncMethodsWithoutToken
|
= (from methodWithoutToken in asyncMethodsWithoutToken
|
||||||
where !asyncMethodsWithToken
|
where !asyncMethodsWithToken
|
||||||
.Any(methodWithToken => methodWithoutToken.Name == methodWithToken.Name
|
.Any(methodWithToken => methodWithoutToken.Name == methodWithToken.Name
|
||||||
&& methodWithoutToken.DeclaringType == methodWithToken.DeclaringType)
|
&& methodWithoutToken.DeclaringType == methodWithToken.DeclaringType)
|
||||||
// ReSharper disable once PossibleNullReferenceException
|
// ReSharper disable once PossibleNullReferenceException
|
||||||
select methodWithoutToken.DeclaringType.Name + "." + methodWithoutToken.Name)
|
select methodWithoutToken.DeclaringType.Name + "." + methodWithoutToken.Name)
|
||||||
.Except(GetCancellationTokenExceptions())
|
.Except(GetCancellationTokenExceptions())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"EntityFramework.InMemory": "7.0.0-*",
|
"EntityFramework.InMemory": "7.0.0-*",
|
||||||
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
|
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
|
||||||
|
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||||
},
|
},
|
||||||
"compile": [ "../Shared/ApiConsistencyTestBase.cs", "../Shared/TestHelpers.cs" ],
|
"compile": [ "../Shared/ApiConsistencyTestBase.cs", "../Shared/TestHelpers.cs" ],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue