Skip to content

Commit 55ca4f8

Browse files
committed
#283 Fixing PR comments
- Adding more options from to provide to WithoutSession and WithoutData components. - Placing System usings on top of the using list - Class renaming, small code style fixes.
1 parent b2a18a8 commit 55ca4f8

File tree

18 files changed

+283
-51
lines changed

18 files changed

+283
-51
lines changed

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IWithoutMemoryCacheBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
22
{
3-
using Microsoft.Extensions.Caching.Memory;
43
using System.Collections.Generic;
4+
using Microsoft.Extensions.Caching.Memory;
55

66
/// <summary>
77
/// Used for building mocked <see cref="IMemoryCache"/>.
@@ -22,10 +22,17 @@ public interface IWithoutMemoryCacheBuilder
2222
/// <returns>The same <see cref="IAndWithoutMemoryCacheBuilder"/>.</returns>
2323
IAndWithoutMemoryCacheBuilder WithoutEntries(IEnumerable<object> keys);
2424

25+
/// <summary>
26+
/// Remove cache params to the mocked <see cref="IMemoryCache"/>.
27+
/// </summary>
28+
/// <param name="keys">Keys of the cache entries.</param>
29+
/// <returns>The same <see cref="IAndWithoutMemoryCacheBuilder"/>.</returns>
30+
IAndWithoutMemoryCacheBuilder WithoutEntries(params object[] keys);
31+
2532
/// <summary>
2633
/// Clear all entries persisted into the <see cref="IMemoryCache"/>.
2734
/// </summary>
2835
/// <returns>The same <see cref="IAndWithoutMemoryCacheBuilder"/>.</returns>
29-
IAndWithoutMemoryCacheBuilder ClearCache();
36+
IAndWithoutMemoryCacheBuilder WithoutAllEntries();
3037
}
3138
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCacheBaseBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/BaseMemoryCacheBuilder.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Data
22
{
3+
using System;
34
using Microsoft.Extensions.Caching.Memory;
45
using Microsoft.Extensions.DependencyInjection;
5-
using System;
66

77
/// <summary>
88
/// Used for building mocked <see cref="IMemoryCache"/>.
99
/// </summary>
10-
public abstract class MemoryCacheBaseBuilder
10+
public abstract class BaseMemoryCacheBuilder
1111
{
1212
/// <summary>
13-
/// Abstract <see cref="MemoryCacheBaseBuilder"/> class.
13+
/// Abstract <see cref="BaseMemoryCacheBuilder"/> class.
1414
/// </summary>
1515
/// <param name="services"><see cref="IServiceProvider"/> providing the current <see cref="IMemoryCache"/>.</param>
16-
public MemoryCacheBaseBuilder(IServiceProvider services)
17-
{
18-
this.MemoryCache = services.GetRequiredService<IMemoryCache>();
19-
}
16+
public BaseMemoryCacheBuilder(IServiceProvider services)
17+
=> this.MemoryCache = services.GetRequiredService<IMemoryCache>();
2018

2119
protected IMemoryCache MemoryCache { get; private set; }
2220
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCacheWithBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/WithMemoryCacheBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
using Utilities.Extensions;
88

99
/// <inheritdoc />
10-
public class MemoryCacheWithBuilder : MemoryCacheBaseBuilder, IAndWithMemoryCacheBuilder
10+
public class WithMemoryCacheBuilder : BaseMemoryCacheBuilder, IAndWithMemoryCacheBuilder
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="MemoryCacheWithBuilder"/> class.
13+
/// Initializes a new instance of the <see cref="WithMemoryCacheBuilder"/> class.
1414
/// </summary>
1515
/// <param name="services"><see cref="IServiceProvider"/> providing the current <see cref="IMemoryCache"/>.</param>
16-
public MemoryCacheWithBuilder(IServiceProvider services) : base(services) { }
16+
public WithMemoryCacheBuilder(IServiceProvider services)
17+
: base(services)
18+
{
19+
}
1720

1821
/// <inheritdoc />
1922
public IAndWithMemoryCacheBuilder WithEntry(object key, object value)

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCacheWithoutBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/WithoutMemoryCacheBuilder.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
using Utilities.Extensions;
88

99
/// <inheritdoc />
10-
public class MemoryCacheWithoutBuilder : MemoryCacheBaseBuilder, IAndWithoutMemoryCacheBuilder
10+
public class WithoutMemoryCacheBuilder : BaseMemoryCacheBuilder, IAndWithoutMemoryCacheBuilder
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="MemoryCacheWithoutBuilder"/> class.
13+
/// Initializes a new instance of the <see cref="WithoutMemoryCacheBuilder"/> class.
1414
/// </summary>
1515
/// <param name="services"><see cref="IServiceProvider"/> providing the current <see cref="IMemoryCache"/>.</param>
16-
public MemoryCacheWithoutBuilder(IServiceProvider services) : base(services) { }
16+
public WithoutMemoryCacheBuilder(IServiceProvider services)
17+
: base(services)
18+
{
19+
}
1720

1821
/// <inheritdoc />
1922
public IAndWithoutMemoryCacheBuilder WithoutEntry(object key)
@@ -30,12 +33,19 @@ public IAndWithoutMemoryCacheBuilder WithoutEntries(IEnumerable<object> keys)
3033
}
3134

3235
/// <inheritdoc />
33-
public IAndWithoutMemoryCacheBuilder ClearCache()
36+
public IAndWithoutMemoryCacheBuilder WithoutAllEntries()
3437
{
3538
this.MemoryCache.AsMemoryCacheMock().ClearCache();
3639
return this;
3740
}
3841

42+
/// <inheritdoc />
43+
public IAndWithoutMemoryCacheBuilder WithoutEntries(params object[] keys)
44+
{
45+
this.MemoryCache.AsMemoryCacheMock().RemoveKeys(keys);
46+
return this;
47+
}
48+
3949
/// <inheritdoc />
4050
public IWithoutMemoryCacheBuilder AndAlso() => this;
4151
}

src/MyTested.AspNetCore.Mvc.Caching/ComponentBuilderCachingExtensions.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace MyTested.AspNetCore.Mvc
22
{
33
using System;
4+
using System.Collections.Generic;
45
using Builders.Contracts.Base;
56
using Builders.Contracts.Data;
67
using Builders.Data;
78
using Builders.Base;
8-
using System.Collections.Generic;
99

1010
/// <summary>
1111
/// Contains <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
@@ -26,7 +26,7 @@ public static TBuilder WithMemoryCache<TBuilder>(
2626
{
2727
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
2828

29-
memoryCacheBuilder(new MemoryCacheWithBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
29+
memoryCacheBuilder(new WithMemoryCacheBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
3030

3131
return actualBuilder.Builder;
3232
}
@@ -40,7 +40,7 @@ public static TBuilder WithMemoryCache<TBuilder>(
4040
public static TBuilder WithoutMemoryCache<TBuilder>(
4141
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder)
4242
where TBuilder : IBaseTestBuilder
43-
=> builder.WithoutMemoryCache(cache => cache.ClearCache());
43+
=> builder.WithoutMemoryCache(cache => cache.WithoutAllEntries());
4444

4545
/// <summary>
4646
/// Remove given entity with key from <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
@@ -68,6 +68,19 @@ public static TBuilder WithoutMemoryCache<TBuilder>(
6868
where TBuilder : IBaseTestBuilder
6969
=> builder.WithoutMemoryCache(cache => cache.WithoutEntries(keys));
7070

71+
/// <summary>
72+
/// Remove given entities from <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
73+
/// </summary>
74+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
75+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
76+
/// <param name="keys">Keys of the entities that will be removed.</param>
77+
/// <returns>The same component builder.</returns>
78+
public static TBuilder WithoutMemoryCache<TBuilder>(
79+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
80+
params object[] keys)
81+
where TBuilder : IBaseTestBuilder
82+
=> builder.WithoutMemoryCache(cache => cache.WithoutEntries(keys));
83+
7184
/// <summary>
7285
/// Remove entity or entities from <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
7386
/// </summary>
@@ -82,7 +95,7 @@ public static TBuilder WithoutMemoryCache<TBuilder>(
8295
{
8396
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
8497

85-
memoryCacheBuilder(new MemoryCacheWithoutBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
98+
memoryCacheBuilder(new WithoutMemoryCacheBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
8699

87100
return actualBuilder.Builder;
88101
}

src/MyTested.AspNetCore.Mvc.EntityFrameworkCore/Builders/Contracts/Data/IWithoutDbContextBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
22
{
3-
using Microsoft.EntityFrameworkCore;
43
using System;
54
using System.Collections.Generic;
5+
using Microsoft.EntityFrameworkCore;
66

77
public interface IWithoutDbContextBuilder
88
{
@@ -75,9 +75,9 @@ IAndWithoutDbContextBuilder WithoutSet<TDbContext, TEntity>(Action<DbSet<TEntity
7575
where TEntity : class;
7676

7777
/// <summary>
78-
/// Wipe the whole database data, returning it to a clean state.
78+
/// Wipes the whole database data, returning it to a clean state.
7979
/// </summary>
8080
/// <returns>The same <see cref="DbContext"/> builder.</returns>
81-
IAndWithoutDbContextBuilder WipeDatabase();
81+
IAndWithoutDbContextBuilder WithoutAllEntities();
8282
}
8383
}

src/MyTested.AspNetCore.Mvc.EntityFrameworkCore/Builders/Data/WithoutDbContextBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Data
22
{
3-
using Microsoft.EntityFrameworkCore;
4-
using MyTested.AspNetCore.Mvc.Builders.Base;
5-
using MyTested.AspNetCore.Mvc.Builders.Contracts.Data;
6-
using MyTested.AspNetCore.Mvc.Internal.TestContexts;
7-
using MyTested.AspNetCore.Mvc.Utilities.Validators;
83
using System;
94
using System.Collections.Generic;
105
using System.Linq;
6+
using Base;
7+
using Contracts.Data;
8+
using Internal.TestContexts;
9+
using Microsoft.EntityFrameworkCore;
10+
using Utilities.Validators;
1111

1212
/// <summary>
1313
/// Used for building <see cref="DbContext"/>.
@@ -46,7 +46,7 @@ public IAndWithoutDbContextBuilder WithoutEntities(Action<DbContext> dbContextSe
4646
=> this.WithoutEntities<DbContext>(dbContextSetup);
4747

4848
/// <inheritdoc />
49-
public IAndWithoutDbContextBuilder WipeDatabase()
49+
public IAndWithoutDbContextBuilder WithoutAllEntities()
5050
=> this.WithoutEntities<DbContext>(dbContext => dbContext.Database.EnsureDeleted());
5151

5252
/// <inheritdoc />

src/MyTested.AspNetCore.Mvc.EntityFrameworkCore/ComponentBuilderEntityFrameworkCoreExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static TBuilder WithoutData<TBuilder>(
125125
where TBuilder : IBaseTestBuilder
126126
=> builder
127127
.WithoutData(data => data
128-
.WipeDatabase());
128+
.WithoutAllEntities());
129129

130130
/// <summary>
131131
/// Remove values from the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component or wipes all tables from it.

src/MyTested.AspNetCore.Mvc.Session/Builders/Contracts/Data/IAndWithoutSessionBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Session/Builders/Contracts/Data/IAndWithoutSessionTestBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Used for adding AndAlso() method to the <see cref="Microsoft.AspNetCore.Http.ISession"/> builder.
55
/// </summary>
6-
public interface IAndWithoutSessionBuilder : IWithoutSessionBuilder
6+
public interface IAndWithoutSessionTestBuilder : IWithoutSessionBuilder
77
{
88
/// <summary>
99
/// AndAlso method for better readability when building <see cref="Microsoft.AspNetCore.Http.ISession"/>.
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Data
22
{
3+
using System.Collections.Generic;
4+
35
/// <summary>
46
/// Used for building <see cref="Microsoft.AspNetCore.Http.ISession"/>.
57
/// </summary>
@@ -9,13 +11,27 @@ public interface IWithoutSessionBuilder
911
/// Removes session key from <see cref="Microsoft.AspNetCore.Http.ISession"/>.
1012
/// </summary>
1113
/// <param name="key">The key to remove as string.</param>
12-
/// <returns>The same <see cref="IAndWithoutSessionBuilder"/>.</returns>
13-
IAndWithoutSessionBuilder WithoutEntry(string key);
14+
/// <returns>The same <see cref="IAndWithoutSessionTestBuilder"/>.</returns>
15+
IAndWithoutSessionTestBuilder WithoutEntry(string key);
16+
17+
/// <summary>
18+
/// Removes provided keys from <see cref="Microsoft.AspNetCore.Http.ISession"/>.
19+
/// </summary>
20+
/// <param name="keys">The given collection of keys to remove as string.</param>
21+
/// <returns>The same <see cref="IAndWithoutSessionTestBuilder"/>.</returns>
22+
IAndWithoutSessionTestBuilder WithoutEntries(IEnumerable<string> keys);
23+
24+
/// <summary>
25+
/// Removes provided keys from <see cref="Microsoft.AspNetCore.Http.ISession"/>.
26+
/// </summary>
27+
/// <param name="keys">The given param colletion of keys to remove as string.</param>
28+
/// <returns>The same <see cref="IAndWithoutSessionTestBuilder"/>.</returns>
29+
IAndWithoutSessionTestBuilder WithoutEntries(params string[] keys);
1430

1531
/// <summary>
16-
/// Clears the whole <see cref="Microsoft.AspNetCore.Http.ISession"/>.
32+
/// Clears all entries from <see cref="Microsoft.AspNetCore.Http.ISession"/>.
1733
/// </summary>
18-
/// <returns>The same <see cref="IAndWithoutSessionBuilder"/>.</returns>
19-
IAndWithoutSessionBuilder ClearSession();
34+
/// <returns>The same <see cref="IAndWithoutSessionTestBuilder"/>.</returns>
35+
IAndWithoutSessionTestBuilder WithoutAllEntries();
2036
}
2137
}

0 commit comments

Comments
 (0)