-
Notifications
You must be signed in to change notification settings - Fork 0
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 #105 from infoshareacademy/feature/ja-110_students…
…-schedule-IsRemote Feature/ja 110 students schedule is remote
- Loading branch information
Showing
10 changed files
with
553 additions
and
41 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...utorLizard.BusinessLogic.Tests/Services/Student/StudentServiceScheduleItemRequestTests.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,77 @@ | ||
using Moq; | ||
using TutorLizard.BusinessLogic.Models; | ||
using TutorLizard.BusinessLogic.Models.DTOs.Requests; | ||
using TutorLizard.BusinessLogic.Services; | ||
|
||
namespace TutorLizard.BusinessLogic.Tests.Services.Student | ||
{ | ||
public class StudentServiceScheduleItemRequestTests : StudentServiceTestBase | ||
{ | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public async Task CreateScheduleItemRequest_ShouldSetIsRemoteCorrectly(bool isRemote) | ||
{ | ||
// Arrange | ||
var ad = new Ad | ||
{ | ||
Description = "Test Description", | ||
Location = "Test Location", | ||
Subject = "Test Subject", | ||
Title = "Test Title", | ||
TutorId = 2 | ||
}; | ||
var scheduleItem = new ScheduleItem { Id = 1, Ad = ad }; | ||
|
||
SetupMockGetScheduleItemById(scheduleItem); | ||
SetupMockGetAllScheduleItems(new List<ScheduleItem> { scheduleItem }); | ||
|
||
var request = new CreateScheduleItemRequestRequest | ||
{ | ||
StudentId = 3, | ||
ScheduleItemId = 1, | ||
IsRemote = isRemote | ||
}; | ||
|
||
MockScheduleItemRequestRepository | ||
.Setup(x => x.Create(It.Is<ScheduleItemRequest>(req => req.IsRemote == isRemote))) | ||
.Returns((ScheduleItemRequest req) => Task.FromResult(req)) | ||
.Verifiable(Times.Once); | ||
|
||
// Act | ||
await StudentService.CreateScheduleItemRequest(request); | ||
|
||
// Assert | ||
MockScheduleItemRequestRepository.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateScheduleItemRequest_WhenRequestSent_ShouldReturnSuccess() | ||
{ | ||
// Arrange | ||
var scheduleItem = new ScheduleItem { Id = 1 }; | ||
var studentId = 1; | ||
var isRemote = true; | ||
|
||
SetupMockGetScheduleItemById(scheduleItem); | ||
|
||
var request = new CreateScheduleItemRequestRequest | ||
{ | ||
StudentId = studentId, | ||
ScheduleItemId = scheduleItem.Id, | ||
IsRemote = isRemote | ||
}; | ||
|
||
// Act | ||
var response = await StudentService.CreateScheduleItemRequest(request); | ||
|
||
// Assert | ||
Assert.True(response.Success); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
Tests/TutorLizard.BusinessLogic.Tests/Services/Student/StudentServiceTestBase.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,55 @@ | ||
using AutoFixture; | ||
using Moq; | ||
using TutorLizard.BusinessLogic.Interfaces.Data.Repositories; | ||
using TutorLizard.BusinessLogic.Models; | ||
using TutorLizard.BusinessLogic.Services; | ||
|
||
namespace TutorLizard.BusinessLogic.Tests.Services.Student | ||
{ | ||
public class StudentServiceTestBase : TestsWithInMemoryDbBase | ||
{ | ||
protected StudentService StudentService; | ||
protected Fixture Fixture = new(); | ||
protected Mock<IDbRepository<Ad>> MockAdRepository = new(); | ||
protected Mock<IDbRepository<AdRequest>> MockAdRequestRepository = new(); | ||
protected Mock<IDbRepository<ScheduleItem>> MockScheduleItemRepository = new(); | ||
protected Mock<IDbRepository<ScheduleItemRequest>> MockScheduleItemRequestRepository = new(); | ||
|
||
|
||
protected StudentServiceTestBase() : base() | ||
{ | ||
StudentService = new StudentService(MockAdRepository.Object, | ||
MockAdRequestRepository.Object, | ||
MockScheduleItemRepository.Object, | ||
MockScheduleItemRequestRepository.Object); | ||
} | ||
|
||
protected void SetupMockGetScheduleItemById(ScheduleItem? scheduleItem) | ||
{ | ||
MockScheduleItemRepository | ||
.Setup(x => x.GetById(It.IsAny<int>())) | ||
.Returns(Task.FromResult(scheduleItem)); | ||
} | ||
|
||
protected void SetupMockGetAllScheduleItems(List<ScheduleItem> scheduleItems) | ||
{ | ||
var scheduleItemsInDb = AddEntitiesToInMemoryDb(scheduleItems); | ||
MockScheduleItemRepository | ||
.Setup(x => x.GetAll()) | ||
.Returns(scheduleItemsInDb); | ||
} | ||
|
||
protected IQueryable<TEntity> AddEntitiesToInMemoryDb<TEntity>(List<TEntity> entities) | ||
where TEntity : class | ||
{ | ||
DbContext | ||
.Set<TEntity>() | ||
.AddRange(entities); | ||
DbContext.SaveChanges(); | ||
|
||
return DbContext | ||
.Set<TEntity>() | ||
.AsQueryable(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.