Spaces:
Runtime error
Runtime error
Download tests/SCM.UnitTests/Controle/ItemControleServiceTests.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.UnitTests/Controle/ItemControleServiceTests.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/tests/SCM.UnitTests/Controle/ItemControleServiceTests.cs
-
curl -L -o ItemControleServiceTests.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.UnitTests/Controle/ItemControleServiceTests.cs
3.31 kB
| using FluentAssertions; | |
| using NSubstitute; | |
| using SCM.Application.Common; | |
| using SCM.Application.Controle; | |
| using SCM.Application.Controle.Dtos; | |
| using SCM.Domain.Controle; | |
| using SCM.Shared.Exceptions; | |
| using Xunit; | |
| namespace SCM.UnitTests.Controle; | |
| public class ItemControleServiceTests | |
| { | |
| private readonly IItemControleRepository _repository = Substitute.For<IItemControleRepository>(); | |
| private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>(); | |
| private readonly ItemControleService _sut; | |
| private static readonly Guid Obra = Guid.NewGuid(); | |
| public ItemControleServiceTests() | |
| { | |
| _sut = new ItemControleService(_repository, _unitOfWork); | |
| _repository.ObraExistsAsync(Obra, Arg.Any<CancellationToken>()).Returns(true); | |
| } | |
| [] | |
| public async Task CreateAsync_DeveLancarNotFound_QuandoObraNaoExiste() | |
| { | |
| var act = () => _sut.CreateAsync(new CreateItemControleRequest("IC-1", "Desc", Guid.NewGuid())); | |
| await act.Should().ThrowAsync<NotFoundException>(); | |
| await _repository.DidNotReceive().AddAsync(Arg.Any<ItemControle>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task CreateAsync_DeveLancarConflict_QuandoCodigoJaExisteNaObra() | |
| { | |
| _repository.CodigoExistsAsync("IC-1", Obra, null, Arg.Any<CancellationToken>()).Returns(true); | |
| var act = () => _sut.CreateAsync(new CreateItemControleRequest("IC-1", "Desc", Obra)); | |
| await act.Should().ThrowAsync<ConflictException>(); | |
| await _repository.DidNotReceive().AddAsync(Arg.Any<ItemControle>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task CreateAsync_DevePersistirEmTransacao_QuandoValido() | |
| { | |
| _repository.CodigoExistsAsync(Arg.Any<string>(), Obra, null, Arg.Any<CancellationToken>()).Returns(false); | |
| var response = await _sut.CreateAsync(new CreateItemControleRequest("IC-1", "Tubulação", Obra)); | |
| response.Codigo.Should().Be("IC-1"); | |
| _unitOfWork.Received(1).Commit(); | |
| await _repository.Received(1).AddAsync(Arg.Any<ItemControle>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task DeleteAsync_DeveLancarConflict_QuandoTemItensProgramados() | |
| { | |
| var id = Guid.NewGuid(); | |
| _repository.GetByIdAsync(id, Arg.Any<CancellationToken>()) | |
| .Returns(new ItemControle { Id = id, Codigo = "IC-1", Descricao = "Desc", ObraId = Obra }); | |
| _repository.ContarItensProgramadosAsync(id, Arg.Any<CancellationToken>()).Returns(5); | |
| var act = () => _sut.DeleteAsync(id); | |
| await act.Should().ThrowAsync<ConflictException>(); | |
| await _repository.DidNotReceive().DeleteAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()); | |
| } | |
| [] | |
| public async Task DeleteAsync_DeveExcluir_QuandoSemItensProgramados() | |
| { | |
| var id = Guid.NewGuid(); | |
| _repository.GetByIdAsync(id, Arg.Any<CancellationToken>()) | |
| .Returns(new ItemControle { Id = id, Codigo = "IC-1", Descricao = "Desc", ObraId = Obra }); | |
| _repository.ContarItensProgramadosAsync(id, Arg.Any<CancellationToken>()).Returns(0); | |
| await _sut.DeleteAsync(id); | |
| await _repository.Received(1).DeleteAsync(id, Arg.Any<CancellationToken>()); | |
| _unitOfWork.Received(1).Commit(); | |
| } | |
| } | |