Пример #1
0
        public void should_not_fail_if_expression_returns_direct_value()
        {
            var ex = new DomainException(() => 3712 );

            ex.ErrorCode.ShouldEqual(3712);
            ex.Message.ShouldEqual(string.Empty);
        }
Пример #2
0
        public void should_not_fail_if_attribute_is_not_defined()
        {
            var ex = new DomainException(() => FakeErrorCode.AnotherAnotherErrorValue);

            ex.ErrorCode.ShouldEqual(FakeErrorCode.AnotherAnotherErrorValue);
            ex.Message.ShouldEqual(string.Empty);
        }
Пример #3
0
        public void should_not_fail_if_expression_returns_constant()
        {
            var ex = new DomainException(() => FakeErrorCode.ContantErrorValue );

            ex.ErrorCode.ShouldEqual(FakeErrorCode.ContantErrorValue);
            ex.Message.ShouldEqual(string.Empty);
        }
Пример #4
0
        public void should_obtain_error_message_via_attribute_with_formatted_parameter()
        {
            var ex = new DomainException(() => FakeErrorCode.AnotherErrorValue, "formatted param");

            ex.ErrorCode.ShouldEqual(FakeErrorCode.AnotherErrorValue);
            ex.Message.ShouldEqual("This is a fake error message with a formatted parameter formatted param");
        }
Пример #5
0
        public void should_obtain_error_message_via_attribute()
        {
            var ex = new DomainException(() => FakeErrorCode.SomeErrorValue);

            ex.ErrorCode.ShouldEqual(FakeErrorCode.SomeErrorValue);
            ex.Message.ShouldEqual("This is a fake error message");
        }
Пример #6
0
        private void ValidateAndSetProperties(string quaNome, string quaEndereco, int quaNumero, string quaBairro)
        {
            DomainException.When(string.IsNullOrEmpty(quaNome), "Nome da Quadra não informado.");
            DomainException.When(string.IsNullOrEmpty(quaEndereco), "Endereço da Quadra não informado.");
            DomainException.When(string.IsNullOrEmpty(quaBairro), "Bairro da Quadra não informado.");

            this.quaNome     = quaNome;
            this.quaEndereco = quaEndereco;
            this.quaNumero   = quaNumero;
            this.quaBairro   = quaBairro;
        }
Пример #7
0
        public static DomainException NotEqual(this object objRef, object objComp, string message)
        {
            DomainException exception = null;

            if (objRef == objComp)
            {
                exception = new DomainException(message);
            }

            return(exception);
        }
Пример #8
0
        public static DomainException NotNull(this object objRef, string message)
        {
            DomainException exception = null;

            if (objRef == null)
            {
                exception = new DomainException(message);
            }

            return(exception);
        }
        protected virtual JsonResult DomainException(DomainException exception)
        {
            string msg = ObterMensagem(exception.ExceptionItemInfo);

            Debug.WriteLine($"{exception.ExceptionItemInfo.Model}.{exception.ExceptionItemInfo.Reference}: {msg}");

            var error  = new Error(exception.ExceptionItemInfo.Model, msg);
            var result = new Result(error);

            return(new JsonResult(result));
        }
Пример #10
0
 public static void WithMessage(this DomainException exception, string message)
 {
     if (exception.ListOfRules.Contains(message))
     {
         Assert.True(true);
     }
     else
     {
         Assert.False(true, $"Expected message {message}");
     }
 }
Пример #11
0
 private static ErrorResponse ExtractErrorResponseFromContext(ExceptionContext context)
 {
     return(context.Exception switch
     {
         AutoMapperMappingException mappingException => mappingException.CreateErrorResponse(),
         DomainException domainException => domainException.CreateErrorResponse(),
         BusinessException businessException => businessException.CreateErrorResponse(),
         AuthorizationConfigException authorizationConfigException => authorizationConfigException.CreateErrorResponse(),
         UnauthorizedAccessException unauthorizedAccessException => unauthorizedAccessException.CreateErrorResponse(),
         _ => context.Exception.CreateErrorResponse()
     });
 public ExceptionResponse Map(Exception exception)
 {
     return(exception switch
     {
         DomainException ex => new ExceptionResponse(new { code = ex.Code, reason = ex.Message },
                                                     HttpStatusCode.BadRequest),
         AppException ex => new ExceptionResponse(new { code = ex.Code, reason = ex.Message },
                                                  HttpStatusCode.BadRequest),
         _ => new ExceptionResponse(new { code = "error", reason = "We obtained a problem, try again later." },
                                    HttpStatusCode.BadRequest)
     });
Пример #13
0
 private static void CheckPropyt(Empresa empresa, string descricao, string codigobanco, string agencia, string conta, string gerente, string telefone, string dataabertura)
 {
     DomainException.When(empresa == null, "Empresa Obrigatorio");
     DomainException.When(string.IsNullOrEmpty(descricao), "Descrição Obrigatoria");
     DomainException.When(string.IsNullOrEmpty(codigobanco), "Codigo do Banco Obrigatorio");
     DomainException.When(string.IsNullOrEmpty(agencia), "Agenci Obrigatorioa");
     DomainException.When(string.IsNullOrEmpty(conta), "Conta Bancaria Obrigatorio");
     DomainException.When(string.IsNullOrEmpty(gerente), "Gerente Obrigatorio");
     DomainException.When(string.IsNullOrEmpty(telefone), "Telefone Obrigatorio");
     DomainException.When(string.IsNullOrEmpty(dataabertura), "Data de Abertura Obrigatorio");
 }
Пример #14
0
        public void ValidateNameAndSetName(int?id, string name)
        {
            DomainException.When(string.IsNullOrEmpty(name), "Nome é obrigatório");

            if (id.HasValue && id > 0)
            {
                Id = id.Value;
            }

            Name = name;
        }
Пример #15
0
        private void ValidateAndSetProperties(int atlCodigo, decimal conValorPago, DateTime conDataPagto, int conMesReferencia)
        {
            DomainException.When(atlCodigo == 0, "Atleta não informado.");
            DomainException.When(conValorPago == 0, "Valor Pago não informado.");
            DomainException.When(conDataPagto == DateTime.MinValue, "Descrição não informada.");
            DomainException.When(conMesReferencia == 0, "Mês de Referência não informado.");

            this.atlCodigo        = atlCodigo;
            this.conValorPago     = conValorPago;
            this.conDataPagto     = conDataPagto;
            this.conMesReferencia = conMesReferencia;
        }
Пример #16
0
        private void ValidacaoValoresSetPropriedades(string modeloCarro, DateTime horarioSaida, Evento evento, Funcionario funcionario)
        {
            DomainException.Quando(string.IsNullOrEmpty(modeloCarro), "Modelo do Carro Digitado Invalido");
            DomainException.Quando(evento == null, "Orçamento não foi completado corretamente");
            DomainException.Quando(funcionario == null, "Orçamento não foi completado corretamente");
            //tratar data


            COD_EVENTO     = evento;
            CAR_NUM_MODELO = modeloCarro;
            HORA_SAIDA_CAR = horarioSaida;
        }
Пример #17
0
        private void ValidateAndSetProperties(int IDCompany, int IDUser, int IDProduto, int Qtde)
        {
            DomainException.When(IDCompany == 0, "Compania não informada.");
            DomainException.When(IDUser == 0, "Usuário não informado.");
            DomainException.When(IDProduto == 0, "Produto não informado.");
            DomainException.When(Qtde < 0, "Qtde não pode ser negativa.");

            this.IDCompany = IDCompany;
            this.IDUser    = IDUser;
            this.IDProduto = IDProduto;
            this.Qtde      = Qtde;
        }
Пример #18
0
 /// <summary>
 /// Initializes a new <see cref="V1CorrelationCondition"/>
 /// </summary>
 public V1CorrelationCondition(params V1EventFilter[] filters)
 {
     if (filters == null)
     {
         throw DomainException.ArgumentNull(nameof(filters));
     }
     if (!filters.Any())
     {
         throw DomainException.ArgumentMustHaveMinimumLengthOf(nameof(filters), 1);
     }
     this._Filters = filters.ToList();
 }
 /// <summary>
 /// Faults the <see cref="V1WorkflowActivity"/>
 /// </summary>
 /// <param name="error">The unhandled <see cref="Error"/> that caused the <see cref="V1WorkflowActivity"/> to end prematurily</param>
 public virtual void Fault(Neuroglia.Error error)
 {
     if (error == null)
     {
         throw DomainException.ArgumentNull(nameof(error));
     }
     if (this.Status >= V1WorkflowActivityStatus.Faulted)
     {
         throw DomainException.UnexpectedState(typeof(V1WorkflowActivity), this.Id, this.Status);
     }
     this.On(this.RegisterEvent(new V1WorkflowActivityFaultedDomainEvent(this.Id, error)));
 }
Пример #20
0
 private void SendCommand <TCommand>(TCommand command)
     where TCommand : ICommand
 {
     try
     {
         this.CommandBus.Send(command);
     }
     catch (DomainException ex)
     {
         this.CatchedException = ex;
     }
 }
        public void the_domain_exception_raised_is_the_original_one()
        {
            var mocks = new MockRepository();
            var actor = mocks.StrictMock<Actor>();
            var scenario = mocks.StrictMock<Scenario>();
            var exception = new DomainException("error");

            Rhino.Mocks.Expect
                .Call(scenario.Authorize(actor))
                .Throw(exception);

            mocks.ReplayAll();

            try
            {
                UseCase.Execute(scenario, actor);
            }
            catch (DomainException exc)
            {
                Expect(exc, Is.EqualTo(exception));
            }
        }
Пример #22
0
        public void should_not_fail_if_enum_attribute_is_not_defined()
        {
            var ex = new DomainException(FakeEnumErrorCode.YetAnotherErrorValue);

            ex.ErrorCode.ShouldEqual((int)FakeEnumErrorCode.YetAnotherErrorValue);
            ex.Message.ShouldEqual(string.Empty);
        }