-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Kentico/MVCHF11-3-initialization-exception
MVCHF11-3 - Fix issue with concurrent GlobalFilters registration
- Loading branch information
Showing
8 changed files
with
95 additions
and
3 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
25 changes: 25 additions & 0 deletions
25
src/Kentico.Content.Web.Mvc/Preview/PreviewGlobalFilters.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,25 @@ | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
|
||
namespace Kentico.Content.Web.Mvc | ||
{ | ||
/// <summary> | ||
/// Class that provides registration of all the required global filters for the page preview feature. | ||
/// </summary> | ||
internal static class PreviewGlobalFilters | ||
{ | ||
/// <summary> | ||
/// Registers global filters for the Preview feature. | ||
/// </summary> | ||
public static void Register() | ||
{ | ||
var globalFilters = GlobalFilters.Filters; | ||
|
||
// Add a filter to disable output cache for preview | ||
if (!globalFilters.Any(f => f.Instance.GetType().Equals(typeof(PreviewOutputCacheFilter)))) | ||
{ | ||
globalFilters.Add(new PreviewOutputCacheFilter()); | ||
} | ||
} | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
test/Kentico.Content.Web.Mvc.Tests/Preview/PreviewGlobalFiltersTests.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,59 @@ | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
|
||
using CMS.Tests; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Kentico.Content.Web.Mvc.Tests | ||
{ | ||
/// <summary> | ||
/// Unit tests for class <see cref="PreviewGlobalFiltersTests"/>. | ||
/// </summary> | ||
public class PreviewGlobalFiltersTests | ||
{ | ||
[TestFixture] | ||
[Category.Unit] | ||
public class RegisterTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
GlobalFilters.Filters.Clear(); | ||
} | ||
|
||
|
||
[OneTimeTearDown] | ||
public void OneTimeTearDown() | ||
{ | ||
GlobalFilters.Filters.Clear(); | ||
} | ||
|
||
|
||
[Test] | ||
public void Register_SingleCall_PreviewFilterRegistered() | ||
{ | ||
PreviewGlobalFilters.Register(); | ||
|
||
CMSAssert.All( | ||
() => Assert.That(GlobalFilters.Filters.Count, Is.EqualTo(1)), | ||
() => Assert.That(GlobalFilters.Filters.First().Instance, Is.TypeOf(typeof(PreviewOutputCacheFilter))) | ||
); | ||
} | ||
|
||
|
||
[Test] | ||
public void Register_TwoCalls_PreviewFilterRegisteredOnlyOnce() | ||
{ | ||
PreviewGlobalFilters.Register(); | ||
PreviewGlobalFilters.Register(); | ||
|
||
CMSAssert.All( | ||
() => Assert.That(GlobalFilters.Filters.Count, Is.EqualTo(1)), | ||
() => Assert.That(GlobalFilters.Filters.First().Instance, Is.TypeOf(typeof(PreviewOutputCacheFilter))) | ||
); | ||
} | ||
|
||
} | ||
} | ||
} |