Skip to content

Commit 6867b87

Browse files
authored
Merge pull request #305 from SlimAhmad/users/slimahmad/controllers/contribtionType-Delete
CODE RUB: ContributionType Delete Tests
2 parents c0a83f7 + a646c06 commit 6867b87

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

GitFyle.Core.Api.Tests.Unit/Controllers/ContributionTypes/ContributionTypesControllerTests.Exceptions.Delete.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public partial class ContributionTypesControllerTests
1818
{
1919
[Theory]
2020
[MemberData(nameof(ValidationExceptions))]
21-
public async Task ShouldReturnBadRequestOnDeleteIfValidationErrorOccursAsync(
21+
public async Task ShouldReturnBadRequestOnDeleteIfValidationExceptionOccursAsync(
2222
Xeption validationException)
2323
{
2424
// given
25-
Guid someId = Guid.NewGuid();
25+
Guid someContributionTypeId = Guid.NewGuid();
2626

2727
BadRequestObjectResult expectedBadRequestObjectResult =
2828
BadRequest(validationException.InnerException);
@@ -36,7 +36,8 @@ public async Task ShouldReturnBadRequestOnDeleteIfValidationErrorOccursAsync(
3636

3737
// when
3838
ActionResult<ContributionType> actualActionResult =
39-
await this.contributionTypesController.DeleteContributionTypeByIdAsync(someId);
39+
await this.contributionTypesController.DeleteContributionTypeByIdAsync(
40+
someContributionTypeId);
4041

4142
// then
4243
actualActionResult.ShouldBeEquivalentTo(expectedActionResult);
@@ -50,25 +51,26 @@ public async Task ShouldReturnBadRequestOnDeleteIfValidationErrorOccursAsync(
5051

5152
[Theory]
5253
[MemberData(nameof(ServerExceptions))]
53-
public async Task ShouldReturnInternalServerErrorOnDeleteIfServerErrorOccurredAsync(
54-
Xeption validationException)
54+
public async Task ShouldReturnInternalServerErrorOnDeleteIfServerExceptionOccurredAsync(
55+
Xeption serverException)
5556
{
5657
// given
57-
Guid someId = Guid.NewGuid();
58+
Guid someContributionTypeId = Guid.NewGuid();
5859

59-
InternalServerErrorObjectResult expectedBadRequestObjectResult =
60-
InternalServerError(validationException);
60+
InternalServerErrorObjectResult expectedInternalServerErrorObjectResult =
61+
InternalServerError(serverException);
6162

6263
var expectedActionResult =
63-
new ActionResult<ContributionType>(expectedBadRequestObjectResult);
64+
new ActionResult<ContributionType>(expectedInternalServerErrorObjectResult);
6465

6566
this.contributionTypeServiceMock.Setup(service =>
6667
service.RemoveContributionTypeByIdAsync(It.IsAny<Guid>()))
67-
.ThrowsAsync(validationException);
68+
.ThrowsAsync(serverException);
6869

6970
// when
7071
ActionResult<ContributionType> actualActionResult =
71-
await this.contributionTypesController.DeleteContributionTypeByIdAsync(someId);
72+
await this.contributionTypesController.DeleteContributionTypeByIdAsync(
73+
someContributionTypeId);
7274

7375
// then
7476
actualActionResult.ShouldBeEquivalentTo(expectedActionResult);
@@ -81,10 +83,10 @@ public async Task ShouldReturnInternalServerErrorOnDeleteIfServerErrorOccurredAs
8183
}
8284

8385
[Fact]
84-
public async Task ShouldReturnNotFoundOnDeleteIfItemDoesNotExistAsync()
86+
public async Task ShouldReturnNotFoundOnDeleteIfContributionTypeDoesNotExistAsync()
8587
{
8688
// given
87-
Guid someId = Guid.NewGuid();
89+
Guid someContributionTypeId = Guid.NewGuid();
8890
string someMessage = GetRandomString();
8991

9092
var notFoundContributionTypeException =
@@ -108,7 +110,8 @@ public async Task ShouldReturnNotFoundOnDeleteIfItemDoesNotExistAsync()
108110

109111
// when
110112
ActionResult<ContributionType> actualActionResult =
111-
await this.contributionTypesController.DeleteContributionTypeByIdAsync(someId);
113+
await this.contributionTypesController.DeleteContributionTypeByIdAsync(
114+
someContributionTypeId);
112115

113116
// then
114117
actualActionResult.ShouldBeEquivalentTo(expectedActionResult);
@@ -121,10 +124,10 @@ public async Task ShouldReturnNotFoundOnDeleteIfItemDoesNotExistAsync()
121124
}
122125

123126
[Fact]
124-
public async Task ShouldReturnLockedOnDeleteIfRecordIsLockedAsync()
127+
public async Task ShouldReturnLockedOnDeleteIfLockedContributionTypeExceptionOccursAsync()
125128
{
126129
// given
127-
Guid someId = Guid.NewGuid();
130+
Guid someContributionTypeId = Guid.NewGuid();
128131
var someInnerException = new Exception();
129132
string someMessage = GetRandomString();
130133
var someDictionaryData = GetRandomDictionaryData();
@@ -141,19 +144,20 @@ public async Task ShouldReturnLockedOnDeleteIfRecordIsLockedAsync()
141144
innerException: lockedContributionTypeException,
142145
data: someDictionaryData);
143146

144-
LockedObjectResult expectedConflictObjectResult =
147+
LockedObjectResult expectedLockedObjectResult =
145148
Locked(lockedContributionTypeException);
146149

147150
var expectedActionResult =
148-
new ActionResult<ContributionType>(expectedConflictObjectResult);
151+
new ActionResult<ContributionType>(expectedLockedObjectResult);
149152

150153
this.contributionTypeServiceMock.Setup(service =>
151154
service.RemoveContributionTypeByIdAsync(It.IsAny<Guid>()))
152155
.ThrowsAsync(contributionTypeDependencyValidationException);
153156

154157
// when
155158
ActionResult<ContributionType> actualActionResult =
156-
await this.contributionTypesController.DeleteContributionTypeByIdAsync(someId);
159+
await this.contributionTypesController.DeleteContributionTypeByIdAsync(
160+
someContributionTypeId);
157161

158162
// then
159163
actualActionResult.ShouldBeEquivalentTo(expectedActionResult);
@@ -166,40 +170,40 @@ public async Task ShouldReturnLockedOnDeleteIfRecordIsLockedAsync()
166170
}
167171

168172
[Fact]
169-
public async Task ShouldReturnFailedDependencyOnDeleteIfReferenceErrorOccursAsync()
173+
public async Task ShouldReturnFailedDependencyOnDeleteIfReferenceExceptionOccursAsync()
170174
{
171175
// given
172-
Guid someId = Guid.NewGuid();
176+
Guid someContributionTypeId = Guid.NewGuid();
173177
ContributionType someContributionType = CreateRandomContributionType();
174178
var someInnerException = new Exception();
175179
string someMessage = GetRandomString();
176180

177-
var invalidReferenceContributionTypeException =
181+
var invalidReferenceContributionTypeException =
178182
new InvalidReferenceContributionTypeException(
179183
message: someMessage,
180184
innerException: someInnerException,
181185
data: someInnerException.Data);
182186

183-
var contributionTypeDependencyValidationException =
187+
var contributionTypeDependencyValidationException =
184188
new ContributionTypeDependencyValidationException(
185189
message: someMessage,
186190
innerException: invalidReferenceContributionTypeException,
187191
data: invalidReferenceContributionTypeException.Data);
188192

189-
FailedDependencyObjectResult expectedConflictObjectResult =
190-
FailedDependency(invalidReferenceContributionTypeException);
191-
192-
var expectedActionResult =
193-
new ActionResult<ContributionType>(expectedConflictObjectResult);
193+
FailedDependencyObjectResult expectedFailedDependencyObjectResult =
194+
FailedDependency(invalidReferenceContributionTypeException);
194195

196+
var expectedActionResult =
197+
new ActionResult<ContributionType>(expectedFailedDependencyObjectResult);
195198

196199
this.contributionTypeServiceMock.Setup(service =>
197200
service.RemoveContributionTypeByIdAsync(It.IsAny<Guid>()))
198201
.ThrowsAsync(contributionTypeDependencyValidationException);
199202

200203
// when
201204
ActionResult<ContributionType> actualActionResult =
202-
await this.contributionTypesController.DeleteContributionTypeByIdAsync(someId);
205+
await this.contributionTypesController.DeleteContributionTypeByIdAsync(
206+
someContributionTypeId);
203207

204208
// then
205209
actualActionResult.ShouldBeEquivalentTo(expectedActionResult);

GitFyle.Core.Api.Tests.Unit/Controllers/ContributionTypes/ContributionTypesControllerTests.Exceptions.Post.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class ContributionTypesControllerTests
1818
{
1919
[Theory]
2020
[MemberData(nameof(ValidationExceptions))]
21-
public async Task ShouldReturnBadRequestOnDeleteIfValidationExceptionOccursAsync(
21+
public async Task ShouldReturnBadRequestOnPostIfValidationExceptionOccursAsync(
2222
Xeption validationException)
2323
{
2424
// given

0 commit comments

Comments
 (0)