Пример #1
0
        public void TestRemoveEFCachePolicyTagWithAdditionalTagComments()
        {
            const string commandText =
                @"-- CustomTagAbove

-- EFCachePolicy[Index(27)] --> Absolute|00:45:00

-- CustomTagBelow

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 commandTextWithCachePolicyTagRemoved = cachePolicyParser.RemoveEFCachePolicyTag(commandText);

            var expectedResult =
                @"-- CustomTagAbove

-- CustomTagBelow

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]";

            Assert.AreEqual(expected: expectedResult, actual: commandTextWithCachePolicyTagRemoved);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void TestGetCacheDependenciesWorksForDeletes()
        {
            const string commandText = @"SET NOCOUNT ON;
        DELETE FROM [Products]
        WHERE [ProductId] = @p0;
        SELECT @@ROWCOUNT;";
            var          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                "Products"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }
        public void TestGetCacheDependenciesWorksForUpdates()
        {
            const string commandText = @"SET NOCOUNT ON;
      UPDATE [Users] SET [UserStatus] = @p0
      WHERE [Id] = @p1;
      SELECT @@ROWCOUNT;";
            var          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                CacheKeyPrefix + "Users"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }
Пример #5
0
        public void TestGetCacheDependenciesWorksWithNormalEFQueries()
        {
            const string commandText = @"-- EFCachePolicy[TestCachingByteArrays(line 391)] --> Absolute|00:45:00|||False

      SELECT TOP(1) [u].[Id], [u].[AddDate], [u].[ByteArrayValue], [u].[ByteValue], [u].[CharValue], [u].[DateTimeOffsetValue], [u].[DecimalValue], [u].[DoubleValue], [u].[FloatValue], [u].[GuidValue], [u].[ImageData], [u].[IsActive], [u].[Name], [u].[Points], [u].[ShortValue], [u].[TimeSpanValue], [u].[UintValue], [u].[UlongValue], [u].[UpdateDate], [u].[UserStatus], [u].[UshortValue]
      FROM [Users] AS [u]
      WHERE [u].[Id] = @__user1_Id_0]";
            var          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                "Users"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }
Пример #6
0
        public void TestGetCacheDependenciesWorksForInserts()
        {
            const string commandText = @"SET NOCOUNT ON;
        INSERT INTO [Products] ([IsActive], [Notes], [ProductName], [ProductNumber], [UserId])
        VALUES (@p0, @p1, @p2, @p3, @p4);
        SELECT [ProductId]
        FROM [Products]
        WHERE @@ROWCOUNT = 1 AND [ProductId] = scope_identity();";
            var          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                "Products"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }
Пример #7
0
        public void TestGetEFCachePolicyWithAllParts()
        {
            string commandText = "-- " + EFCachePolicy.Configure(options =>
                                                                 options.ExpirationMode(CacheExpirationMode.Absolute)
                                                                 .Timeout(TimeSpan.FromMinutes(45))
                                                                 .SaltKey("saltKey")
                                                                 .CacheDependencies("item 1", "item 2"));

            var cachePolicyParser = EFServiceProvider.GetRequiredService <IEFCachePolicyParser>();
            var cachePolicy       = cachePolicyParser.GetEFCachePolicy(commandText);

            Assert.IsNotNull(cachePolicy);
            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>);
        }
Пример #8
0
        public void TestGetCacheDependenciesWorksForInsertsWithBacktick()
        {
            const string commandText = @"SET NOCOUNT ON;
        INSERT INTO `Products` (`IsActive`, `Notes`, `ProductName`, `ProductNumber`, `UserId`)
        VALUES (@p0, @p1, @p2, @p3, @p4);
        SELECT `ProductId`
        FROM `Products`
        WHERE @@ROWCOUNT = 1 AND `ProductId` = scope_identity();";
            var          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                "Products"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }
Пример #9
0
        public void TestGetCacheDependenciesWorks()
        {
            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          cacheDependenciesProcessor = EFServiceProvider.GetRequiredService <IEFCacheDependenciesProcessor>();
            var          cacheDependencies          = cacheDependenciesProcessor.GetCacheDependencies(new EFCachePolicy(), new SortedSet <string> {
                "Posts", "Users", "Products"
            }, commandText);

            var inUseTableNames = new SortedSet <string> {
                "Posts", "Users"
            };

            CollectionAssert.AreEqual(expected: inUseTableNames, actual: cacheDependencies);
        }