-
-
Notifications
You must be signed in to change notification settings - Fork 41
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 #3392 from 2sic/develop
Release 17.09
- Loading branch information
Showing
38 changed files
with
1,003 additions
and
108 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
73 changes: 73 additions & 0 deletions
73
Src/Sxc.Tests/ToSic.Sxc.Tests/ServicesTests/CacheTests/CacheKeyTests.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,73 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using ToSic.Sxc.Services.Cache; | ||
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert; | ||
using static ToSic.Sxc.Services.Cache.CacheServiceConstants; | ||
|
||
namespace ToSic.Sxc.Tests.ServicesTests.CacheTests; | ||
|
||
[TestClass] | ||
public class CacheKeyTests | ||
{ | ||
internal const string FullDefaultPrefix = $"{DefaultPrefix}{Sep}App:0{Sep}{SegmentPrefix}{DefaultSegment}{Sep}"; | ||
|
||
[DataRow(null)] | ||
[DataRow("")] | ||
[TestMethod] | ||
[ExpectedException(typeof(ArgumentException))] | ||
public void MainKeyBad(string main) | ||
=> AreEqual(FullDefaultPrefix + main, new CacheKeySpecs(0, main).Key); | ||
|
||
[DataRow(Sep + "App:0", 0, "zero")] | ||
[DataRow(Sep + "App:27", 27, "27")] | ||
[DataRow(Sep + "App:42", 42, "42")] | ||
[DataRow("", CacheKeySpecs.NoApp, "no app")] | ||
[TestMethod] | ||
public void MainKeyAppIds(string expectedReplace, int appId, string message) | ||
=> AreEqual(FullDefaultPrefix.Replace(Sep + "App:0", expectedReplace) + "Test", new CacheKeySpecs(appId, "Test").Key, message); | ||
|
||
|
||
|
||
[DataRow("TestKey")] | ||
[DataRow("A")] | ||
[DataRow("A\nB")] | ||
[TestMethod] | ||
public void MainKeyOnly(string main) | ||
=> AreEqual( FullDefaultPrefix + main, new CacheKeySpecs(0, main).Key); | ||
|
||
private const string FullSegmentPrefix = $"{DefaultPrefix}{Sep}App:0{Sep}{SegmentPrefix}"; | ||
|
||
[DataRow($"{DefaultSegment}{Sep}Main", "Main", null)] | ||
[DataRow($"{DefaultSegment}{Sep}Main", "Main", "")] | ||
[DataRow($"MySegment{Sep}Main", "Main", "MySegment")] | ||
[TestMethod] | ||
public void MainAndSegment(string expected, string main, string segment) | ||
=> AreEqual( FullSegmentPrefix + expected, new CacheKeySpecs(0, main, segment).Key); | ||
|
||
|
||
[TestMethod] | ||
public void EnsureDicIsSorted() | ||
{ | ||
var expected = $"{Sep}A=AVal{Sep}B=BVal{Sep}C=CVal"; | ||
var dic = new Dictionary<string, string> | ||
{ | ||
{ "B", "BVal" }, | ||
{ "A", "AVal" }, | ||
{ "C", "CVal" } | ||
}; | ||
var resultDic1 = CacheKeySpecs.GetVaryByOfDic(dic); | ||
AreEqual(expected, resultDic1); | ||
|
||
var dic2 = new Dictionary<string, string> | ||
{ | ||
{ "C", "CVal" }, | ||
{ "A", "AVal" }, | ||
{ "B", "BVal" } | ||
}; | ||
var resultDic2 = CacheKeySpecs.GetVaryByOfDic(dic2); | ||
AreEqual(expected, resultDic2); | ||
AreEqual(resultDic1, resultDic2); | ||
|
||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
Src/Sxc.Tests/ToSic.Sxc.Tests/ServicesTests/CacheTests/CacheSpecsTests.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,146 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using ToSic.Sxc.Context.Internal; | ||
using ToSic.Sxc.Services; | ||
using ToSic.Sxc.Services.Cache; | ||
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert; | ||
using static ToSic.Sxc.Services.Cache.CacheServiceConstants; | ||
|
||
namespace ToSic.Sxc.Tests.ServicesTests.CacheTests; | ||
|
||
[TestClass] | ||
public class CacheSpecsTests: TestBaseSxcDb | ||
{ | ||
private static readonly string MainPrefix = $"{CacheKeyTests.FullDefaultPrefix.Replace("App:0", "App:-1")}Main{Sep}"; | ||
|
||
private ICacheSpecs GetForMain(string name = "Main") => GetService<ICacheService>().CreateSpecs(name); | ||
|
||
[TestMethod] | ||
public void ShareKeyAcrossApps() | ||
{ | ||
var expected = $"{CacheKeyTests.FullDefaultPrefix.Replace(Sep + "App:0", "")}Main"; | ||
var svc = GetService<ICacheService>(); | ||
var specs = svc.CreateSpecs("Main", shared: true); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByCustom1CaseSensitive() | ||
{ | ||
var expected = MainPrefix + "VaryByKey1=Value1"; | ||
var svc = GetService<ICacheService>(); | ||
var specs = svc.CreateSpecs("Main") | ||
.VaryBy("Key1", "Value1", caseSensitive: true); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByCustom1() | ||
{ | ||
var expected = MainPrefix + "VaryByKey1=Value1".ToLowerInvariant(); | ||
var specs = GetForMain() | ||
.VaryBy("Key1", "Value1"); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByCustom2SameKey() | ||
{ | ||
var expected = MainPrefix + "VaryByKey1=Value1".ToLowerInvariant(); | ||
var specs = GetForMain() | ||
.VaryBy("Key1", "valueWhichWillGoAway") | ||
.VaryBy("Key1", "Value1"); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByCustom2DiffKey() | ||
{ | ||
var expected = MainPrefix + $"VaryByKey1=Val1{Sep}VaryByKey2=Value2".ToLowerInvariant(); | ||
var specs = GetForMain() | ||
.VaryBy("Key1", "Val1") | ||
.VaryBy("Key2", "Value2"); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
// Disabled for now, not sure if this single-value case is needed | ||
//[TestMethod] | ||
//public void VaryByCustom1ValueOnly() | ||
//{ | ||
// var expected = MainPrefix + "VaryByThisIsTheValue=".ToLowerInvariant(); | ||
// var specs = GetForMain() | ||
// .VaryBy("ThisIsTheValue"); | ||
// AreEqual(expected, specs.Key); | ||
//} | ||
|
||
[TestMethod] | ||
public void VaryByParameters() | ||
{ | ||
var expected = MainPrefix + "VaryByParameters=".ToLowerInvariant(); | ||
var pars = new Parameters(); | ||
var specs = GetForMain().VaryByParameters(pars); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[DataRow(null, "no names specified")] | ||
[DataRow("", "empty names specified")] | ||
[DataRow("A,B,C", "too many names")] | ||
[DataRow("A", "names with exact casing")] | ||
[DataRow("a", "names with different casing")] | ||
[TestMethod] | ||
public void VaryByParametersOneNamed(string names, string testName) | ||
{ | ||
var expected = MainPrefix + "VaryByParameters=A=AVal".ToLowerInvariant(); | ||
var pars = new Parameters(new() | ||
{ | ||
{ "A", "AVal" } | ||
}); | ||
var specs = GetForMain().VaryByParameters(pars, names: names); | ||
AreEqual(expected, specs.Key, testName); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void VaryByParametersWithNamesAll() | ||
{ | ||
var expected = MainPrefix + "VaryByParameters=A=AVal&B=BVal&C=CVal".ToLowerInvariant(); | ||
var pars = new Parameters(new() | ||
{ | ||
{ "A", "AVal" }, | ||
{ "B", "BVal" }, | ||
{ "C", "CVal" } | ||
}); | ||
var specs = GetForMain().VaryByParameters(pars, names: "A,B,c"); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByParametersWithNamesSome() | ||
{ | ||
var expected = MainPrefix + "VaryByParameters=A=AVal&C=CVal".ToLowerInvariant(); | ||
var pars = new Parameters(new() | ||
{ | ||
{ "A", "AVal" }, | ||
{ "B", "BVal" }, | ||
{ "C", "CVal" } | ||
}); | ||
var specs = GetForMain().VaryByParameters(pars, names: "A,c"); | ||
AreEqual(expected, specs.Key); | ||
} | ||
|
||
[TestMethod] | ||
public void VaryByParametersBlankSameAsNone() | ||
{ | ||
var expected = MainPrefix + "VaryByParameters=A=AVal&C=CVal".ToLowerInvariant(); | ||
var pars = new Parameters(new() | ||
{ | ||
{ "A", "AVal" }, | ||
{ "B", "" }, | ||
{ "C", "CVal" } | ||
}); | ||
var specsFiltered = GetForMain().VaryByParameters(pars, names: "A,c"); | ||
var specsAll = GetForMain().VaryByParameters(pars); | ||
AreEqual(expected, specsFiltered.Key); | ||
AreEqual(specsFiltered.Key, specsAll.Key); | ||
} | ||
|
||
} |
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
Oops, something went wrong.