Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DKymachynskyi committed Sep 17, 2023
1 parent 10ad49a commit 56ce243
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ public async Task GetById_WhenThereIsNoEntityWithId_ShouldReturnNull()
public async Task GetByProviderId_WhenThereIsNoEntityWithId_ShouldReturnEmptyList()
{
// Arrange
var emptyListWorkshopBaseCards = new List<WorkshopProviderViewCard>();
var emptyListWorkshopProviderViewCards = new List<WorkshopProviderViewCard>();
SetupGetRepositoryCount(0);
SetupGetByProviderById(new List<Workshop>(), new List<ChatRoomWorkshop>());
mapperMock.Setup(m => m.Map<List<WorkshopProviderViewCard>>(It.IsAny<List<Workshop>>()))
.Returns(emptyListWorkshopProviderViewCards);

// Act
var result = await workshopService.GetByProviderId(It.IsAny<Guid>(), It.IsAny<ExcludeIdFilter>()).ConfigureAwait(false);
Expand All @@ -215,24 +217,31 @@ public async Task GetByProviderId_WhenProviderWithIdExists_ShouldReturnEntitiesW
var numberOfWorkshops = 10;
var numberOfChatMessages = 5;
var directions = InstitutionHierarchyGenerator.Generate();
var workshops = WorkshopGenerator.Generate(numberOfWorkshops).WithProvider().WithApplications().WithInstitutionHierarchy(directions);
var workshops = WorkshopGenerator.Generate(numberOfWorkshops).WithProvider().WithApplications()
.WithInstitutionHierarchy(directions);
var workshopsProviderViewCards = mapper.Map<List<WorkshopProviderViewCard>>(workshops);

var chatrooms = new List<ChatRoomWorkshop>()
{
new ChatRoomWorkshop
{
Id = Guid.NewGuid(),
WorkshopId = workshops[1].Id,
WorkshopId = workshops[workshops.Count > 1 ? 1 : 0].Id,
},
};
var chatmessages = ChatMessagesGenerator.Generate(numberOfChatMessages).WithSenderRoleIsProvider(false)
.WithReadDateTime(null).WithChatRoom(chatrooms[0]);
chatmessages[chatmessages.Count > 1 ? 1 : 0].SenderRoleIsProvider = true;
chatrooms[0].ChatMessages = chatmessages;

var expectedUnreadMessages = workshops.Select(d => chatmessages.Count(m =>
m.ChatRoom.WorkshopId == d.Id &&
m.ReadDateTime == null &&
!m.SenderRoleIsProvider)).ToList();

mapperMock.Setup(m => m.Map<List<WorkshopProviderViewCard>>(It.IsAny<List<Workshop>>()))
.Returns(workshopsProviderViewCards);

SetupGetRepositoryCount(workshops.Count);
SetupGetByProviderById(workshops, chatrooms);

Expand Down

0 comments on commit 56ce243

Please sign in to comment.