-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
CoreArchitecturalTests.cs
93 lines (80 loc) · 3.22 KB
/
CoreArchitecturalTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using HappyCode.NetCoreBoilerplate.Core;
using Microsoft.EntityFrameworkCore;
using NetArchTest.Rules;
using Xunit;
namespace HappyCode.NetCoreBoilerplate.ArchitecturalTests
{
public class CoreArchitecturalTests
{
private static readonly Types _coreTypes = Types.InAssembly(typeof(FeatureFlags).Assembly);
[Fact]
public void Core_should_not_use_AspNetCore()
{
var result = _coreTypes
.ShouldNot()
.HaveDependencyOn("Microsoft.AspNetCore")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
[Fact]
public void Repositories_should_not_use_Services()
{
var result = _coreTypes
.That()
.ResideInNamespace("HappyCode.NetCoreBoilerplate.Core.Repositories")
.ShouldNot()
.HaveDependencyOn("HappyCode.NetCoreBoilerplate.Core.Services")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
[Fact]
public void Repositories_should_have_Repository_suffix()
{
var result = _coreTypes
.That()
.ResideInNamespace("HappyCode.NetCoreBoilerplate.Core.Repositories")
.And()
.AreNotAbstract()
.Should()
.HaveNameEndingWith("Repository")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
[Fact]
public void Services_should_have_Service_suffix()
{
var result = _coreTypes
.That()
.ResideInNamespace("HappyCode.NetCoreBoilerplate.Core.Services")
.And()
.AreNotAbstract()
.Should()
.HaveNameEndingWith("Service")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
[Fact]
public void Dto_should_have_Dto_suffix()
{
var result = _coreTypes
.That()
.ResideInNamespace("HappyCode.NetCoreBoilerplate.Core.Dtos")
.Should()
.HaveNameEndingWith("Dto")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
[Fact]
public void DbContext_should_have_Context_suffix()
{
var result = _coreTypes
.That()
.Inherit(typeof(DbContext))
.Should()
.HaveNameEndingWith("Context")
.GetResult();
Assert.True(result.IsSuccessful, $"Failing Types: {string.Join("; ", result.FailingTypeNames ?? Array.Empty<string>())}");
}
}
}