Example #1
0
        public void SearchProductFinancial()
        {
            var option = new DbContextOptionsBuilder <appcontext>()
                         .UseInMemoryDatabase(databaseName: "SearchProductFinancial")
                         .Options;

            using (var context = new appcontext(option))
            {
                var productfinancial = new productfinancial();
                productfinancial.name = "Tesouro Direto";

                var productfinancialservice = new productfinancialservice(context);
                productfinancialservice.CreateProductFinancial(productfinancial);
            }

            using (var context = new appcontext(option))
            {
                var productfinancial = new productfinancial();
                productfinancial.name = "Tesouro Direto";

                var productfinancialservice        = new productfinancialservice(context);
                productfinancial productfinancials = productfinancialservice.SearchProductFinancial(productfinancial);

                Assert.Equal("Tesouro Direto", productfinancials.name);
                Assert.Equal(1, productfinancials.id);
            }
        }
        private bool ExistProductFinancial(productfinancial productfinancial)
        {
            try
            {
                bool productFinancialExist = _appcontext.productfinancials.Any(
                    a => a.name == productfinancial.name);

                return(productFinancialExist);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public productfinancial SearchProductFinancial(productfinancial productfinancial)
        {
            try
            {
                var resultProduct = _appcontext.productfinancials.FirstOrDefault(fp => fp.name == productfinancial.name);

                if (resultProduct.Equals(null))
                {
                    throw new ArgumentNullException("O produto financeiro informado não encontrado.");
                }

                return(resultProduct);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void CreateProductFinancial(productfinancial productfinancial)
        {
            try
            {
                this.ValidateArguments(productfinancial.name);

                if (this.ExistProductFinancial(productfinancial))
                {
                    throw new ArgumentException("Produto financeiro já existe no cadastro.");
                }

                _appcontext.productfinancials.Add(productfinancial);

                _appcontext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Realizar resgate de uma aplicação.
        /// </summary>
        /// <param name="client">cliente informado</param>
        /// <param name="productfinancial">produto financeiro informado</param>
        /// <param name="daterescue">data de resgate informado</param>
        public void Rescue(client client, productfinancial productfinancial, DateTime daterescue)
        {
            try
            {
                application applicationRescue;

                applicationRescue = new application
                {
                    idclient           = client.id,
                    client             = client,
                    idproductfinancial = productfinancial.id,
                    productfinancial   = productfinancial,
                    daterescue         = daterescue
                };

                _applicationservice.RescueApplication(applicationRescue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Realizar uma aplicação na carteira de investimento.
        /// </summary>
        /// <param name="client">cliente informado</param>
        /// <param name="productfinancial">produto financeiro informado</param>
        /// <param name="valueapplication">valor da aplicação informado</param>
        public void ToApply(client client, productfinancial productfinancial, decimal valueapplication)
        {
            try
            {
                application applicationToApply;

                applicationToApply = new application
                {
                    idclient           = client.id,
                    client             = client,
                    idproductfinancial = productfinancial.id,
                    productfinancial   = productfinancial,
                    dateapplication    = DateTime.Now,
                    valueapplication   = valueapplication
                };

                _applicationservice.CreateApplication(applicationToApply);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public void CreateProductFinancial()
        {
            var option = new DbContextOptionsBuilder <appcontext>()
                         .UseInMemoryDatabase(databaseName: "CreateProductFinancial")
                         .Options;

            using (var context = new appcontext(option))
            {
                var productfinancial = new productfinancial();
                productfinancial.name = "Tesouro Direto";
                productfinancial.percentageyieldyear = 10;

                var productfinancialservice = new productfinancialservice(context);
                productfinancialservice.CreateProductFinancial(productfinancial);
            }

            using (var context = new appcontext(option))
            {
                Assert.Equal(1, context.productfinancials.Count());
                Assert.Equal("Tesouro Direto", context.productfinancials.Single().name);
                Assert.Equal(10.0m, context.productfinancials.Single().percentageyieldyear);
                Assert.Equal(1, context.productfinancials.Single().id);
            }
        }