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": { "dependencies": {
"EntityFramework.MicrosoftSqlServer": "7.0.0-*", "EntityFramework.MicrosoftSqlServer": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity.Tests": "1.0.0", "Microsoft.AspNet.Diagnostics.Entity.Tests": "1.0.0",
"Microsoft.AspNet.TestHost": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"commands": { "commands": {
"test": "xunit.runner.aspnet" "test": "xunit.runner.aspnet"
}, },
"frameworks": { "frameworks": {
"dnx451": { } "dnx451": { },
} "dnxcore50": { }
},
"compilationOptions": {
"warningsAsErrors": true
}
} }

View File

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

View File

@ -14,9 +14,9 @@ namespace Microsoft.Data.Entity
{ {
public abstract class ApiConsistencyTestBase 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 protected const BindingFlags PublicInstance
@ -29,15 +29,15 @@ namespace Microsoft.Data.Entity
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.GetTypes()) = (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible where type.IsVisible
&& !type.IsSealed && !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 != null
&& !type.Namespace.EndsWith(".Compiled") && !type.Namespace.EndsWith(".Compiled")
&& !_typesToSkip.Contains(type) && !_typesToSkip.Contains(type)
from method in type.GetMethods(PublicInstance) from method in type.DeclaredMethods.Where(m => m.IsPublic && !m.IsStatic)
where method.DeclaringType == 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();
@ -51,17 +51,17 @@ namespace Microsoft.Data.Entity
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.GetTypes()) = (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible && !typeof(Delegate).IsAssignableFrom(type) && !_typesToSkip.Contains(type) where type.IsVisible && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(type) && !_typesToSkip.Contains(type)
let interfaceMappings = type.GetInterfaces().Select(type.GetInterfaceMap) let interfaceMappings = type.ImplementedInterfaces.Select(type.GetRuntimeInterfaceMap)
let events = type.GetEvents() let events = type.DeclaredEvents
from method in type.GetMethods(PublicInstance | BindingFlags.Static) from method in type.DeclaredMethods.Where(m => m.IsPublic)
.Concat<MethodBase>(type.GetConstructors()) .Concat<MethodBase>(type.DeclaredConstructors)
where method.DeclaringType == 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.IsValueType where !parameter.ParameterType.GetTypeInfo().IsValueType
&& !parameter.GetCustomAttributes() && !parameter.GetCustomAttributes()
.Any( .Any(
a => a.GetType().Name == "NotNullAttribute" 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() public void Async_methods_should_have_overload_with_cancellation_token_and_end_with_async_suffix()
{ {
var asyncMethods var asyncMethods
= (from type in GetAllTypes(TargetAssembly.GetTypes()) = (from type in GetAllTypes(TargetAssembly.DefinedTypes)
where type.IsVisible where type.IsVisible
from method in type.GetMethods(PublicInstance | BindingFlags.Static) from method in type.DeclaredMethods.Where(m => m.IsPublic)
where method.DeclaringType == type where method.DeclaringType.GetTypeInfo() == type
where typeof(Task).IsAssignableFrom(method.ReturnType) where typeof(Task).IsAssignableFrom(method.ReturnType)
select method).ToList(); select method).ToList();
@ -99,7 +99,7 @@ namespace Microsoft.Data.Entity
= (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.ReflectedType == methodWithToken.ReflectedType) && 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())
@ -133,13 +133,13 @@ namespace Microsoft.Data.Entity
protected abstract Assembly TargetAssembly { get; } 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; yield return nestedType;
} }

View File

@ -1,15 +1,26 @@
{ {
"dependencies": { "compilationOptions": {
"EntityFramework.InMemory": "7.0.0-*", "warningsAsErrors": true
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*", },
"Moq": "4.2.1312.1622", "dependencies": {
"xunit.runner.aspnet": "2.0.0-aspnet-*" "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" ], "dnxcore50": {
"commands": { "dependencies": {
"test": "xunit.runner.aspnet" "moq.netcore": "4.4.0-beta8"
}, }
"frameworks": {
"dnx451": { }
} }
}
} }

View File

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

View File

@ -1,22 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.WebEncoders.Testing; using Microsoft.Extensions.WebEncoders.Testing;
#if DNX451
using Moq; using Moq;
#endif
using Xunit; using Xunit;
namespace Microsoft.AspNet.Diagnostics.Tests namespace Microsoft.AspNet.Diagnostics.Tests
@ -35,12 +30,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests
Assert.Equal(DefaultPath, options.Path.Value); Assert.Equal(DefaultPath, options.Path.Value);
} }
#if DNX451
[Fact] [Fact]
public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages() public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
{ {
// Arrage // Arrage
var libraries = new [] { var libraries = new[] {
new Library("LibInfo1", string.Empty, "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()), 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>()) new Library("LibInfo2", string.Empty, "Path2", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>())
}; };
@ -111,7 +105,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
{ {
// Arrange // Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict); 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("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>()) 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 // Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict); 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("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>")); Assert.True(response.Contains("<td>HtmlEncode[[Path1]]</td>"));
} }
} }
#endif
} }
} }

View File

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