Skip to content

Commit 06380ee

Browse files
authored
Merge pull request #339 - IDistributedCache feature
IDistributedCache feature
2 parents 58f519a + 36fc018 commit 06380ee

File tree

56 files changed

+2665
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2665
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ This package will include all available assertion methods in your test project,
207207
- `MyTested.AspNetCore.Mvc.DataAnnotations` - Contains setup and assertion methods for data annotation validations
208208
- `MyTested.AspNetCore.Mvc.EntityFrameworkCore` - Contains setup and assertion methods for `DbContext`
209209
- `MyTested.AspNetCore.Mvc.DependencyInjection` - Contains setup methods for dependency injection services
210-
- `MyTested.AspNetCore.Mvc.Caching` - Contains setup and assertion methods for `IMemoryCache`
210+
- `MyTested.AspNetCore.Mvc.Caching` - Contains setup and assertion methods for `IMemoryCache` and `IDistributedCache`
211211
- `MyTested.AspNetCore.Mvc.Session` - Contains setup and assertion methods for `ISession`
212212
- `MyTested.AspNetCore.Mvc.Options` - Contains setup and assertion methods for `IOptions`
213213
- `MyTested.AspNetCore.Mvc.Helpers` - Contains additional helper methods for easier assertions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
/// <summary>
4+
/// Used for adding AndAlso() method to the <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> builder.
5+
/// </summary>
6+
public interface IAndDistributedCacheBuilder : IDistributedCacheBuilder
7+
{
8+
/// <summary>
9+
/// AndAlso method for better readability when building <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/>.
10+
/// </summary>
11+
/// <returns></returns>
12+
IDistributedCacheBuilder AndAlso();
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
using MemoryCache;
4+
5+
/// <summary>
6+
/// Used for adding AndAlso() method to the <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entry builder.
7+
/// </summary>
8+
public interface IAndDistributedCacheEntryBuilder : IDistributedCacheEntryBuilder
9+
{
10+
/// <summary>
11+
/// AndAlso method for better readability when building <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entries.
12+
/// </summary>
13+
/// <returns>The same <see cref="IMemoryCacheEntryBuilder"/>.</returns>
14+
IDistributedCacheEntryBuilder AndAlso();
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
/// <summary>
4+
/// Used for adding AndAlso() method to the <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entry tests.
5+
/// </summary>
6+
public interface IAndDistributedCacheEntryTestBuilder : IDistributedCacheEntryTestBuilder
7+
{
8+
/// <summary>
9+
/// AndAlso method for better readability when testing <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entries.
10+
/// </summary>
11+
/// <returns>The same <see cref="IDistributedCacheEntryTestBuilder"/>.</returns>
12+
IDistributedCacheEntryTestBuilder AndAlso();
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
/// <summary>
4+
/// Used for adding AndAlso() method to the <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> tests.
5+
/// </summary>
6+
public interface IAndDistributedCacheTestBuilder : IDistributedCacheTestBuilder
7+
{
8+
/// <summary>
9+
/// AndAlso method for better readability when testing <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/>
10+
/// </summary>
11+
/// <returns></returns>
12+
IDistributedCacheTestBuilder AndAlso();
13+
}
14+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Microsoft.Extensions.Caching.Distributed;
6+
7+
/// <summary>
8+
/// Used for building mocked <see cref="IDistributedCache"/>.
9+
/// </summary>
10+
public interface IDistributedCacheBuilder
11+
{
12+
/// <summary>
13+
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
14+
/// </summary>
15+
/// <param name="key">Key of the cache entry.</param>
16+
/// <param name="value">Value of the cache entry.</param>
17+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
18+
IAndDistributedCacheBuilder WithEntry(string key, byte[] value);
19+
20+
/// <summary>
21+
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
22+
/// </summary>
23+
/// <param name="key">Key of the cache entry.</param>
24+
/// <param name="value">String value of the cache entry.</param>
25+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
26+
IAndDistributedCacheBuilder WithEntry(string key, string value);
27+
28+
/// <summary>
29+
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
30+
/// </summary>
31+
/// <param name="key">Key of the cache entry.</param>
32+
/// <param name="value">Value of the cache entry.</param>
33+
/// <param name="options"><see cref="DistributedCacheEntryOptions"/> of the cache entry.</param>
34+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
35+
IAndDistributedCacheBuilder WithEntry(string key, byte[] value, DistributedCacheEntryOptions options);
36+
37+
/// <summary>
38+
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
39+
/// </summary>
40+
/// <param name="key">Key of the cache entry.</param>
41+
/// <param name="value">String value of the cache entry.</param>
42+
/// <param name="options"><see cref="DistributedCacheEntryOptions"/> of the cache entry.</param>
43+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
44+
IAndDistributedCacheBuilder WithEntry(string key, string value, DistributedCacheEntryOptions options);
45+
46+
/// <summary>
47+
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
48+
/// </summary>
49+
/// <param name="distributedCacheEntryBuilder">Builder for creating cache entry.</param>
50+
/// <returns>The same <see cref="IDistributedCacheEntryKeyBuilder"/>.</returns>
51+
IAndDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBuilder> distributedCacheEntryBuilder);
52+
53+
/// <summary>
54+
/// Adds cache entries to the mocked <see cref="IDistributedCache"/>.
55+
/// </summary>
56+
/// <param name="entries">Dictionary of cache entries.</param>
57+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
58+
IAndDistributedCacheBuilder WithEntries(IDictionary<string, byte[]> entries);
59+
60+
/// <summary>
61+
/// Adds cache entries to the mocked <see cref="IDistributedCache"/>.
62+
/// </summary>
63+
/// <param name="entries">Dictionary of cache entries.</param>
64+
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
65+
IAndDistributedCacheBuilder WithEntries(IDictionary<string, string> entries);
66+
}
67+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
using System;
4+
using Microsoft.Extensions.Caching.Distributed;
5+
6+
/// <summary>
7+
/// Used for building <see cref="IDistributedCache"/> entry.
8+
/// </summary>
9+
public interface IDistributedCacheEntryBuilder
10+
{
11+
/// <summary>
12+
/// Sets the value of the built <see cref="IDistributedCache"/> entry.
13+
/// </summary>
14+
/// <param name="value">Cache entry value to set.</param>
15+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
16+
IAndDistributedCacheEntryBuilder WithValue(byte[] value);
17+
18+
/// <summary>
19+
/// Sets the value of the built <see cref="IDistributedCache"/> entry.
20+
/// </summary>
21+
/// <param name="value">Cache entry string value to set.</param>
22+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
23+
IAndDistributedCacheEntryBuilder WithValue(string value);
24+
25+
/// <summary>
26+
/// Sets the <see cref="DistributedCacheEntryOptions.AbsoluteExpiration"/> value to the built <see cref="IDistributedCache"/> entry.
27+
/// </summary>
28+
/// <param name="absoluteExpiration">Absolute expiration value to set.</param>
29+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
30+
IAndDistributedCacheEntryBuilder WithAbsoluteExpiration(DateTimeOffset? absoluteExpiration);
31+
32+
/// <summary>
33+
/// Sets the <see cref="DistributedCacheEntryOptions.AbsoluteExpirationRelativeToNow"/> value to the built <see cref="IDistributedCache"/> entry.
34+
/// </summary>
35+
/// <param name="absoluteExpirationRelativeToNow">Absolute expiration relative to now value to set.</param>
36+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
37+
IAndDistributedCacheEntryBuilder WithAbsoluteExpirationRelativeToNow(TimeSpan? absoluteExpirationRelativeToNow);
38+
39+
/// <summary>
40+
/// Sets the <see cref="DistributedCacheEntryOptions.SlidingExpiration"/> value to the built <see cref="IDistributedCache"/> entry.
41+
/// </summary>
42+
/// <param name="slidingExpiration">Sliding expiration value to set.</param>
43+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
44+
IAndDistributedCacheEntryBuilder WithSlidingExpiration(TimeSpan? slidingExpiration);
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
/// <summary>
4+
/// Used for setting <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> key.
5+
/// </summary>
6+
public interface IDistributedCacheEntryKeyBuilder
7+
{
8+
/// <summary>
9+
/// Sets the key of the built <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entry.
10+
/// </summary>
11+
/// <param name="key">Cache entry key to set.</param>
12+
/// <returns>The same <see cref="IAndDistributedCacheEntryBuilder"/>.</returns>
13+
IAndDistributedCacheEntryBuilder WithKey(string key);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
/// <summary>
4+
/// Used for setting <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> key.
5+
/// </summary>
6+
public interface IDistributedCacheEntryKeyTestBuilder
7+
{
8+
/// <summary>
9+
/// Sets the key of the built <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entry.
10+
/// </summary>
11+
/// <param name="key">Cache entry key to set.</param>
12+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
13+
IAndDistributedCacheEntryTestBuilder WithKey(string key);
14+
}
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
2+
{
3+
using System;
4+
using Microsoft.Extensions.Caching.Distributed;
5+
6+
/// <summary>
7+
/// Used for testing <see cref="IDistributedCache"/> entry.
8+
/// </summary>
9+
public interface IDistributedCacheEntryTestBuilder
10+
{
11+
/// <summary>
12+
/// Sets the value of the built <see cref="IDistributedCache"/> entry.
13+
/// </summary>
14+
/// <param name="value">Cache entry value to set.</param>
15+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
16+
IAndDistributedCacheEntryTestBuilder WithValue(byte[] value);
17+
18+
/// <summary>
19+
/// Sets the value of the built <see cref="IDistributedCache"/> entry.
20+
/// </summary>
21+
/// <param name="value">Cache entry string value to set.</param>
22+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
23+
IAndDistributedCacheEntryTestBuilder WithValue(string value);
24+
25+
/// <summary>
26+
/// Sets the <see cref="DistributedCacheEntryOptions.AbsoluteExpiration"/> value to the built <see cref="IDistributedCache"/> entry.
27+
/// </summary>
28+
/// <param name="absoluteExpiration">Absolute expiration value to set.</param>
29+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
30+
IAndDistributedCacheEntryTestBuilder WithAbsoluteExpiration(DateTimeOffset? absoluteExpiration);
31+
32+
/// <summary>
33+
/// Sets the <see cref="DistributedCacheEntryOptions.AbsoluteExpirationRelativeToNow"/> value to the built <see cref="IDistributedCache"/> entry.
34+
/// </summary>
35+
/// <param name="absoluteExpirationRelativeToNow">Absolute expiration relative to now value to set.</param>
36+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
37+
IAndDistributedCacheEntryTestBuilder WithAbsoluteExpirationRelativeToNow(TimeSpan? absoluteExpirationRelativeToNow);
38+
39+
/// <summary>
40+
/// Sets the <see cref="DistributedCacheEntryOptions.SlidingExpiration"/> value to the built <see cref="IDistributedCache"/> entry.
41+
/// </summary>
42+
/// <param name="slidingExpiration">Sliding expiration value to set.</param>
43+
/// <returns>The same <see cref="IAndDistributedCacheEntryTestBuilder"/>.</returns>
44+
IAndDistributedCacheEntryTestBuilder WithSlidingExpiration(TimeSpan? slidingExpiration);
45+
}
46+
}

0 commit comments

Comments
 (0)