Esempio n. 1
0
        public async Task Metodo_CalcularJurosCompostosAsync_Deve_Retornar_Nao_Foi_Possivel_Calcular()
        {
            var input = new JurosCompostosInput()
            {
                Meses        = 5,
                ValorInicial = 100
            };

            var viewModel = new JurosCompostosViewModel()
            {
                Meses                   = 5,
                TaxaJuros               = 0.01m,
                ValorInicial            = 100,
                JurosCompostosCalculado = 105.10m
            };

            var jsonResult = new JsonResultBase <JurosCompostosViewModel>()
            {
                Data     = viewModel,
                Error    = false,
                Messages = null
            };

            var jurosCompostos = default(JurosCompostos);

            var jurosCompostosDomainServiceMock = new Mock <IJurosCompostosDomainService>();

            jurosCompostosDomainServiceMock.Setup(x => x.CalcularJurosCompostosAsync(jurosCompostos)).ReturnsAsync(jurosCompostos);

            var jurosCompostosAppService = new JurosCompostosAppService(jurosCompostosDomainServiceMock.Object);
            var result = await jurosCompostosAppService.CalcularJurosCompostosAsync(input);

            Assert.NotNull(result);
            Assert.True(result.Error);
        }
Esempio n. 2
0
        public async Task Metodo_GetAsync_Deve_Retornar_Juros_Calculado_Com_Status_Code_400()
        {
            var input = new JurosCompostosInput()
            {
                Meses        = 0,
                ValorInicial = 0
            };

            var viewModel = new JurosCompostosViewModel()
            {
                Meses                   = 5,
                TaxaJuros               = 0.01m,
                ValorInicial            = 100,
                JurosCompostosCalculado = 105.10m
            };

            var jsonResult = new JsonResultBase <JurosCompostosViewModel>()
            {
                Data     = viewModel,
                Error    = true,
                Messages = null
            };

            var appServiceMock = new Mock <IJurosCompostosAppService>();

            appServiceMock.Setup(x => x.CalcularJurosCompostosAsync(input)).ReturnsAsync(jsonResult);
            var controller = new JurosCompostosController(appServiceMock.Object);
            var resultado  = await controller.GetAsync(input);

            Assert.NotNull(resultado);
            var badRequestResult = resultado as BadRequestObjectResult;

            Assert.Equal(400, badRequestResult.StatusCode);
        }
        public async Task <JsonResultBase <JurosCompostosViewModel> > CalcularJurosCompostosAsync(JurosCompostosInput input)
        {
            var result = new JsonResultBase <JurosCompostosViewModel>();

            var validarParametros = ValidarParametrosJurosCompostos(input.ValorInicial, input.Meses);

            if (validarParametros.Any())
            {
                result.Data     = null;
                result.Error    = true;
                result.Messages = validarParametros;
                return(result);
            }

            var jurosCompostos = new JurosCompostos()
            {
                TaxaJuros    = 0,
                Meses        = input.Meses,
                ValorInicial = input.ValorInicial
            };

            var jurosCalculado = await _jurosCompostosDomainService.CalcularJurosCompostosAsync(jurosCompostos);

            if (jurosCalculado == null)
            {
                var errorMsg = new ValidationMessageBase()
                {
                    Message = "Não foi possível calcular o juros."
                };
                var listMsg = new List <ValidationMessageBase>();
                listMsg.Add(errorMsg);
                result.Data     = null;
                result.Error    = true;
                result.Messages = listMsg;
                return(result);
            }

            var data = new JurosCompostosViewModel()
            {
                ValorInicial            = input.ValorInicial,
                Meses                   = input.Meses,
                JurosCompostosCalculado = jurosCalculado.JurosCompostosCalculado,
                TaxaJuros               = jurosCalculado.TaxaJuros
            };

            result.Data  = data;
            result.Error = false;

            return(result);
        }
Esempio n. 4
0
        public async Task Metodo_CalcularJurosCompostosAsync_Deve_Retornar_Calculo_Com_Sucesso()
        {
            var input = new JurosCompostosInput()
            {
                Meses        = 5,
                ValorInicial = 100
            };

            var viewModel = new JurosCompostosViewModel()
            {
                Meses                   = 5,
                TaxaJuros               = 0.01m,
                ValorInicial            = 100,
                JurosCompostosCalculado = 105.10m
            };

            var jsonResult = new JsonResultBase <JurosCompostosViewModel>()
            {
                Data     = viewModel,
                Error    = false,
                Messages = null
            };

            var jurosCompostos = new JurosCompostos()
            {
                Meses        = 5,
                TaxaJuros    = 0,
                ValorInicial = 100
            };

            var jurosCompostosCalculado = new JurosCompostos()
            {
                Meses        = 5,
                TaxaJuros    = 0.01m,
                ValorInicial = 100
            };

            var jurosCompostosDomainServiceMock = new Mock <IJurosCompostosDomainService>();

            //jurosCompostosDomainServiceMock.Setup(x => x.ObterTaxaDeJurosApiOneAsync()).ReturnsAsync(0.01m);
            jurosCompostosDomainServiceMock.Setup(x => x.CalcularJurosCompostosAsync(jurosCompostos)).ReturnsAsync(jurosCompostosCalculado);

            var jurosCompostosAppService = new JurosCompostosAppService(jurosCompostosDomainServiceMock.Object);
            var result = await jurosCompostosAppService.CalcularJurosCompostosAsync(input);

            Assert.NotNull(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Executes action for result.
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            CaterpillarMvcHttpRequest mvcRequest = new CaterpillarMvcHttpRequest(context.RequestContext);
            bool isAjax = mvcRequest.IsAjaxRequest();

            HttpResponseBase response = context.HttpContext.Response;

            if (isAjax)
            {
                object errorId = context.Controller.ViewData["ErrorId"] ?? "0";
                object error   = context.Controller.ViewData["Error"] ?? string.Empty;

                DataType dataType = mvcRequest.GetResponseType();
                switch (dataType)
                {
                case DataType.Json:
                    response.Clear();
                    JsonResultBase jrb = new JsonResultBase();
                    jrb.ClientSideAction = ClientSideAction.ShowErrorMessage;
                    jrb.Error(errorId.ToString(), error.ToString());
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    string jsonString = serializer.Serialize(jrb);
                    response.Write(jsonString);
                    break;

                case DataType.Html:
                    if (isAjax)
                    {
                        //if (string.IsNullOrWhiteSpace(partialViewName))
                        //{
                        //    result = context.Controller.RenderMvcViewToString(null, "ErrorPartial.cshtml");
                        //}
                        //else
                        //{
                        //    result = PartialView(partialViewName, modelForUi);
                        //}
                    }
                    break;
                }
            }
            else
            {
                context.HttpContext.Response.Redirect(ApplicationFoundation.Settings.ErrorPageUrl, false);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Creates an ExceptionResult instance with specified System.Exception and client information.
 /// </summary>
 /// <param name="ex">Exception information for system.</param>
 /// /// <param name="clientData">client information to inform client.</param>
 public ExceptionResult(Exception ex, JsonResultBase clientOperation)
 {
     this.OccuredException = ex;
     this.ClientOperation  = clientOperation;
 }