Example #1
0
        public ResponseBag <int> Create(EPatrimonio entity)
        {
            // Apply the validations rules to entity.
            var validations = _validationInsertFactory.Create();

            foreach (var validation in validations)
            {
                var result = validation.Validate(entity);
                if (!result.IsValid)
                {
                    return(new ResponseBag <int>
                    {
                        Ok = false,
                        Message = string.Join(", ", result.Errors)
                    });
                }
            }

            // Apply the business rules.
            var rules = _bizRulesInsertFactory.Create();

            foreach (var rule in rules)
            {
                rule.Apply(entity);
            }

            // Save the patrimônio in database.
            var affectedRows = _repository.Create(entity);

            return(new ResponseBag <int>
            {
                Ok = true,
                ObjectResponse = affectedRows
            });
        }
        public void Update_Put_AtualizaUmPatrimonio()
        {
            // Encontre um patrimônio por id
            Patrimonio testPatrimonio = MockPatrimonioRepository.GetById(1);

            // Altere os valores
            testPatrimonio.Nome = "Patrimônio 5";

            // Salve as alterações
            MockPatrimonioRepository.Create(testPatrimonio);

            // Verifique a mudança
            Assert.AreEqual("Patrimônio 5", MockPatrimonioRepository.GetById(1).Nome);
        }