Skip to content

Commit 6e60239

Browse files
authored
Add Title property to Error class. (#7)
1 parent 073dd31 commit 6e60239

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

Winton.DomainModelling.Abstractions.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{859C9252-D63B-4ECB-9AB5-0BA8415C76AE}"
77
ProjectSection(SolutionItems) = preProject
88
.gitignore = .gitignore
9+
.travis.yml = .travis.yml
10+
appveyor.yml = appveyor.yml
11+
CONTRIBUTING.md = CONTRIBUTING.md
912
GitVersion.yml = GitVersion.yml
13+
icon.jpg = icon.jpg
14+
LICENSE = LICENSE
1015
README.md = README.md
1116
stylecop.json = stylecop.json
1217
EndProjectSection

src/Winton.DomainModelling.Abstractions/Error.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@ public class Error
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="Error" /> class.
2323
/// </summary>
24+
/// <param name="title">The title for this type of error.</param>
2425
/// <param name="detail">The detail that describes the error.</param>
2526
/// <returns>A new instance of <see cref="Error" />.</returns>
26-
public Error(string detail)
27+
public Error(string title, string detail)
2728
{
29+
Title = title;
2830
Detail = detail;
2931
}
3032

3133
/// <summary>
3234
/// Gets the detail that describes the error.
3335
/// </summary>
3436
public string Detail { get; }
37+
38+
/// <summary>
39+
/// Gets the title of the error. This should be the same for all instances of the same error type.
40+
/// </summary>
41+
public string Title { get; }
3542
}
3643
}

src/Winton.DomainModelling.Abstractions/NotFoundError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class NotFoundError : Error
1515
/// <param name="detail">The detail that describes the error.</param>
1616
/// <returns>A new instance of <see cref="NotFoundError" />.</returns>
1717
public NotFoundError(string detail)
18-
: base(detail)
18+
: base("Not found", detail)
1919
{
2020
}
2121
}

src/Winton.DomainModelling.Abstractions/UnauthorizedError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class UnauthorizedError : Error
1515
/// <param name="detail">The detail that describes the error.</param>
1616
/// <returns>A new instance of <see cref="UnauthorizedError" />.</returns>
1717
public UnauthorizedError(string detail)
18-
: base(detail)
18+
: base("Unauthorized", detail)
1919
{
2020
}
2121
}

test/Winton.DomainModelling.Abstractions.Tests/AsyncResultExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public sealed class Then : AsyncResultExtensionsTests
2323
},
2424
new object[]
2525
{
26-
Task.FromResult<Result<int>>(new Failure<int>(new Error("Boom!"))),
26+
Task.FromResult<Result<int>>(new Failure<int>(new Error("Error", "Boom!"))),
2727
new Func<int, Result<int>>(i => new Success<int>(i + 1)),
28-
new Failure<int>(new Error("Boom!"))
28+
new Failure<int>(new Error("Error", "Boom!"))
2929
}
3030
};
3131

@@ -39,9 +39,9 @@ public sealed class Then : AsyncResultExtensionsTests
3939
},
4040
new object[]
4141
{
42-
Task.FromResult<Result<int>>(new Failure<int>(new Error("Boom!"))),
42+
Task.FromResult<Result<int>>(new Failure<int>(new Error("Error", "Boom!"))),
4343
new Func<int, Task<Result<int>>>(i => Task.FromResult<Result<int>>(new Success<int>(i + 1))),
44-
new Failure<int>(new Error("Boom!"))
44+
new Failure<int>(new Error("Error", "Boom!"))
4545
}
4646
};
4747

test/Winton.DomainModelling.Abstractions.Tests/FailureTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ public sealed class Combine : FailureTests
1414
[Fact]
1515
private void ShouldCombineErrorsIfTheOtherResultIsAFailure()
1616
{
17-
var failure = new Failure<int>(new Error("Ka"));
17+
var failure = new Failure<int>(new Error("Error", "Ka"));
1818

1919
Result<int> combined = failure.Combine(
20-
new Failure<int>(new Error("Boom!")),
20+
new Failure<int>(new Error("Error", "Boom!")),
2121
(i, j) => i + j,
22-
(error, otherError) => new Error($"{error.Detail}-{otherError.Detail}"));
22+
(error, otherError) => new Error("Error", $"{error.Detail}-{otherError.Detail}"));
2323

24-
combined.Should().BeEquivalentTo(new Failure<int>(new Error("Ka-Boom!")));
24+
combined.Should().BeEquivalentTo(new Failure<int>(new Error("Error", "Ka-Boom!")));
2525
}
2626

2727
[Fact]
2828
private void ShouldReturnFailureWithOriginalErrorIfOtherIsASuccess()
2929
{
30-
var failure = new Failure<int>(new Error("Ka"));
30+
var failure = new Failure<int>(new Error("Error", "Ka"));
3131

3232
Result<int> combined = failure.Combine(
3333
new Success<int>(2),
3434
(i, j) => i + j,
35-
(error, otherError) => new Error($"{error.Detail}-{otherError.Detail}"));
35+
(error, otherError) => new Error("Error", $"{error.Detail}-{otherError.Detail}"));
3636

3737
combined.Should().BeEquivalentTo(failure);
3838
}
@@ -43,7 +43,7 @@ public sealed class Match : FailureTests
4343
[Fact]
4444
private void ShouldInvokeOnFailureFunc()
4545
{
46-
var failure = new Failure<int>(new Error("Boom!"));
46+
var failure = new Failure<int>(new Error("Error", "Boom!"));
4747

4848
bool matchedFailure = failure.Match(_ => false, _ => true);
4949

@@ -56,7 +56,7 @@ public sealed class Select : FailureTests
5656
[Fact]
5757
private void ShouldReturnOriginalFailure()
5858
{
59-
var failure = new Failure<int>(new Error("Boom!"));
59+
var failure = new Failure<int>(new Error("Error", "Boom!"));
6060

6161
Result<string> result = failure.Select(i => $"{i}");
6262

@@ -66,7 +66,7 @@ private void ShouldReturnOriginalFailure()
6666
[Fact]
6767
private async Task ShouldReturnOriginalFailureAsynchronously()
6868
{
69-
var failure = new Failure<int>(new Error("Boom!"));
69+
var failure = new Failure<int>(new Error("Error", "Boom!"));
7070

7171
Result<string> result = await failure.Select(i => Task.FromResult($"{i}"));
7272

@@ -79,7 +79,7 @@ public sealed class Then : FailureTests
7979
[Fact]
8080
private void ShouldReturnFailureWithOriginalError()
8181
{
82-
var failure = new Failure<int>(new Error("Boom!"));
82+
var failure = new Failure<int>(new Error("Error", "Boom!"));
8383

8484
Result<int> result = failure.Then(i => new Success<int>(i + 1));
8585

@@ -95,7 +95,7 @@ async Task<Result<int>> OnSuccess(int i)
9595
return new Success<int>(i + 1);
9696
}
9797

98-
var failure = new Failure<int>(new Error("Boom!"));
98+
var failure = new Failure<int>(new Error("Error", "Boom!"));
9999

100100
Result<int> result = await failure.Then(OnSuccess);
101101

test/Winton.DomainModelling.Abstractions.Tests/SuccessTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private void ShouldCombineDataElementsIfOtherResultIsASuccess()
1919
Result<int> combined = success.Combine(
2020
new Success<int>(2),
2121
(i, j) => i + j,
22-
(error, otherError) => new Error($"{error.Detail}-{otherError.Detail}"));
22+
(error, otherError) => new Error("Error", $"{error.Detail}-{otherError.Detail}"));
2323

2424
combined.Should().BeEquivalentTo(new Success<int>(3));
2525
}
@@ -28,12 +28,12 @@ private void ShouldCombineDataElementsIfOtherResultIsASuccess()
2828
private void ShouldReturnFailureWithOtherErrorIfTheOtherResultIsAFailure()
2929
{
3030
var success = new Success<int>(1);
31-
var otherResult = new Failure<int>(new Error("Boom!"));
31+
var otherResult = new Failure<int>(new Error("Error", "Boom!"));
3232

3333
Result<int> combined = success.Combine(
3434
otherResult,
3535
(i, j) => i + j,
36-
(error, otherError) => new Error($"{error.Detail}-{otherError.Detail}"));
36+
(error, otherError) => new Error("Error", $"{error.Detail}-{otherError.Detail}"));
3737

3838
combined.Should().BeEquivalentTo(otherResult);
3939
}

0 commit comments

Comments
 (0)