Skip to content

Commit 4762588

Browse files
committed
#283 Separating Caching, Core and Session component builders in two parts, one containing "With" and one "Without" implementations.
1 parent 723dc01 commit 4762588

File tree

6 files changed

+147
-102
lines changed

6 files changed

+147
-102
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using Builders.Contracts.Base;
5+
using Builders.Contracts.Data;
6+
using Builders.Data;
7+
using Builders.Base;
8+
9+
/// <summary>
10+
/// Contains <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
11+
/// </summary>
12+
public static class ComponentBuilderCachingWithExtensions
13+
{
14+
/// <summary>
15+
/// Sets initial values to the <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
16+
/// </summary>
17+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
18+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
19+
/// <param name="memoryCacheBuilder">Action setting the <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> values by using <see cref="IWithMemoryCacheBuilder"/>.</param>
20+
/// <returns>The same component builder.</returns>
21+
public static TBuilder WithMemoryCache<TBuilder>(
22+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
23+
Action<IWithMemoryCacheBuilder> memoryCacheBuilder)
24+
where TBuilder : IBaseTestBuilder
25+
{
26+
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
27+
28+
memoryCacheBuilder(new WithMemoryCacheBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
29+
30+
return actualBuilder.Builder;
31+
}
32+
}
33+
}

src/MyTested.AspNetCore.Mvc.Caching/ComponentBuilderCachingExtensions.cs renamed to src/MyTested.AspNetCore.Mvc.Caching/ComponentBuilderCachingWithoutExtensions.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,8 @@
1010
/// <summary>
1111
/// Contains <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
1212
/// </summary>
13-
public static class ComponentBuilderCachingExtensions
13+
public static class ComponentBuilderCachingWithoutExtensions
1414
{
15-
/// <summary>
16-
/// Sets initial values to the <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
17-
/// </summary>
18-
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
19-
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
20-
/// <param name="memoryCacheBuilder">Action setting the <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> values by using <see cref="IWithMemoryCacheBuilder"/>.</param>
21-
/// <returns>The same component builder.</returns>
22-
public static TBuilder WithMemoryCache<TBuilder>(
23-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
24-
Action<IWithMemoryCacheBuilder> memoryCacheBuilder)
25-
where TBuilder : IBaseTestBuilder
26-
{
27-
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
28-
29-
memoryCacheBuilder(new WithMemoryCacheBuilder(actualBuilder.TestContext.HttpContext.RequestServices));
30-
31-
return actualBuilder.Builder;
32-
}
3315

3416
/// <summary>
3517
/// Clear all entities from <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> service.
@@ -50,7 +32,7 @@ public static TBuilder WithoutMemoryCache<TBuilder>(
5032
/// <param name="key">Key of the entity that will be removed.</param>
5133
/// <returns>The same component builder.</returns>
5234
public static TBuilder WithoutMemoryCache<TBuilder>(
53-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
35+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
5436
object key)
5537
where TBuilder : IBaseTestBuilder
5638
=> builder.WithoutMemoryCache(cache => cache.WithoutEntry(key));
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Builders.Base;
6+
using Builders.Contracts.Base;
7+
using Builders.Contracts.Data;
8+
using Builders.Data;
9+
10+
/// <summary>
11+
/// Contains <see cref="Microsoft.EntityFrameworkCore.DbContext"/>
12+
/// extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
13+
/// </summary>
14+
public static class ComponentBuilderEntityFrameworkCoreWithExtensions
15+
{
16+
/// <summary>
17+
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
18+
/// </summary>
19+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
20+
/// <param name="builder">
21+
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
22+
/// </param>
23+
/// <param name="entities">
24+
/// Initial values to add to the registered <see cref="Microsoft.EntityFrameworkCore.DbContext"/>.
25+
/// </param>
26+
/// <returns>The same component builder.</returns>
27+
public static TBuilder WithData<TBuilder>(
28+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
29+
IEnumerable<object> entities)
30+
where TBuilder : IBaseTestBuilder
31+
=> builder
32+
.WithData(data => data
33+
.WithEntities(entities));
34+
35+
/// <summary>
36+
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
37+
/// </summary>
38+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
39+
/// <param name="builder">
40+
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
41+
/// </param>
42+
/// <param name="entities">
43+
/// Initial values to add to the registered <see cref="Microsoft.EntityFrameworkCore.DbContext"/>.
44+
/// </param>
45+
/// <returns>The same component builder.</returns>
46+
public static TBuilder WithData<TBuilder>(
47+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
48+
params object[] entities)
49+
where TBuilder : IBaseTestBuilder
50+
=> builder
51+
.WithData(data => data
52+
.WithEntities(entities));
53+
54+
/// <summary>
55+
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
56+
/// </summary>
57+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
58+
/// <param name="builder">
59+
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
60+
/// </param>
61+
/// <param name="dbContextBuilder">
62+
/// Action setting the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> by using <see cref="IWithDbContextBuilder"/>.
63+
/// </param>
64+
/// <returns>The same component builder.</returns>
65+
public static TBuilder WithData<TBuilder>(
66+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
67+
Action<IWithDbContextBuilder> dbContextBuilder)
68+
where TBuilder : IBaseTestBuilder
69+
{
70+
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
71+
72+
dbContextBuilder(new WithDbContextBuilder(actualBuilder.TestContext));
73+
74+
return actualBuilder.Builder;
75+
}
76+
}
77+
}
Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,8 @@
1111
/// Contains <see cref="Microsoft.EntityFrameworkCore.DbContext"/>
1212
/// extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
1313
/// </summary>
14-
public static class ComponentBuilderEntityFrameworkCoreExtensions
14+
public static class ComponentBuilderEntityFrameworkCoreWithoutExtensions
1515
{
16-
/// <summary>
17-
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
18-
/// </summary>
19-
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
20-
/// <param name="builder">
21-
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
22-
/// </param>
23-
/// <param name="entities">
24-
/// Initial values to add to the registered <see cref="Microsoft.EntityFrameworkCore.DbContext"/>.
25-
/// </param>
26-
/// <returns>The same component builder.</returns>
27-
public static TBuilder WithData<TBuilder>(
28-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
29-
IEnumerable<object> entities)
30-
where TBuilder : IBaseTestBuilder
31-
=> builder
32-
.WithData(data => data
33-
.WithEntities(entities));
34-
35-
/// <summary>
36-
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
37-
/// </summary>
38-
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
39-
/// <param name="builder">
40-
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
41-
/// </param>
42-
/// <param name="entities">
43-
/// Initial values to add to the registered <see cref="Microsoft.EntityFrameworkCore.DbContext"/>.
44-
/// </param>
45-
/// <returns>The same component builder.</returns>
46-
public static TBuilder WithData<TBuilder>(
47-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
48-
params object[] entities)
49-
where TBuilder : IBaseTestBuilder
50-
=> builder
51-
.WithData(data => data
52-
.WithEntities(entities));
53-
54-
/// <summary>
55-
/// Sets initial values to the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
56-
/// </summary>
57-
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
58-
/// <param name="builder">
59-
/// Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.
60-
/// </param>
61-
/// <param name="dbContextBuilder">
62-
/// Action setting the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> by using <see cref="IWithDbContextBuilder"/>.
63-
/// </param>
64-
/// <returns>The same component builder.</returns>
65-
public static TBuilder WithData<TBuilder>(
66-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
67-
Action<IWithDbContextBuilder> dbContextBuilder)
68-
where TBuilder : IBaseTestBuilder
69-
{
70-
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
71-
72-
dbContextBuilder(new WithDbContextBuilder(actualBuilder.TestContext));
73-
74-
return actualBuilder.Builder;
75-
}
76-
7716
/// <summary>
7817
/// Remove entity from the <see cref="Microsoft.EntityFrameworkCore.DbContext"/> on the tested component.
7918
/// </summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using Builders.Base;
5+
using Builders.Contracts.Base;
6+
using Builders.Contracts.Data;
7+
using Builders.Data;
8+
9+
/// <summary>
10+
/// Contains <see cref="Microsoft.AspNetCore.Http.ISession"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
11+
/// </summary>
12+
public static class ComponentBuilderSessionWithExtensions
13+
{
14+
/// <summary>
15+
/// Sets initial values to the HTTP <see cref="Microsoft.AspNetCore.Http.ISession"/>.
16+
/// </summary>
17+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
18+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
19+
/// <param name="sessionBuilder">Action setting the <see cref="Microsoft.AspNetCore.Http.ISession"/> values by using <see cref="IWithSessionBuilder"/>.</param>
20+
/// <returns>The same component builder.</returns>
21+
public static TBuilder WithSession<TBuilder>(
22+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
23+
Action<IWithSessionBuilder> sessionBuilder)
24+
where TBuilder : IBaseTestBuilder
25+
{
26+
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
27+
28+
sessionBuilder(new WithSessionBuilder(actualBuilder.TestContext.Session));
29+
30+
return actualBuilder.Builder;
31+
}
32+
}
33+
}

src/MyTested.AspNetCore.Mvc.Session/ComponentBuilderSessionExtensions.cs renamed to src/MyTested.AspNetCore.Mvc.Session/ComponentBuilderSessionWithoutExtensions.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,8 @@
1010
/// <summary>
1111
/// Contains <see cref="Microsoft.AspNetCore.Http.ISession"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
1212
/// </summary>
13-
public static class ComponentBuilderSessionExtensions
13+
public static class ComponentBuilderSessionWithoutExtensions
1414
{
15-
/// <summary>
16-
/// Sets initial values to the HTTP <see cref="Microsoft.AspNetCore.Http.ISession"/>.
17-
/// </summary>
18-
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
19-
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
20-
/// <param name="sessionBuilder">Action setting the <see cref="Microsoft.AspNetCore.Http.ISession"/> values by using <see cref="IWithSessionBuilder"/>.</param>
21-
/// <returns>The same component builder.</returns>
22-
public static TBuilder WithSession<TBuilder>(
23-
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
24-
Action<IWithSessionBuilder> sessionBuilder)
25-
where TBuilder : IBaseTestBuilder
26-
{
27-
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
28-
29-
sessionBuilder(new WithSessionBuilder(actualBuilder.TestContext.Session));
30-
31-
return actualBuilder.Builder;
32-
}
33-
3415
/// <summary>
3516
/// Clears the whole http <see cref="Microsoft.AspNetCore.Http.ISession"/>.
3617
/// </summary>

0 commit comments

Comments
 (0)