Skip to content

Commit

Permalink
Merge pull request #119 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: unit test
  • Loading branch information
ychung-mot authored Apr 11, 2024
2 parents 06c45ba + f034452 commit 69efa2c
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions server/StrDss.Test/UserServiceShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,40 @@
using Xunit;
using StrDss.Model.OrganizationDtos;
using StrDss.Common;
using Microsoft.EntityFrameworkCore;
using StrDss.Data.Entities;

namespace StrDss.Test
{
public class UserServiceShould
{
[Theory]
[AutoDomainData]
public async Task CreateAccessRequestAsync_ValidDto_NoErrors(
AccessRequestCreateDto dto,
UserDto userDto,
OrganizationDto organizationDto,
[Frozen] Mock<IUserRepository> userRepoMock,
[Frozen] Mock<ICurrentUser> currentUserMock,
[Frozen] Mock<IUnitOfWork> unitOfWorkMock,
[Frozen] Mock<IOrganizationRepository> organizationRepoMock,
[Frozen] Mock<IEmailMessageService> emailServiceMock,
UserService sut)
{
// Arrange
SetupCurrentUser(currentUserMock);
SetupUserRepository(userRepoMock, (UserDto)null);
SetupUnitOfWork(unitOfWorkMock);
SetupOrganizationRepository(organizationRepoMock, organizationDto);

// Act
var result = await sut.CreateAccessRequestAsync(dto);

// Assert
Assert.Empty(result);
unitOfWorkMock.Verify(x => x.Commit(), Times.AtLeastOnce);
}
//[Theory]
//[AutoDomainData]
//public async Task CreateAccessRequestAsync_ValidDto_NoErrors(
// AccessRequestCreateDto dto,
// UserDto userDto,
// OrganizationDto organizationDto,
// [Frozen] Mock<IUserRepository> userRepoMock,
// [Frozen] Mock<ICurrentUser> currentUserMock,
// [Frozen] Mock<IUnitOfWork> unitOfWorkMock,
// [Frozen] Mock<IOrganizationRepository> organizationRepoMock,
// [Frozen] Mock<IEmailMessageService> emailServiceMock,
// [Frozen] Mock<DssDbContext> dbContextMock,
// UserService sut)
//{
// // Arrange
// SetupCurrentUser(currentUserMock);
// SetupUserRepository(userRepoMock, (UserDto)null);
// SetupUnitOfWork(unitOfWorkMock, dbContextMock);
// SetupOrganizationRepository(organizationRepoMock, organizationDto);

// // Act
// var result = await sut.CreateAccessRequestAsync(dto);

// // Assert
// Assert.Empty(result);
// unitOfWorkMock.Verify(x => x.Commit(), Times.AtLeastOnce);
//}

[Theory]
[AutoDomainData]
Expand Down Expand Up @@ -317,7 +320,7 @@ public void SetupUserRepository(Mock<IUserRepository> userRepoMock, UserDto user
userRepoMock.Setup(x => x.GetAdminUsers()).ReturnsAsync(new List<UserDto> { userDto });
}

public void SetupUnitOfWork(Mock<IUnitOfWork> unitOfWorkMock)
public void SetupUnitOfWork(Mock<IUnitOfWork> unitOfWorkMock, Mock<DssDbContext> dbContextMock)
{
unitOfWorkMock.Setup(x => x.Commit()).Verifiable();
}
Expand Down

0 comments on commit 69efa2c

Please sign in to comment.