public async Task Inserir_Cargo_Invalido(string descricao)
        {
            var builder = new CargoBuilder().WithDescricao(descricao);
            var entity  = builder.Build();
            var dto     = builder.BuildDto();

            await _armazenadorDeCargo.Armazenar(dto);

            _cargoRepositoryMock.Verify(r => r.Add(entity), Times.Never);
            Assert.True(_notificationContext.HasNotifications);
            entity.ValidationResult.Errors.Should().HaveCount(1);
        }
        public async Task Inserir_Cargo_Valido()
        {
            var builder = new CargoBuilder();
            var entity  = builder.Build();
            var dto     = builder.BuildDto();

            await _armazenadorDeCargo.Armazenar(dto);

            _cargoRepositoryMock.Verify(r =>
                                        r.Add(It.Is <Cargo>(cargo => cargo.Descricao == dto.Descricao)),
                                        Times.Once);
            Assert.False(_notificationContext.HasNotifications);
        }
Beispiel #3
0
        public async Task Deletar_Cargo_Existente()
        {
            var builder = new CargoBuilder().WithId(1);
            var entity  = builder.Build();

            _cargoRepositoryMock
            .Setup(c => c.GetWithIncludes(It.IsAny <Predicate <Cargo> >()))
            .ReturnsAsync(new List <Cargo> {
                entity
            });

            await _exclusaoDeCargo.Excluir(1);

            _cargoRepositoryMock.Verify(r => r.Delete(1), Times.Once);
            Assert.False(_notificationContext.HasNotifications);
        }
        public async Task Alterar_Cargo_Inexistente()
        {
            var builder = new CargoBuilder().WithId(10);
            var entity  = builder.Build();
            var dto     = builder.BuildDto();

            _cargoRepositoryMock
            .Setup(c => c.Get(It.IsAny <Predicate <Cargo> >()))
            .ReturnsAsync(new List <Cargo> {
            });

            await _armazenadorDeCargo.Armazenar(dto);

            _cargoRepositoryMock.Verify(r => r.Update(entity), Times.Never);
            Assert.True(_notificationContext.HasNotifications);
            _notificationContext.Notifications.Should().HaveCount(1);
        }
        public async Task Alterar_Cargo_Sucesso()
        {
            var builder         = new CargoBuilder().WithId(1);
            var entityAlteracao = builder.Build();
            var dto             = builder.BuildDto();

            _cargoRepositoryMock
            .Setup(c => c.Get(It.IsAny <Predicate <Cargo> >()))
            .ReturnsAsync(new List <Cargo> {
                entityAlteracao
            });

            await _armazenadorDeCargo.Armazenar(dto);

            _cargoRepositoryMock.Verify(r => r.Update(entityAlteracao), Times.Once);
            Assert.False(_notificationContext.HasNotifications);
        }
Beispiel #6
0
        public async Task Deletar_Cargo_Funcionarios_Vinculados()
        {
            var builder = new CargoBuilder()
                          .WithId(1)
                          .WithFuncionarios(3);

            var cargo = builder.Build();

            _cargoRepositoryMock
            .Setup(c => c.GetWithIncludes(It.IsAny <Predicate <Cargo> >()))
            .ReturnsAsync(new List <Cargo> {
                cargo
            });

            await _exclusaoDeCargo.Excluir(1);

            Assert.True(_notificationContext.HasNotifications);
            Assert.Contains(_notificationContext.Notifications,
                            n => n.Key.Equals("CargoComFuncionariosVinculados"));

            _cargoRepositoryMock.Verify(r => r.Delete(1), Times.Never);
        }