Skip to content

Commit 9e69647

Browse files
committed
handle open generic type passed as parameter to ImplementInterface
1 parent c5f723d commit 9e69647

File tree

32 files changed

+399
-43
lines changed

32 files changed

+399
-43
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,23 @@ The library is available as a package on NuGet: [NetArchTest.eNhancedEdition](ht
6464
[TestClass]
6565
public class SampleApp_ModuleAlpha_Tests
6666
{
67-
static readonly Assembly AssemblyUnderTest = typeof(SampleApp.ModuleAlpha.TestUtils).Assembly;
67+
static readonly Assembly AssemblyUnderTest = typeof(TestUtils).Assembly;
68+
6869
[TestMethod]
6970
public void PersistenceIsNotAccessibleFromOutsideOfModuleExceptOfDbContext()
7071
{
7172
var result = Types.InAssembly(AssemblyUnderTest)
7273
.That()
73-
.ResideInNamespace("SampleApp.ModuleAlpha.Persistence")
74+
.ResideInNamespace("SampleApp.ModuleAlpha.Persistence")
7475
.And()
7576
.DoNotHaveNameEndingWith("DbContext")
7677
.Should()
7778
.NotBePublic()
7879
.GetResult();
80+
7981
Assert.IsTrue(result.IsSuccessful);
8082
}
83+
8184
[TestMethod]
8285
public void DomainIsIndependent()
8386
{
@@ -89,11 +92,32 @@ public class SampleApp_ModuleAlpha_Tests
8992
"System",
9093
"SampleApp.ModuleAlpha.Domain",
9194
"SampleApp.SharedKernel.Domain",
92-
"SampleApp.BuildingBlocks.Domain"
95+
"SampleApp.BuildingBlocks.Domain"
9396
)
9497
.GetResult();
98+
9599
Assert.IsTrue(result.IsSuccessful, "Domain has lost its independence!");
96100
}
101+
102+
}
103+
104+
[TestClass]
105+
public class SampleApp_ModuleOmega_Tests
106+
{
107+
static readonly Assembly AssemblyUnderTest = typeof(TestUtils).Assembly;
108+
109+
[TestMethod]
110+
public void RequestHandlersShouldBeSealed()
111+
{
112+
var result = Types.InAssembly(AssemblyUnderTest)
113+
.That()
114+
.ImplementInterface(typeof(IRequestHandler<,>))
115+
.Should()
116+
.BeSealed()
117+
.GetResult();
118+
119+
Assert.IsTrue(result.IsSuccessful);
120+
}
97121
}
98122
```
99123

documentation/readme.nt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ The library is available as a package on NuGet: [NetArchTest.eNhancedEdition](ht
6464
### Examples
6565

6666
```csharp
67-
{{ sample = data.Classes | Symbols.WhereNameMatches "SampleApp_ModuleAlpha_Tests" | Array.First
68-
sample.SourceCode
67+
{{ sample1 = data.Classes | Symbols.WhereNameMatches "SampleApp_ModuleAlpha_Tests" | Array.First
68+
sample1.SourceCode}}
69+
70+
{{ sample2 = data.Classes | Symbols.WhereNameMatches "SampleApp_ModuleOmega_Tests" | Array.First
71+
sample2.SourceCode
6972
}}
7073
```
7174

samples/NetArchTest.SampleTests/UnitTest1.cs renamed to samples/NetArchTest.SampleTests/SampleApp_ModuleAlpha_Tests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
using System.Reflection;
2+
using MediatR;
23
using Microsoft.VisualStudio.TestTools.UnitTesting;
34
using NetArchTest.Rules;
5+
using SampleApp.ModuleAlpha;
46

57
namespace NetArchTest.SampleTests
68
{
79
[TestClass]
810
public class SampleApp_ModuleAlpha_Tests
911
{
10-
static readonly Assembly AssemblyUnderTest = typeof(SampleApp.ModuleAlpha.TestUtils).Assembly;
12+
static readonly Assembly AssemblyUnderTest = typeof(TestUtils).Assembly;
1113

1214
[TestMethod]
1315
public void PersistenceIsNotAccessibleFromOutsideOfModuleExceptOfDbContext()
1416
{
1517
var result = Types.InAssembly(AssemblyUnderTest)
1618
.That()
17-
.ResideInNamespace("SampleApp.ModuleAlpha.Persistence")
19+
.ResideInNamespace("SampleApp.ModuleAlpha.Persistence")
1820
.And()
1921
.DoNotHaveNameEndingWith("DbContext")
2022
.Should()
2123
.NotBePublic()
2224
.GetResult();
25+
2326
Assert.IsTrue(result.IsSuccessful);
2427
}
2528

@@ -34,10 +37,12 @@ public void DomainIsIndependent()
3437
"System",
3538
"SampleApp.ModuleAlpha.Domain",
3639
"SampleApp.SharedKernel.Domain",
37-
"SampleApp.BuildingBlocks.Domain"
40+
"SampleApp.BuildingBlocks.Domain"
3841
)
3942
.GetResult();
43+
4044
Assert.IsTrue(result.IsSuccessful, "Domain has lost its independence!");
4145
}
46+
4247
}
4348
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Reflection;
2+
using MediatR;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using NetArchTest.Rules;
5+
using SampleApp.ModuleOmega;
6+
7+
8+
namespace NetArchTest.SampleTests
9+
{
10+
[TestClass]
11+
public class SampleApp_ModuleOmega_Tests
12+
{
13+
static readonly Assembly AssemblyUnderTest = typeof(TestUtils).Assembly;
14+
15+
[TestMethod]
16+
public void RequestHandlersShouldBeSealed()
17+
{
18+
var result = Types.InAssembly(AssemblyUnderTest)
19+
.That()
20+
.ImplementInterface(typeof(IRequestHandler<,>))
21+
.Should()
22+
.BeSealed()
23+
.GetResult();
24+
25+
Assert.IsTrue(result.IsSuccessful);
26+
}
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore;
7+
8+
namespace SampleApp.BuildingBlocks.Persistence
9+
{
10+
public abstract class GenericRepository<TEntity, TContext> where TEntity : class
11+
where TContext : DbContext
12+
{
13+
protected readonly TContext context;
14+
15+
16+
public GenericRepository(TContext context)
17+
{
18+
this.context = context;
19+
}
20+
21+
22+
public void Add(TEntity entity)
23+
{
24+
context.Set<TEntity>().Add(entity);
25+
}
26+
public TEntity GetById(long id)
27+
{
28+
return context.Set<TEntity>().Find(id);
29+
}
30+
}
31+
}

samples/SampleApp.BuildingBlocks/SampleApp.BuildingBlocks.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
<Folder Include="Domain\" />
1111
</ItemGroup>
1212

13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
15+
</ItemGroup>
16+
1317
</Project>

samples/SampleApp.ModuleAlpha/App/Users/UsersService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace SampleApp.ModuleAlpha.App.Users
55
{
6-
internal class UsersService
6+
internal sealed class UsersService
77
{
88

99
public async Task<long> CreateUser(CreateUser createUser)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions
8+
{
9+
internal class QuestionOnListDTO
10+
{
11+
}
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using MediatR;
7+
using SampleApp.ModuleOmega.Persistence;
8+
9+
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions
10+
{
11+
internal sealed class ReadQuestionsHandler : IRequestHandler<ReadQuestionsQuery, List<QuestionOnListDTO>>
12+
{
13+
private readonly ReadOnlyTestCreationDbContext context;
14+
15+
public ReadQuestionsHandler(ReadOnlyTestCreationDbContext context)
16+
{
17+
this.context = context;
18+
}
19+
20+
21+
public async Task<List<QuestionOnListDTO>> Handle(ReadQuestionsQuery query, CancellationToken cancellationToken)
22+
{
23+
24+
25+
return null;
26+
}
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using MediatR;
7+
8+
namespace SampleApp.ModuleOmega.App.RequestHandlers.Questions
9+
{
10+
internal class ReadQuestionsQuery : IRequest<List<QuestionOnListDTO>>
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)