38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|||
|
using Moq;
|
|||
|
using UserManager.Application.Features.Users.Requests;
|
|||
|
using UserManager.Application.Interfaces;
|
|||
|
using UserManager.Application.Features.Users.Services;
|
|||
|
using UserManager.Application.Features.Users.Responses;
|
|||
|
using UserManager.Domain.Entities;
|
|||
|
|
|||
|
namespace UserManager.Application.UnitTests.Features.Users
|
|||
|
{
|
|||
|
[TestClass]
|
|||
|
public class UserServiceUnitTests
|
|||
|
{
|
|||
|
[TestMethod]
|
|||
|
public async Task CreateUserAsync_ShouldCallAddAndSave_WhenCreateUserCalled()
|
|||
|
{
|
|||
|
// Arrange
|
|||
|
Mock<IUnitOfWork> unitOfWork = new();
|
|||
|
Mock<IUserRepository> userRepository = new();
|
|||
|
unitOfWork.SetupGet(u => u.UserRepository).Returns(userRepository.Object);
|
|||
|
var request = new CreateUserRequestDto()
|
|||
|
{
|
|||
|
FirstName = "John",
|
|||
|
LastName = "Doe",
|
|||
|
};
|
|||
|
|
|||
|
UserService userService = new(unitOfWork.Object);
|
|||
|
|
|||
|
// Act
|
|||
|
CreateUserResponseDto responseDto = await userService.CreateUserAsync(request);
|
|||
|
|
|||
|
// Assert
|
|||
|
unitOfWork.Verify(u => u.UserRepository.CreateAsync(It.IsAny<User>()), Times.Once);
|
|||
|
unitOfWork.Verify(u => u.SaveChangesAsync(), Times.Once);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|