Spaces:
Runtime error
Runtime error
Download tests/SCM.UnitTests/Projects/ProjectServiceTests.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.UnitTests/Projects/ProjectServiceTests.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/tests/SCM.UnitTests/Projects/ProjectServiceTests.cs
-
curl -L -o ProjectServiceTests.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.UnitTests/Projects/ProjectServiceTests.cs
2.02 kB
| using FluentAssertions; | |
| using NSubstitute; | |
| using SCM.Application.Common; | |
| using SCM.Application.Projects; | |
| using SCM.Application.Projects.Dtos; | |
| using SCM.Domain.Projects; | |
| using SCM.Shared.Exceptions; | |
| using Xunit; | |
| namespace SCM.UnitTests.Projects; | |
| public class ProjectServiceTests | |
| { | |
| private readonly IProjectRepository _repository = Substitute.For<IProjectRepository>(); | |
| private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>(); | |
| private readonly ProjectService _sut; | |
| public ProjectServiceTests() => _sut = new ProjectService(_repository, _unitOfWork); | |
| [] | |
| public async Task CreateAsync_DeveLancarConflict_QuandoCodigoJaExiste() | |
| { | |
| _repository.CodeExistsAsync("OBRA-001", null, Arg.Any<CancellationToken>()) | |
| .Returns(true); | |
| var act = () => _sut.CreateAsync( | |
| new CreateProjectRequest("OBRA-001", "Obra", null, DateTime.Today, null)); | |
| await act.Should().ThrowAsync<ConflictException>(); | |
| await _repository.DidNotReceive().AddAsync(Arg.Any<Project>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task CreateAsync_DevePersistirEmTransacao_QuandoValido() | |
| { | |
| _repository.CodeExistsAsync(Arg.Any<string>(), null, Arg.Any<CancellationToken>()) | |
| .Returns(false); | |
| var response = await _sut.CreateAsync( | |
| new CreateProjectRequest("OBRA-001", "Obra", null, DateTime.Today, null)); | |
| response.Code.Should().Be("OBRA-001"); | |
| _unitOfWork.Received(1).BeginTransaction(); | |
| _unitOfWork.Received(1).Commit(); | |
| await _repository.Received(1).AddAsync(Arg.Any<Project>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task GetByIdAsync_DeveLancarNotFound_QuandoInexistente() | |
| { | |
| _repository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()) | |
| .Returns((Project?)null); | |
| var act = () => _sut.GetByIdAsync(Guid.NewGuid()); | |
| await act.Should().ThrowAsync<NotFoundException>(); | |
| } | |
| } | |