-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hassanhabib/master
Merge from Original Repo
- Loading branch information
Showing
82 changed files
with
1,903 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...ces/StudentSemesterCourseServiceTests/StudentSemesterCourseServiceTests.Exceptions.Add.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
//--------------------------------------------------------------- | ||
// Copyright (c) Coalition of the Good-Hearted Engineers | ||
// FREE TO USE AS LONG AS SOFTWARE FUNDS ARE DONATED TO THE POOR | ||
//---------------------------------------------------------------- | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Moq; | ||
using OtripleS.Web.Api.Models.StudentSemesterCourses; | ||
using OtripleS.Web.Api.Models.StudentSemesterCourses.Exceptions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace OtripleS.Web.Api.Tests.Unit.Services.StudentSemesterCourseServiceTests | ||
{ | ||
public partial class StudentSemesterCourseServiceTests | ||
{ | ||
[Fact] | ||
public async Task ShouldThrowDependencyExceptionOnCreateWhenSqlExceptionOccursAndLogItAsync() | ||
{ | ||
// given | ||
DateTimeOffset dateTime = GetRandomDateTime(); | ||
StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(dateTime); | ||
StudentSemesterCourse inputStudentSemesterCourse = randomStudentSemesterCourse; | ||
inputStudentSemesterCourse.UpdatedBy = inputStudentSemesterCourse.CreatedBy; | ||
inputStudentSemesterCourse.UpdatedDate = inputStudentSemesterCourse.CreatedDate; | ||
var sqlException = GetSqlException(); | ||
|
||
var expectedStudentSemesterCourseDependencyException = | ||
new StudentSemesterCourseDependencyException(sqlException); | ||
|
||
this.dateTimeBrokerMock.Setup(broker => | ||
broker.GetCurrentDateTime()) | ||
.Returns(dateTime); | ||
|
||
this.storageBrokerMock.Setup(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse)) | ||
.ThrowsAsync(sqlException); | ||
|
||
// when | ||
ValueTask<StudentSemesterCourse> createStudentSemesterCourseTask = | ||
this.studentSemesterCourseService.CreateStudentSemesterCourseAsync(inputStudentSemesterCourse); | ||
|
||
// then | ||
await Assert.ThrowsAsync<StudentSemesterCourseDependencyException>(() => | ||
createStudentSemesterCourseTask.AsTask()); | ||
|
||
this.loggingBrokerMock.Verify(broker => | ||
broker.LogCritical(It.Is(SameExceptionAs(expectedStudentSemesterCourseDependencyException))), | ||
Times.Once); | ||
|
||
this.storageBrokerMock.Verify(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.Verify(broker => | ||
broker.GetCurrentDateTime(), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.VerifyNoOtherCalls(); | ||
this.loggingBrokerMock.VerifyNoOtherCalls(); | ||
this.storageBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldThrowDependencyExceptionOnCreateWhenDbExceptionOccursAndLogItAsync() | ||
{ | ||
// given | ||
DateTimeOffset dateTime = GetRandomDateTime(); | ||
StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(dateTime); | ||
StudentSemesterCourse inputStudentSemesterCourse = randomStudentSemesterCourse; | ||
inputStudentSemesterCourse.UpdatedBy = inputStudentSemesterCourse.CreatedBy; | ||
inputStudentSemesterCourse.UpdatedDate = inputStudentSemesterCourse.CreatedDate; | ||
var databaseUpdateException = new DbUpdateException(); | ||
|
||
var expectedStudentSemesterCourseDependencyException = | ||
new StudentSemesterCourseDependencyException(databaseUpdateException); | ||
|
||
this.dateTimeBrokerMock.Setup(broker => | ||
broker.GetCurrentDateTime()) | ||
.Returns(dateTime); | ||
|
||
this.storageBrokerMock.Setup(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse)) | ||
.ThrowsAsync(databaseUpdateException); | ||
|
||
// when | ||
ValueTask<StudentSemesterCourse> createStudentSemesterCourseTask = | ||
this.studentSemesterCourseService.CreateStudentSemesterCourseAsync(inputStudentSemesterCourse); | ||
|
||
// then | ||
await Assert.ThrowsAsync<StudentSemesterCourseDependencyException>(() => | ||
createStudentSemesterCourseTask.AsTask()); | ||
|
||
this.loggingBrokerMock.Verify(broker => | ||
broker.LogError(It.Is(SameExceptionAs(expectedStudentSemesterCourseDependencyException))), | ||
Times.Once); | ||
|
||
this.storageBrokerMock.Verify(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.Verify(broker => | ||
broker.GetCurrentDateTime(), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.VerifyNoOtherCalls(); | ||
this.loggingBrokerMock.VerifyNoOtherCalls(); | ||
this.storageBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldThrowServiceExceptionOnCreateWhenExceptionOccursAndLogItAsync() | ||
{ | ||
// given | ||
DateTimeOffset dateTime = GetRandomDateTime(); | ||
StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(dateTime); | ||
StudentSemesterCourse inputStudentSemesterCourse = randomStudentSemesterCourse; | ||
inputStudentSemesterCourse.UpdatedBy = inputStudentSemesterCourse.CreatedBy; | ||
inputStudentSemesterCourse.UpdatedDate = inputStudentSemesterCourse.CreatedDate; | ||
var exception = new Exception(); | ||
|
||
var expectedStudentSemesterCourseServiceException = | ||
new StudentSemesterCourseServiceException(exception); | ||
|
||
this.dateTimeBrokerMock.Setup(broker => | ||
broker.GetCurrentDateTime()) | ||
.Returns(dateTime); | ||
|
||
this.storageBrokerMock.Setup(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse)) | ||
.ThrowsAsync(exception); | ||
|
||
// when | ||
ValueTask<StudentSemesterCourse> createStudentSemesterCourseTask = | ||
this.studentSemesterCourseService.CreateStudentSemesterCourseAsync(inputStudentSemesterCourse); | ||
|
||
// then | ||
await Assert.ThrowsAsync<StudentSemesterCourseServiceException>(() => | ||
createStudentSemesterCourseTask.AsTask()); | ||
|
||
this.loggingBrokerMock.Verify(broker => | ||
broker.LogError(It.Is(SameExceptionAs(expectedStudentSemesterCourseServiceException))), | ||
Times.Once); | ||
|
||
this.storageBrokerMock.Verify(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.Verify(broker => | ||
broker.GetCurrentDateTime(), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.VerifyNoOtherCalls(); | ||
this.loggingBrokerMock.VerifyNoOtherCalls(); | ||
this.storageBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...nit/Services/StudentSemesterCourseServiceTests/StudentSemesterCourseServiceTests.Logic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//--------------------------------------------------------------- | ||
// Copyright (c) Coalition of the Good-Hearted Engineers | ||
// FREE TO USE AS LONG AS SOFTWARE FUNDS ARE DONATED TO THE POOR | ||
//---------------------------------------------------------------- | ||
|
||
using FluentAssertions; | ||
using Moq; | ||
using OtripleS.Web.Api.Models.StudentSemesterCourses; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace OtripleS.Web.Api.Tests.Unit.Services.StudentSemesterCourseServiceTests | ||
{ | ||
public partial class StudentSemesterCourseServiceTests | ||
{ | ||
[Fact] | ||
public async Task ShouldCreateStudentSemesterCourseAsync() | ||
{ | ||
// given | ||
DateTimeOffset randomDateTime = GetRandomDateTime(); | ||
DateTimeOffset dateTime = randomDateTime; | ||
StudentSemesterCourse randomSemesterCourse = CreateRandomStudentSemesterCourse(randomDateTime); | ||
randomSemesterCourse.UpdatedBy = randomSemesterCourse.CreatedBy; | ||
randomSemesterCourse.UpdatedDate = randomSemesterCourse.CreatedDate; | ||
StudentSemesterCourse inputStudentSemesterCourse = randomSemesterCourse; | ||
StudentSemesterCourse storageStudentSemesterCourse = randomSemesterCourse; | ||
StudentSemesterCourse expectedStudentSemesterCourse = storageStudentSemesterCourse; | ||
|
||
this.dateTimeBrokerMock.Setup(broker => | ||
broker.GetCurrentDateTime()) | ||
.Returns(dateTime); | ||
|
||
this.storageBrokerMock.Setup(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse)) | ||
.ReturnsAsync(storageStudentSemesterCourse); | ||
|
||
// when | ||
StudentSemesterCourse actualSemesterCourse = | ||
await this.studentSemesterCourseService.CreateStudentSemesterCourseAsync(inputStudentSemesterCourse); | ||
|
||
// then | ||
actualSemesterCourse.Should().BeEquivalentTo(expectedStudentSemesterCourse); | ||
|
||
// This is called within validation code | ||
this.dateTimeBrokerMock.Verify(broker => | ||
broker.GetCurrentDateTime(), | ||
Times.Once); | ||
|
||
this.storageBrokerMock.Verify(broker => | ||
broker.InsertStudentSemesterCourseAsync(inputStudentSemesterCourse), | ||
Times.Once); | ||
|
||
this.dateTimeBrokerMock.VerifyNoOtherCalls(); | ||
this.storageBrokerMock.VerifyNoOtherCalls(); | ||
this.storageBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
} | ||
} |
Oops, something went wrong.