This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #4914 patternize filter overrides
Adding some convenience methods to the context class and updating our code to use them.
- Loading branch information
Showing
11 changed files
with
205 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
test/Microsoft.AspNetCore.Mvc.Abstractions.Test/Filters/FilterContextTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc.Abstractions; | ||
using Microsoft.AspNetCore.Routing; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Filters | ||
{ | ||
public class FilterContextTest | ||
{ | ||
[Fact] | ||
public void IsEffectivePolicy_FindsAnotherFilter_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var filters = new IFilterMetadata[] | ||
{ | ||
Mock.Of<ITestFilterPolicy>(), | ||
Mock.Of<IAnotherTestFilterPolicy>(), | ||
Mock.Of<ITestFilterPolicy>(), | ||
}; | ||
|
||
var context = new TestFilterContext(filters); | ||
|
||
// Act | ||
var result = context.IsEffectivePolicy((ITestFilterPolicy)filters.First()); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEffectivePolicy_FindsFilterOfInterest_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var filters = new IFilterMetadata[] | ||
{ | ||
Mock.Of<ITestFilterPolicy>(), | ||
Mock.Of<IAnotherTestFilterPolicy>(), | ||
Mock.Of<ITestFilterPolicy>(), | ||
}; | ||
|
||
var context = new TestFilterContext(filters); | ||
|
||
// Act | ||
var result = context.IsEffectivePolicy((ITestFilterPolicy)filters.Last()); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEffectivePolicy_NoMatch_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var filters = new IFilterMetadata[] | ||
{ | ||
Mock.Of<ITestFilterPolicy>(), | ||
Mock.Of<ITestFilterPolicy>(), | ||
}; | ||
|
||
var context = new TestFilterContext(filters); | ||
|
||
// Act | ||
var result = context.IsEffectivePolicy(Mock.Of<IAnotherTestFilterPolicy>()); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
|
||
[Fact] | ||
public void FindEffectivePolicy_FindsLastFilter_ReturnsIt() | ||
{ | ||
// Arrange | ||
var filters = new IFilterMetadata[] | ||
{ | ||
Mock.Of<ITestFilterPolicy>(), | ||
Mock.Of<IAnotherTestFilterPolicy>(), | ||
Mock.Of<ITestFilterPolicy>(), | ||
}; | ||
|
||
var context = new TestFilterContext(filters); | ||
|
||
// Act | ||
var result = context.FindEffectivePolicy<ITestFilterPolicy>(); | ||
|
||
// Assert | ||
Assert.Same(filters.Last(), result); | ||
} | ||
|
||
[Fact] | ||
public void FindEffectivePolicy_NoMatch_ReturnsNull() | ||
{ | ||
// Arrange | ||
var filters = new IFilterMetadata[] | ||
{ | ||
Mock.Of<ITestFilterPolicy>(), | ||
Mock.Of<ITestFilterPolicy>(), | ||
}; | ||
|
||
var context = new TestFilterContext(filters); | ||
|
||
// Act | ||
var result = context.FindEffectivePolicy<IAnotherTestFilterPolicy>(); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
|
||
internal class ITestFilterPolicy : IFilterMetadata | ||
{ | ||
} | ||
|
||
internal class IAnotherTestFilterPolicy : IFilterMetadata | ||
{ | ||
} | ||
|
||
private class TestFilterContext : FilterContext | ||
{ | ||
public TestFilterContext(IList<IFilterMetadata> filters) | ||
: base(new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()), filters) | ||
{ | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
test/Microsoft.AspNetCore.Mvc.Abstractions.Test/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// 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.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] |
Oops, something went wrong.