Skip to content

Commit

Permalink
Tsylia / Refactoring WorkshopDTOs (#1231)
Browse files Browse the repository at this point in the history
* Refactored WorkshopDTO: splitted into different DTOs. Also refactored WorkshopCard, WorkshopResult and WorkshopResponse. Fixed the referencies, mapping profiles, tests.

* Created the several test data generators for the workshops dtos. Fixed the tests.

* Added the additional test data generators. The process of the creating test data for nested classes was changed.
  • Loading branch information
andriitsylia authored Sep 18, 2023
1 parent dff205f commit da4e4cf
Show file tree
Hide file tree
Showing 73 changed files with 696 additions and 756 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Models.Application;
using OutOfSchool.WebApi.Models.Workshop;
using OutOfSchool.WebApi.Models.Workshops;
using OutOfSchool.WebApi.Models.Providers;
using OutOfSchool.WebApi.Services;
using OutOfSchool.WebApi.Models.SocialGroup;
Expand All @@ -42,7 +42,7 @@ public class ApplicationControllerTests
private IEnumerable<WorkshopCard> workshops;
private ParentDTO parent;
private ProviderDto provider;
private WorkshopDTO workshopDto;
private WorkshopV2Dto workshopDto;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -290,7 +290,7 @@ public async Task GetByWorkshopId_WhenProviderHasNoApplications_ShouldReturnNoCo
var filter = new ApplicationFilter ();

var newProvider = new ProviderDto { Id = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666"), UserId = userId };
var newWorkshop = new WorkshopDTO { Id = new Guid("94b81fa7-180f-4965-8aac-908a9f3ecb8d"), ProviderId = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666") };
var newWorkshop = new WorkshopDto { Id = new Guid("94b81fa7-180f-4965-8aac-908a9f3ecb8d"), ProviderId = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666") };

httpContext.Setup(c => c.User.IsInRole("provider")).Returns(true);

Expand Down Expand Up @@ -320,7 +320,7 @@ public async Task GetByProviderId_WhenProviderHasNoApplications_ShouldReturnNoCo
var filter = new ApplicationFilter ();

var newProvider = new ProviderDto { Id = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666"), UserId = userId };
var newWorkshop = new WorkshopDTO { Id = new Guid("94b81fa7-180f-4965-8aac-908a9f3ecb8d"), ProviderId = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666") };
var newWorkshop = new WorkshopDto { Id = new Guid("94b81fa7-180f-4965-8aac-908a9f3ecb8d"), ProviderId = new Guid("83caa2e6-902a-43b5-9744-8a9d66604666") };

httpContext.Setup(c => c.User.IsInRole("provider")).Returns(true);

Expand Down Expand Up @@ -351,7 +351,7 @@ public void GetByWorkshopId_WhenProviderHasNoRights_ShouldThrowUnauthorizedAcces

httpContext.Setup(c => c.User.IsInRole("provider")).Returns(true);

workshopService.Setup(s => s.GetById(id)).ReturnsAsync(new WorkshopDTO());
workshopService.Setup(s => s.GetById(id)).ReturnsAsync(new WorkshopDto());
applicationService.Setup(s => s.GetAllByWorkshop(id, It.IsAny<Guid>(), filter))
.ThrowsAsync(new UnauthorizedAccessException());

Expand Down Expand Up @@ -484,7 +484,7 @@ public async Task UpdateApplication_WhenModelIsValid_ShouldReturnOkObjectResult(
};

applicationService.Setup(s => s.Update(It.IsAny<ApplicationUpdate>(), It.IsAny<Guid>())).ReturnsAsync(Result<ApplicationDto>.Success(applications.First()));
workshopService.Setup(s => s.GetById(It.IsAny<Guid>())).ReturnsAsync(new WorkshopDTO());
workshopService.Setup(s => s.GetById(It.IsAny<Guid>())).ReturnsAsync(new WorkshopDto());

// Act
var result = await controller.Update(shortApplication).ConfigureAwait(false);
Expand Down Expand Up @@ -527,7 +527,7 @@ public void UpdateApplication_WhenUserHasNoRights_ShouldThrowUnauthorizedAccess(

applicationService.Setup(s => s.Update(shortApplication, It.IsAny<Guid>()))
.ThrowsAsync(new UnauthorizedAccessException());
workshopService.Setup(s => s.GetById(shortApplication.WorkshopId)).ReturnsAsync(new WorkshopDTO());
workshopService.Setup(s => s.GetById(shortApplication.WorkshopId)).ReturnsAsync(new WorkshopDto());

// Act & Assert
Assert.ThrowsAsync<UnauthorizedAccessException>(async () => await controller.Update(shortApplication));
Expand All @@ -553,9 +553,9 @@ public async Task UpdateApplication_WhenThereIsNoApplicationWithId_ShouldReturnB
Assert.That(result, Is.InstanceOf<BadRequestObjectResult>());
}

private WorkshopDTO FakeWorkshop()
private WorkshopV2Dto FakeWorkshop()
{
return new WorkshopDTO()
return new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title6",
Expand Down Expand Up @@ -617,11 +617,11 @@ private WorkshopDTO FakeWorkshop()
};
}

private List<WorkshopDTO> FakeWorkshops()
private List<WorkshopV2Dto> FakeWorkshops()
{
return new List<WorkshopDTO>()
return new List<WorkshopV2Dto>()
{
new WorkshopDTO()
new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title1",
Expand Down Expand Up @@ -649,7 +649,7 @@ private List<WorkshopDTO> FakeWorkshops()
CATOTTGId = 4970,
},
},
new WorkshopDTO()
new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title2",
Expand All @@ -676,7 +676,7 @@ private List<WorkshopDTO> FakeWorkshops()
CATOTTGId = 4970,
},
},
new WorkshopDTO()
new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title3",
Expand All @@ -701,7 +701,7 @@ private List<WorkshopDTO> FakeWorkshops()
CoverImageId = "image3",
InstitutionHierarchyId = new Guid("af475193-6a1e-4a75-9ba3-439c4300f771"),
},
new WorkshopDTO()
new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title4",
Expand All @@ -725,7 +725,7 @@ private List<WorkshopDTO> FakeWorkshops()
CoverImageId = "image4",
InstitutionHierarchyId = new Guid("af475193-6a1e-4a75-9ba3-439c4300f771"),
},
new WorkshopDTO()
new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using OutOfSchool.WebApi.Models.Application;
using OutOfSchool.WebApi.Models.Providers;
using OutOfSchool.WebApi.Models.SocialGroup;
using OutOfSchool.WebApi.Models.Workshop;
using OutOfSchool.WebApi.Models.Workshops;
using OutOfSchool.WebApi.Services;

namespace OutOfSchool.WebApi.Tests.Controllers;
Expand Down Expand Up @@ -246,7 +246,7 @@ public async Task GetApprovedByWorkshopId_WhenThereAreChildren_ShouldReturnOkRes
{
// Arrange
ChildDto child = children.First();
WorkshopDTO existingWorkshop = new WorkshopDTO()
WorkshopV2Dto existingWorkshop = new WorkshopV2Dto()
{
Id = Guid.NewGuid(),
Title = "Title1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using OutOfSchool.WebApi.Controllers.V1;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Models.Application;
using OutOfSchool.WebApi.Models.Workshop;
using OutOfSchool.WebApi.Models.Workshops;
using OutOfSchool.WebApi.Services;
using OutOfSchool.WebApi.Util;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using OutOfSchool.Services.Enums;
using OutOfSchool.WebApi.Controllers.V1;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Models.Workshop;
using OutOfSchool.WebApi.Models.Workshops;
using OutOfSchool.WebApi.Services;

namespace OutOfSchool.WebApi.Tests.Controllers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OutOfSchool.Services.Models;
using OutOfSchool.WebApi.Controllers.V1;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Models.Workshops;
using OutOfSchool.WebApi.Services;
using Range = Moq.Range;

Expand Down
Loading

0 comments on commit da4e4cf

Please sign in to comment.