Updating tests to run on dnxcore50

This commit is contained in:
Pranav K 2015-11-12 15:01:56 -08:00
parent c8990bcc29
commit f0c2d7ed25
7 changed files with 94 additions and 90 deletions

View File

@ -1,16 +1,20 @@
{
"dependencies": {
"EntityFramework.MicrosoftSqlServer": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity.Tests": "1.0.0",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": { }
}
"dependencies": {
"EntityFramework.MicrosoftSqlServer": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity.Tests": "1.0.0",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"compilationOptions": {
"warningsAsErrors": true
}
}

View File

@ -10,10 +10,7 @@ namespace Microsoft.AspNet.Diagnostics.EntityTests
{
public class ApiConsistencyTest : ApiConsistencyTestBase
{
protected override Assembly TargetAssembly
{
get { return typeof(DatabaseErrorPageMiddleware).Assembly; }
}
protected override Assembly TargetAssembly => typeof(DatabaseErrorPageMiddleware).GetTypeInfo().Assembly;
protected override IEnumerable<string> GetCancellationTokenExceptions()
{

View File

@ -14,9 +14,9 @@ namespace Microsoft.Data.Entity
{
public abstract class ApiConsistencyTestBase
{
private static readonly HashSet<Type> _typesToSkip = new HashSet<Type>
private static readonly HashSet<TypeInfo> _typesToSkip = new HashSet<TypeInfo>
{
typeof(DatabaseErrorPage)
typeof(DatabaseErrorPage).GetTypeInfo()
};
protected const BindingFlags PublicInstance
@ -29,15 +29,15 @@ namespace Microsoft.Data.Entity
public void Public_inheritable_apis_should_be_virtual()
{
var nonVirtualMethods
= (from type in GetAllTypes(TargetAssembly.GetTypes())
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible
&& !type.IsSealed
&& type.GetConstructors(AnyInstance).Any(c => c.IsPublic || c.IsFamily || c.IsFamilyOrAssembly)
&& type.DeclaredConstructors.Any(c => c.IsPublic || c.IsFamily || c.IsFamilyOrAssembly)
&& type.Namespace != null
&& !type.Namespace.EndsWith(".Compiled")
&& !_typesToSkip.Contains(type)
from method in type.GetMethods(PublicInstance)
where method.DeclaringType == type
from method in type.DeclaredMethods.Where(m => m.IsPublic && !m.IsStatic)
where method.DeclaringType.GetTypeInfo() == type
&& !(method.IsVirtual && !method.IsFinal)
select type.FullName + "." + method.Name)
.ToList();
@ -51,17 +51,17 @@ namespace Microsoft.Data.Entity
public void Public_api_arguments_should_have_not_null_annotation()
{
var parametersMissingAttribute
= (from type in GetAllTypes(TargetAssembly.GetTypes())
where type.IsVisible && !typeof(Delegate).IsAssignableFrom(type) && !_typesToSkip.Contains(type)
let interfaceMappings = type.GetInterfaces().Select(type.GetInterfaceMap)
let events = type.GetEvents()
from method in type.GetMethods(PublicInstance | BindingFlags.Static)
.Concat<MethodBase>(type.GetConstructors())
where method.DeclaringType == type
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(type) && !_typesToSkip.Contains(type)
let interfaceMappings = type.ImplementedInterfaces.Select(type.GetRuntimeInterfaceMap)
let events = type.DeclaredEvents
from method in type.DeclaredMethods.Where(m => m.IsPublic)
.Concat<MethodBase>(type.DeclaredConstructors)
where method.DeclaringType.GetTypeInfo() == type
where type.IsInterface || !interfaceMappings.Any(im => im.TargetMethods.Contains(method))
where !events.Any(e => e.AddMethod == method || e.RemoveMethod == method)
from parameter in method.GetParameters()
where !parameter.ParameterType.IsValueType
where !parameter.ParameterType.GetTypeInfo().IsValueType
&& !parameter.GetCustomAttributes()
.Any(
a => a.GetType().Name == "NotNullAttribute"
@ -78,10 +78,10 @@ namespace Microsoft.Data.Entity
public void Async_methods_should_have_overload_with_cancellation_token_and_end_with_async_suffix()
{
var asyncMethods
= (from type in GetAllTypes(TargetAssembly.GetTypes())
= (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible
from method in type.GetMethods(PublicInstance | BindingFlags.Static)
where method.DeclaringType == type
from method in type.DeclaredMethods.Where(m => m.IsPublic)
where method.DeclaringType.GetTypeInfo() == type
where typeof(Task).IsAssignableFrom(method.ReturnType)
select method).ToList();
@ -99,7 +99,7 @@ namespace Microsoft.Data.Entity
= (from methodWithoutToken in asyncMethodsWithoutToken
where !asyncMethodsWithToken
.Any(methodWithToken => methodWithoutToken.Name == methodWithToken.Name
&& methodWithoutToken.ReflectedType == methodWithToken.ReflectedType)
&& methodWithoutToken.DeclaringType == methodWithToken.DeclaringType)
// ReSharper disable once PossibleNullReferenceException
select methodWithoutToken.DeclaringType.Name + "." + methodWithoutToken.Name)
.Except(GetCancellationTokenExceptions())
@ -133,13 +133,13 @@ namespace Microsoft.Data.Entity
protected abstract Assembly TargetAssembly { get; }
protected virtual IEnumerable<Type> GetAllTypes(IEnumerable<Type> types)
protected virtual IEnumerable<TypeInfo> GetAllTypes(IEnumerable<TypeInfo> typeInfos)
{
foreach (var type in types)
foreach (var typeInfo in typeInfos)
{
yield return type;
yield return typeInfo;
foreach (var nestedType in GetAllTypes(type.GetNestedTypes()))
foreach (var nestedType in GetAllTypes(typeInfo.DeclaredNestedTypes))
{
yield return nestedType;
}

View File

@ -1,15 +1,26 @@
{
"dependencies": {
"EntityFramework.InMemory": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"EntityFramework.InMemory": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"compile": [ "../Shared/ApiConsistencyTestBase.cs", "../Shared/TestHelpers.cs" ],
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
},
"compile": [ "..\\Shared\\ApiConsistencyTestBase.cs", "..\\Shared\\TestHelpers.cs" ],
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": { }
"dnxcore50": {
"dependencies": {
"moq.netcore": "4.4.0-beta8"
}
}
}
}

View File

@ -14,9 +14,7 @@ using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
#if DNX451
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Diagnostics.Tests
@ -35,7 +33,6 @@ namespace Microsoft.AspNet.Diagnostics.Tests
Assert.Equal(DefaultPath, options.Path.Value);
}
#if DNX451
[Fact]
public async void Invoke_WithNonMatchingPath_IgnoresRequest()
{
@ -226,7 +223,6 @@ namespace Microsoft.AspNet.Diagnostics.Tests
.Returns(featureCollection);
return contextMock;
}
#endif
[Fact]
public async Task SetsNewIdentifierFeature_IfNotPresentOnContext()

View File

@ -1,22 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.WebEncoders.Testing;
#if DNX451
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Diagnostics.Tests
@ -35,12 +30,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests
Assert.Equal(DefaultPath, options.Path.Value);
}
#if DNX451
[Fact]
public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
{
// Arrage
var libraries = new [] {
var libraries = new[] {
new Library("LibInfo1", string.Empty, "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()),
new Library("LibInfo2", string.Empty, "Path2", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>())
};
@ -111,7 +105,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
{
// Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new [] {
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new[] {
new Library("LibInfo1", "1.0.0-beta1", "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()),
new Library("LibInfo2", "1.0.0-beta2", "Path2", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>())
});
@ -171,7 +165,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
{
// Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new [] {
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new[] {
new Library("LibInfo1", "1.0.0-beta1", "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()),
});
@ -219,6 +213,5 @@ namespace Microsoft.AspNet.Diagnostics.Tests
Assert.True(response.Contains("<td>HtmlEncode[[Path1]]</td>"));
}
}
#endif
}
}

View File

@ -1,31 +1,34 @@
{
"compilationOptions": {
"warningsAsErrors": false,
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*",
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*",
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
},
"dnxcore50": {
}
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
},
"dnxcore50": {
"dependencies": {
"moq.netcore": "4.4.0-beta8"
}
}
},
"commands": {
"test": "xunit.runner.aspnet"
},
"commands": {
"test": "xunit.runner.aspnet"
},
"resource": [ "Resources/**" ]
"resource": [ "Resources/**" ]
}