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 unitOfWork = new(); Mock 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()), Times.Once); unitOfWork.Verify(u => u.SaveChangesAsync(), Times.Once); } } }