Skip to content

Commit

Permalink
fixed test buid error and added test GetApplications_WhenAreaAdminCal…
Browse files Browse the repository at this point in the history
…led_ShouldReturnApplications()
  • Loading branch information
min4uk committed Aug 23, 2023
1 parent 69aa91b commit e274bb1
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ApplicationServiceTests
private Mock<ICurrentUserService> currentUserServiceMock;
private Mock<IMinistryAdminService> ministryAdminServiceMock;
private Mock<IRegionAdminService> regionAdminServiceMock;
private Mock<IAreaAdminService> areaAdminServiceMock;
private Mock<ICodeficatorService> codeficatorServiceMock;

private Mock<IOptions<ApplicationsConstraintsConfig>> applicationsConstraintsConfig;
Expand All @@ -59,6 +60,7 @@ public void SetUp()
currentUserServiceMock = new Mock<ICurrentUserService>();
ministryAdminServiceMock = new Mock<IMinistryAdminService>();
regionAdminServiceMock = new Mock<IRegionAdminService>();
areaAdminServiceMock = new Mock<IAreaAdminService>();
codeficatorServiceMock = new Mock<ICodeficatorService>();

logger = new Mock<ILogger<ApplicationService>>();
Expand All @@ -85,6 +87,7 @@ public void SetUp()
currentUserServiceMock.Object,
ministryAdminServiceMock.Object,
regionAdminServiceMock.Object,
areaAdminServiceMock.Object,
codeficatorServiceMock.Object);
}

Expand Down Expand Up @@ -184,6 +187,47 @@ public async Task GetApplications_WhenRegionAdminCalled_ShouldReturnApplications
Assert.That(result.Entities.FirstOrDefault().Workshop.InstitutionId, Is.EqualTo(institutionId));
}

[Test]
public async Task GetApplications_WhenAreaAdminCalled_ShouldReturnApplications()
{
// Arrange
var institutionId = new Guid("b929a4cd-ee3d-4bad-b2f0-d40aedf656c4");
long catottgId = 31737;
var applications = WithApplicationsList();
SetupGetAllByInstitutionId(applications);

currentUserServiceMock.Setup(c => c.IsAdmin()).Returns(true);
currentUserServiceMock.Setup(c => c.IsMinistryAdmin()).Returns(false);
currentUserServiceMock.Setup(c => c.IsRegionAdmin()).Returns(false);
currentUserServiceMock.Setup(c => c.IsAreaAdmin()).Returns(true);
areaAdminServiceMock
.Setup(m => m.GetByUserId(It.IsAny<string>()))
.Returns(Task.FromResult<AreaAdminDto>(new AreaAdminDto()
{
InstitutionId = institutionId,
CATOTTGId = catottgId,
}));

currentUserServiceMock.Setup(c => c.IsAreaAdmin()).Returns(true);
areaAdminServiceMock
.Setup(m => m.GetByUserId(It.IsAny<string>()))
.Returns(Task.FromResult<AreaAdminDto>(new AreaAdminDto()
{
InstitutionId = institutionId,
}));

codeficatorServiceMock
.Setup(x => x.GetAllChildrenIdsByParentIdAsync(It.IsAny<long>()))
.Returns(Task.FromResult((IEnumerable<long>)new List<long> { catottgId }));

// Act
var result = await service.GetAll(new ApplicationFilter());

// Assert
Assert.That(result.Entities.Count, Is.EqualTo(1));
Assert.That(result.Entities.FirstOrDefault().Workshop.InstitutionId, Is.EqualTo(institutionId));
}

[Test]
public async Task GetApplicationById_WhenIdIsValid_ShouldReturnApplication()
{
Expand Down

0 comments on commit e274bb1

Please sign in to comment.