Ejemplo n.º 1
0
        public void TestIsThisProductCodeAlreadyExist()
        {
            SavingsBookProduct savingsProduct = new SavingsBookProduct
            {
                Name             = "Good savings account",
                Code             = "P123",
                ClientType       = OpenCBS.Enums.OClientTypes.All,
                InitialAmountMin = 100,
                InitialAmountMax = 200,
                DepositMin       = 250,
                DepositMax       = 400,
                WithdrawingMin   = 400,
                WithdrawingMax   = 450,
                TransferMin      = 100,
                TransferMax      = 500,
                InterestRateMin  = 0.12,
                InterestRateMax  = 0.20,
                BalanceMin       = 1000,
                BalanceMax       = 2000,
                Currency         = new Currency {
                    Id = 1
                },
                InterestBase      = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfWeek
            };
            InstallmentType managementFeeFreq = new InstallmentType {
                Name = "Weekly", NbOfDays = 7, NbOfMonths = 0, Id = 1
            };

            savingsProduct.ManagementFeeFreq = managementFeeFreq;

            InstallmentType agioFeeFreq = new InstallmentType {
                Name = "Daily", NbOfDays = 1, NbOfMonths = 0
            };

            savingsProduct.AgioFeesFreq = agioFeeFreq;

            _savingProductManager = (SavingProductManager)container["SavingProductManager"];

            Assert.IsTrue(_savingProductManager.IsThisProductCodeAlreadyExist("P1"));
            Assert.IsFalse(_savingProductManager.IsThisProductCodeAlreadyExist(savingsProduct.Code));

            _savingProductManager.Add(savingsProduct);

            Assert.IsTrue(_savingProductManager.IsThisProductCodeAlreadyExist(savingsProduct.Code));
        }
        public bool ValidateProduct(ISavingProduct savingsProduct, int clientTypeCounter)
        {
            if (string.IsNullOrEmpty(savingsProduct.Name))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.NameIsEmpty);
            }

            if (string.IsNullOrEmpty(savingsProduct.Code))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CodeIsEmpty);
            }

            if (savingsProduct.Id == 0 && _savingProductManager.IsThisProductNameAlreadyExist(savingsProduct.Name))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DuplicateProductName);
            }

            if (savingsProduct.Id == 0 && _savingProductManager.IsThisProductCodeAlreadyExist(savingsProduct.Code))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.DuplicateProductCode);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.InitialAmountMin, savingsProduct.InitialAmountMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountIsInvalid);
            }

            if (savingsProduct.InitialAmountMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMinIsInvalid);
            }

            if (!ServicesHelper.CheckIfValueBetweenMinAndMax(savingsProduct.BalanceMin, savingsProduct.BalanceMax, savingsProduct.InitialAmountMin))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMinNotInBalance);
            }

            if (!ServicesHelper.CheckIfValueBetweenMinAndMax(savingsProduct.BalanceMin, savingsProduct.BalanceMax, savingsProduct.InitialAmountMax))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InitialAmountMaxNotInBalance);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.BalanceMin, savingsProduct.BalanceMax, null))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.BalanceIsInvalid);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.InterestRateMin, savingsProduct.InterestRateMax, savingsProduct.InterestRate))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateMinMaxIsInvalid);
            }

            if (savingsProduct.InterestRate.HasValue && savingsProduct.InterestRate < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateIsInvalid);
            }

            if (!savingsProduct.InterestRate.HasValue && savingsProduct.InterestRateMin < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.InterestRateMinIsInvalid);
            }

            if (savingsProduct.Currency == null)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CurrencyIsEmpty);
            }

            if (savingsProduct.Currency.Id == 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.CurrencyIsEmpty);
            }

            if (clientTypeCounter < 1)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.ClientTypeIsInvalid);
            }

            if (!ServicesHelper.CheckMinMaxAndValueCorrectlyFilled(savingsProduct.EntryFeesMin, savingsProduct.EntryFeesMax, savingsProduct.EntryFees))
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.EntryFeesMinMaxIsInvalid);
            }

            if (savingsProduct.EntryFees.HasValue && savingsProduct.EntryFees.Value < 0)
            {
                throw new OpenCbsSavingProductException(OpenCbsSavingProductExceptionEnum.EntryFeesIsInvalid);
            }

            if (savingsProduct is SavingsBookProduct)
            {
                ValidateSavingBookProduct((SavingsBookProduct)savingsProduct);
            }
            return(true);
        }