Skip to content

Commit f84772e

Browse files
committed
#283 Adding initial structure of the with and without distributed cache.
- Tidying up the structure of the memory cache and distributed cache folders in order to be more clear what and from where is used.
1 parent bebb5fb commit f84772e

15 files changed

Lines changed: 100 additions & 45 deletions

File tree

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/DistributedCache/IAndDistributedCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/DistributedCache/WithDistributedCache/IAndWithDistributedCacheBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
22
{
33
/// <summary>
44
/// Used for adding AndAlso() method to the <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> builder.
55
/// </summary>
6-
public interface IAndDistributedCacheBuilder : IDistributedCacheBuilder
6+
public interface IAndWithDistributedCacheBuilder : IWithDistributedCacheBuilder
77
{
88
/// <summary>
99
/// AndAlso method for better readability when building <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/>.
1010
/// </summary>
1111
/// <returns></returns>
12-
IDistributedCacheBuilder AndAlso();
12+
IWithDistributedCacheBuilder AndAlso();
1313
}
1414
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/DistributedCache/IDistributedCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/DistributedCache/WithDistributedCache/IWithDistributedCacheBuilder.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
1-
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data.DistributedCache
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
22
{
33
using System;
44
using System.Collections.Generic;
55
using Microsoft.Extensions.Caching.Distributed;
6+
using Builders.Contracts.Data.DistributedCache;
67

78
/// <summary>
89
/// Used for building mocked <see cref="IDistributedCache"/>.
910
/// </summary>
10-
public interface IDistributedCacheBuilder
11+
public interface IWithDistributedCacheBuilder
1112
{
1213
/// <summary>
1314
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
1415
/// </summary>
1516
/// <param name="key">Key of the cache entry.</param>
1617
/// <param name="value">Value of the cache entry.</param>
17-
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
18-
IAndDistributedCacheBuilder WithEntry(string key, byte[] value);
18+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
19+
IAndWithDistributedCacheBuilder WithEntry(string key, byte[] value);
1920

2021
/// <summary>
2122
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
2223
/// </summary>
2324
/// <param name="key">Key of the cache entry.</param>
2425
/// <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);
26+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
27+
IAndWithDistributedCacheBuilder WithEntry(string key, string value);
2728

2829
/// <summary>
2930
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
3031
/// </summary>
3132
/// <param name="key">Key of the cache entry.</param>
3233
/// <param name="value">Value of the cache entry.</param>
3334
/// <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);
35+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
36+
IAndWithDistributedCacheBuilder WithEntry(string key, byte[] value, DistributedCacheEntryOptions options);
3637

3738
/// <summary>
3839
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
3940
/// </summary>
4041
/// <param name="key">Key of the cache entry.</param>
4142
/// <param name="value">String value of the cache entry.</param>
4243
/// <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);
44+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
45+
IAndWithDistributedCacheBuilder WithEntry(string key, string value, DistributedCacheEntryOptions options);
4546

4647
/// <summary>
4748
/// Adds cache entry to the mocked <see cref="IDistributedCache"/>.
4849
/// </summary>
4950
/// <param name="distributedCacheEntryBuilder">Builder for creating cache entry.</param>
5051
/// <returns>The same <see cref="IDistributedCacheEntryKeyBuilder"/>.</returns>
51-
IAndDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBuilder> distributedCacheEntryBuilder);
52+
IAndWithDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBuilder> distributedCacheEntryBuilder);
5253

5354
/// <summary>
5455
/// Adds cache entries to the mocked <see cref="IDistributedCache"/>.
5556
/// </summary>
5657
/// <param name="entries">Dictionary of cache entries.</param>
57-
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
58-
IAndDistributedCacheBuilder WithEntries(IDictionary<string, byte[]> entries);
58+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
59+
IAndWithDistributedCacheBuilder WithEntries(IDictionary<string, byte[]> entries);
5960

6061
/// <summary>
6162
/// Adds cache entries to the mocked <see cref="IDistributedCache"/>.
6263
/// </summary>
6364
/// <param name="entries">Dictionary of cache entries.</param>
64-
/// <returns>The same <see cref="IAndDistributedCacheBuilder"/>.</returns>
65-
IAndDistributedCacheBuilder WithEntries(IDictionary<string, string> entries);
65+
/// <returns>The same <see cref="IAndWithDistributedCacheBuilder"/>.</returns>
66+
IAndWithDistributedCacheBuilder WithEntries(IDictionary<string, string> entries);
6667
}
6768
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
2+
{
3+
public interface IAndWithoutDistributedCache : IWithoutDistributedCache
4+
{
5+
IWithoutDistributedCache AndAlso();
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
2+
{
3+
using System.Collections.Generic;
4+
5+
public interface IWithoutDistributedCache
6+
{
7+
IAndWithoutDistributedCache WithoutEntry(object key);
8+
9+
IAndWithoutDistributedCache WithoutEntries(IEnumerable<object> keys);
10+
11+
IAndWithoutDistributedCache WithoutEntries(params object[] keys);
12+
13+
IAndWithoutDistributedCache WithoutAllEntries();
14+
}
15+
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IAndWithMemoryCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/MemoryCache/WithMemoryCache/IAndWithMemoryCacheBuilder.cs

File renamed without changes.

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IWithMemoryCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/MemoryCache/WithMemoryCache/IWithMemoryCacheBuilder.cs

File renamed without changes.

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IAndWithoutMemoryCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/MemoryCache/WithoutMemoryCache/IAndWithoutMemoryCacheBuilder.cs

File renamed without changes.

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IWithoutMemoryCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/MemoryCache/WithoutMemoryCache/IWithoutMemoryCacheBuilder.cs

File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Data
2+
{
3+
using System;
4+
using Microsoft.Extensions.Caching.Distributed;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
public abstract class BaseDistributedCacheBuilder
8+
{
9+
public BaseDistributedCacheBuilder(IServiceProvider services)
10+
=> this.DistributedCache = services.GetRequiredService<IDistributedCache>();
11+
12+
/// <summary>
13+
/// Gets the mocked <see cref="IDistributedCache"/>.
14+
/// </summary>
15+
/// <value>Built <see cref="IDistributedCache"/>.</value>
16+
protected IDistributedCache DistributedCache { get; private set; }
17+
}
18+
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/DistributedCache/DistributedCacheBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/DistributedCache/WithDistributedCache/WithDistributedCacheBuilder.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
1-
namespace MyTested.AspNetCore.Mvc.Builders.Data.DistributedCache
1+
namespace MyTested.AspNetCore.Mvc.Builders.Data
22
{
33
using System;
44
using System.Collections.Generic;
55
using Contracts.Data.DistributedCache;
66
using Microsoft.Extensions.Caching.Distributed;
7-
using Microsoft.Extensions.DependencyInjection;
7+
using Builders.Data.DistributedCache;
88
using Utilities.Extensions;
9+
using Builders.Contracts.Data;
910

10-
public class DistributedCacheBuilder : IAndDistributedCacheBuilder
11+
public class WithDistributedCacheBuilder : BaseDistributedCacheBuilder, IAndWithDistributedCacheBuilder
1112
{
1213
/// <summary>
13-
/// Initializes a new instance of the <see cref="DistributedCacheBuilder"/> class.
14+
/// Initializes a new instance of the <see cref="WithDistributedCacheBuilder"/> class.
1415
/// </summary>
1516
/// <param name="services"><see cref="IServiceProvider"/> providing the current <see cref="IDistributedCache"/>.</param>
16-
public DistributedCacheBuilder(IServiceProvider services)
17-
=> this.DistributedCache = services.GetRequiredService<IDistributedCache>();
18-
19-
/// <summary>
20-
/// Gets the mocked <see cref="IDistributedCache"/>.
21-
/// </summary>
22-
/// <value>Built <see cref="IDistributedCache"/>.</value>
23-
protected IDistributedCache DistributedCache { get; private set; }
17+
public WithDistributedCacheBuilder(IServiceProvider services)
18+
: base(services)
19+
{
20+
}
2421

2522
/// <inheritdoc />
26-
public IAndDistributedCacheBuilder WithEntry(string key, byte[] value)
23+
public IAndWithDistributedCacheBuilder WithEntry(string key, byte[] value)
2724
{
2825
this.DistributedCache.Set(key, value);
2926
return this;
3027
}
3128

32-
public IAndDistributedCacheBuilder WithEntry(string key, string value)
29+
public IAndWithDistributedCacheBuilder WithEntry(string key, string value)
3330
{
3431
this.DistributedCache.SetString(key, value);
3532
return this;
3633
}
3734

3835
/// <inheritdoc />
39-
public IAndDistributedCacheBuilder WithEntry(string key, byte[] value, DistributedCacheEntryOptions options)
36+
public IAndWithDistributedCacheBuilder WithEntry(string key, byte[] value, DistributedCacheEntryOptions options)
4037
{
4138
this.DistributedCache.Set(key, value, options);
4239
return this;
4340
}
4441

45-
public IAndDistributedCacheBuilder WithEntry(string key, string value, DistributedCacheEntryOptions options)
42+
public IAndWithDistributedCacheBuilder WithEntry(string key, string value, DistributedCacheEntryOptions options)
4643
{
4744
this.DistributedCache.SetString(key, value, options);
4845
return this;
4946
}
5047

51-
public IAndDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBuilder> distributedCacheEntryBuilder)
48+
public IAndWithDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBuilder> distributedCacheEntryBuilder)
5249
{
5350
var newDistributedCacheEntryBuilder = new DistributedCacheEntryBuilder();
5451
distributedCacheEntryBuilder(newDistributedCacheEntryBuilder);
@@ -65,19 +62,19 @@ public IAndDistributedCacheBuilder WithEntry(Action<IDistributedCacheEntryKeyBui
6562
}
6663

6764
/// <inheritdoc />
68-
public IAndDistributedCacheBuilder WithEntries(IDictionary<string, byte[]> entries)
65+
public IAndWithDistributedCacheBuilder WithEntries(IDictionary<string, byte[]> entries)
6966
{
7067
entries.ForEach(e => this.WithEntry(e.Key, e.Value));
7168
return this;
7269
}
7370

74-
public IAndDistributedCacheBuilder WithEntries(IDictionary<string, string> entries)
71+
public IAndWithDistributedCacheBuilder WithEntries(IDictionary<string, string> entries)
7572
{
7673
entries.ForEach(e => this.WithEntry(e.Key, e.Value));
7774
return this;
7875
}
7976

8077
/// <inheritdoc />
81-
public IDistributedCacheBuilder AndAlso() => this;
78+
public IWithDistributedCacheBuilder AndAlso() => this;
8279
}
8380
}

0 commit comments

Comments
 (0)