Skip to content

Commit b4bf5c6

Browse files
Matthew ThorntonMatthew Thornton
authored andcommitted
Merge pull request #2 in TECHBUS/winton.domainmodelling.abstractions from feature/BT-6528 to master
* commit '5305b81eefc2f5a38c775f8b24521262d1c5cc33': Add solution items to VS. Add domain exceptions.
2 parents 532b578 + 5305b81 commit b4bf5c6

File tree

8 files changed

+158
-23
lines changed

8 files changed

+158
-23
lines changed

Winton.DomainModelling.Abstractions.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{697902B3-26B
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{02075BDC-A66D-4346-8093-2F2667660F36}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Winton.DomainModelling.Abstractions", "src\Winton.DomainModelling.Abstractions\Winton.DomainModelling.Abstractions.csproj", "{4CC49F58-367B-4E87-8925-49D913FA7BD1}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Winton.DomainModelling.Abstractions", "src\Winton.DomainModelling.Abstractions\Winton.DomainModelling.Abstractions.csproj", "{4CC49F58-367B-4E87-8925-49D913FA7BD1}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Winton.DomainModelling.Abstractions.Tests", "test\Winton.DomainModelling.Abstractions.Tests\Winton.DomainModelling.Abstractions.Tests.csproj", "{8FD5A9B0-44ED-470F-A0F0-721E55B5790D}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Winton.DomainModelling.Abstractions.Tests", "test\Winton.DomainModelling.Abstractions.Tests\Winton.DomainModelling.Abstractions.Tests.csproj", "{8FD5A9B0-44ED-470F-A0F0-721E55B5790D}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{859C9252-D63B-4ECB-9AB5-0BA8415C76AE}"
15+
ProjectSection(SolutionItems) = preProject
16+
.gitignore = .gitignore
17+
GitVersionConfig.yaml = GitVersionConfig.yaml
18+
Jenkinsfile = Jenkinsfile
19+
README.md = README.md
20+
stylecop.json = stylecop.json
21+
EndProjectSection
1322
EndProject
1423
Global
1524
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace Winton.DomainModelling
4+
{
5+
/// <inheritdoc />
6+
/// <summary>
7+
/// Represents domain errors.
8+
/// </summary>
9+
public class DomainException : Exception
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="DomainException" /> class.
13+
/// </summary>
14+
/// <param name="message">The message that describes the error.</param>
15+
public DomainException(string message)
16+
: base(message)
17+
{
18+
}
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace Winton.DomainModelling
4+
{
5+
/// <inheritdoc />
6+
/// <summary>
7+
/// An error indicating that an entity could not be found.
8+
/// </summary>
9+
/// <typeparam name="TEntity">The type of entity.</typeparam>
10+
/// <typeparam name="TEntityId">The type of entity id.</typeparam>
11+
public class EntityNotFoundException<TEntity, TEntityId> : DomainException
12+
where TEntity : Entity<TEntityId>
13+
where TEntityId : IEquatable<TEntityId>
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="EntityNotFoundException{TEntity, TEntityId}" /> class.
17+
/// </summary>
18+
public EntityNotFoundException()
19+
: base($"The specified {typeof(TEntity).Name} could not be found.")
20+
{
21+
}
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Winton.DomainModelling
2+
{
3+
/// <inheritdoc />
4+
/// <summary>
5+
/// An error indicating that the action being performed is not authorized.
6+
/// </summary>
7+
public class UnauthorizedException : DomainException
8+
{
9+
/// <summary>
10+
/// Initializes a new instance of the <see cref="UnauthorizedException" /> class.
11+
/// </summary>
12+
/// <param name="message">The message that describes the error.</param>
13+
public UnauthorizedException(string message)
14+
: base(message)
15+
{
16+
}
17+
}
18+
}

stylecop.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
{
2-
"$schema":
3-
"https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/1.0.2/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
4-
"settings": {
5-
"documentationRules": {
6-
"documentExposedElements": false,
7-
"documentInterfaces": false,
8-
"documentInternalElements": false,
9-
"xmlHeader": false
10-
},
11-
"maintainabilityRules": {
12-
"topLevelTypes": [
13-
"class",
14-
"enum",
15-
"interface",
16-
"struct"
17-
]
18-
},
19-
"orderingRules": {
20-
"blankLinesBetweenUsingGroups": "omit",
21-
"usingDirectivesPlacement": "outsideNamespace"
2+
"$schema":
3+
"https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/1.0.2/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
4+
"settings": {
5+
"documentationRules": {
6+
"documentInternalElements": false,
7+
"xmlHeader": false
8+
},
9+
"maintainabilityRules": {
10+
"topLevelTypes": [
11+
"class",
12+
"enum",
13+
"interface",
14+
"struct"
15+
]
16+
},
17+
"orderingRules": {
18+
"blankLinesBetweenUsingGroups": "omit",
19+
"usingDirectivesPlacement": "outsideNamespace"
20+
}
2221
}
23-
}
2422
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace Winton.DomainModelling
5+
{
6+
public class DomainExceptionTests
7+
{
8+
public sealed class Message : DomainExceptionTests
9+
{
10+
[Theory]
11+
[InlineData("Test")]
12+
[InlineData("Foo")]
13+
private void ShouldSetMessageFromConstructor(string message)
14+
{
15+
var exception = new DomainException(message);
16+
17+
exception.Message.Should().Be(message);
18+
}
19+
}
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace Winton.DomainModelling
5+
{
6+
public class EntityNotFoundExceptionTests
7+
{
8+
[Fact]
9+
private void ShouldSetMessageBasedOnTypeOfEntity()
10+
{
11+
var exception = new EntityNotFoundException<TestEntity, int>();
12+
13+
exception.Message.Should().Be("The specified TestEntity could not be found.");
14+
}
15+
16+
// ReSharper disable once ClassNeverInstantiated.Local
17+
private sealed class TestEntity : Entity<int>
18+
{
19+
public TestEntity(int id)
20+
: base(id)
21+
{
22+
}
23+
}
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace Winton.DomainModelling
5+
{
6+
public class UnauthorizedExceptionTests
7+
{
8+
public sealed class Message : UnauthorizedExceptionTests
9+
{
10+
[Theory]
11+
[InlineData("Test")]
12+
[InlineData("Foo")]
13+
private void ShouldSetMessageFromConstructor(string message)
14+
{
15+
var exception = new UnauthorizedException(message);
16+
17+
exception.Message.Should().Be(message);
18+
}
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)