forked from VahidN/EFCoreSecondLevelCacheInterceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEFCachePolicyParserTests.cs
More file actions
48 lines (41 loc) · 2.18 KB
/
EFCachePolicyParserTests.cs
File metadata and controls
48 lines (41 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EFCoreSecondLevelCacheInterceptor.Tests
{
[TestClass]
public class EFCachePolicyParserTests
{
[TestMethod]
public void TestGetEFCachePolicyWith2Parts()
{
const string commandText = @"-- EFCachePolicy[Index(27)] --> Absolute|00:45:00
SELECT TOP(1) [p].[Id], [p].[Title], [p].[UserId], [p].[post_type], [u].[Id], [u].[Name], [u].[UserStatus]
FROM [Posts] AS [p]
INNER JOIN [Users] AS [u] ON [p].[UserId] = [u].[Id]
WHERE [p].[post_type] IN (N'post_base', N'post_page') AND ([p].[Id] > @__param1_0)
ORDER BY [p].[Id]";
var cachePolicyParser = EFServiceProvider.GetRequiredService<IEFCachePolicyParser>();
var cachePolicy = cachePolicyParser.GetEFCachePolicy(commandText);
Assert.AreEqual(expected: CacheExpirationMode.Absolute, actual: cachePolicy.CacheExpirationMode);
Assert.AreEqual(expected: TimeSpan.FromMinutes(45), actual: cachePolicy.CacheTimeout);
}
[TestMethod]
public void TestGetEFCachePolicyWithAllParts()
{
string commandText = EFCachePolicy.Configure(options =>
options.ExpirationMode(CacheExpirationMode.Absolute)
.Timeout(TimeSpan.FromMinutes(45))
.SaltKey("saltKey")
.CallerMemberName("methodName")
.CallerLineNumber(10)
.CacheDependencies("item 1", "item 2"));
var cachePolicyParser = EFServiceProvider.GetRequiredService<IEFCachePolicyParser>();
var cachePolicy = cachePolicyParser.GetEFCachePolicy(commandText);
Assert.AreEqual(expected: CacheExpirationMode.Absolute, actual: cachePolicy.CacheExpirationMode);
Assert.AreEqual(expected: TimeSpan.FromMinutes(45), actual: cachePolicy.CacheTimeout);
Assert.AreEqual(expected: "saltKey", actual: cachePolicy.CacheSaltKey);
CollectionAssert.AreEqual(expected: new SortedSet<string> { "item 1", "item 2" }, actual: cachePolicy.CacheItemsDependencies as SortedSet<string>);
}
}
}