public void TestSaving_When_Product_IsNull() { SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null) { InterestRate = 0.15 }; _savingServices = new SavingServices(null, null, new User { Id = 6 }); try { _savingServices.SaveContract(saving, new Person { Id = 6 }); Assert.Fail("Saving Contract shouldn't pass validation test before save (Product is Null)."); } catch (OpenCbsSavingException exception) { Assert.AreEqual(exception.Code, OpenCbsSavingExceptionEnum.ProductIsInvalid); } }
public void TestSaving_When_InitialAmount_IsNull() { Assert.Ignore(); SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User()) { CreationDate = TimeProvider.Today, InterestRate = 0.13, Product = _savingsProduct }; _savingServices = new SavingServices(null, null, new User { Id = 6 }); try { _savingServices.SaveContract(saving, new Person { Id = 6 }); saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller); Assert.Fail("Saving Contract shouldn't pass validation test before save (Initial Amount is Null)."); } catch (OpenCbsSavingException exception) { Assert.AreEqual(exception.Code, OpenCbsSavingExceptionEnum.EntryFeesIsInvalid); } }
public void TestSaving_RateWithdrawFees() { Assert.Ignore(); _savingsProduct.WithdrawFeesType = OSavingsFeesType.Rate; _savingsProduct.RateWithdrawFeesMin = 0.01; _savingsProduct.RateWithdrawFeesMax = 0.05; SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User { Id = 6 }, TimeProvider.Today, _savingsProduct, null) { InterestRate = 0.15, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6, ManagementFees = 7, AgioFees = 8 }; Client client = new Person { Id = 6, LastName = "El Fanidi" }; _savingManagerMock = new DynamicMock(typeof(SavingManager)); _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager)); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6); _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, null); _savingServices = new SavingServices((SavingManager)_savingManagerMock.MockInstance, (SavingEventManager)_savingEventManagerMock.MockInstance, new User { Id = 6 }); try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0.06; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0.03; Assert.AreEqual(1, _savingServices.SaveContract(saving, client)); saving.Product.RateWithdrawFees = 0.02; saving.Product.RateWithdrawFeesMin = null; saving.Product.RateWithdrawFeesMax = null; _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6); _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, null); saving.RateWithdrawFees = null; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0.01; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0.03; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code); } saving.RateWithdrawFees = 0.02; Assert.AreEqual(2, _savingServices.SaveContract(saving, client)); }
public void TestSavingIsValid_InterestRate() { Assert.Ignore(); SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User { Id = 6 }, TimeProvider.Today, _savingsProduct, null) { FlatWithdrawFees = 3, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6, ManagementFees = 7 }; Client client = new Person { Id = 6, LastName = "El Fanidi" }; _savingManagerMock = new DynamicMock(typeof(SavingManager)); _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager)); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6); _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, null); _savingServices = new SavingServices((SavingManager)_savingManagerMock.MockInstance, (SavingEventManager)_savingEventManagerMock.MockInstance, new User { Id = 6 }); //Test InterestRate is valid (between min/max) saving.InterestRate = 0.11; try { _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.AgioFeesIsInvalid, (int)exception.Code); } try { _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6); _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, null); saving.InterestRate = 0.12; _savingServices.SaveContract(saving, client); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 3, 6); _savingManagerMock.ExpectAndReturn("Add", 3, saving, client, null); saving.InterestRate = 0.13; _savingServices.SaveContract(saving, client); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 4, 6); _savingManagerMock.ExpectAndReturn("Add", 4, saving, client, null); saving.InterestRate = 0.16; _savingServices.SaveContract(saving, client); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 5, 6); _savingManagerMock.ExpectAndReturn("Add", 5, saving, client, null); saving.InterestRate = 0.19; _savingServices.SaveContract(saving, client); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 6, 6); _savingManagerMock.ExpectAndReturn("Add", 6, saving, client, null); saving.InterestRate = 0.20; _savingServices.SaveContract(saving, client); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 7, 6); _savingManagerMock.ExpectAndReturn("Add", 7, saving, client, null); saving.InterestRate = 0.21; } catch (OpenCbsSavingException exception) { Assert.Fail(exception.Code.ToString()); } try { _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 8, 6); _savingManagerMock.ExpectAndReturn("Add", 8, saving, client, null); _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code); } //Test InterestRate is valid (equals to required value) //Create a product with min/max InterestRate _savingsProduct.InterestRate = 0.15; _savingsProduct.InterestRateMin = null; _savingsProduct.InterestRateMax = null; saving.InterestRate = 0.14; try { _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 9, 6); _savingManagerMock.ExpectAndReturn("Add", 9, saving, client, null); _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code); } _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 10, 6); _savingManagerMock.ExpectAndReturn("Add", 10, saving, client, null); saving.InterestRate = 0.15; _savingServices.SaveContract(saving, client); saving.InterestRate = 0.16; try { _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 11, 6); _savingManagerMock.ExpectAndReturn("Add", 11, saving, client, null); _savingServices.SaveContract(saving, client); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code); } }
public void TestSavingIsValid_InitialAmountTooSmall() { Assert.Ignore(); SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null) { InterestRate = 0.13, Product = _savingsProduct }; _savingServices = new SavingServices(null, null, new User { Id = 6 }); try { Client client = new Person { Id = 1 }; _savingServices.SaveContract(saving, client); saving.FirstDeposit(1, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller); Assert.Fail("Saving Contract shouldn't pass validation test before save (initial amount < product.min)."); } catch (OpenCbsSavingException exception) { Assert.AreEqual((int)OpenCbsSavingExceptionEnum.EntryFeesIsInvalid, (int)exception.Code); } }
public void TestSavingIsValid_InitialAmountCorrect() { // Assert.Ignore(); SavingBookContract saving = new SavingBookContract( ApplicationSettings.GetInstance(""), new User { Id = 6 }, TimeProvider.Today, _savingsProduct, null) { InterestRate = 0.13, FlatWithdrawFees = 3, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6, ManagementFees = 7, AgioFees = 6 }; Client client = new Person { Id = 6, LastName = "El Fanidi", Branch = new Branch()}; _savingManagerMock = new DynamicMock(typeof(SavingManager)); _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager)); DynamicMock connectionMock = new DynamicMock(typeof(SqlConnection)); DynamicMock transactionMock = new DynamicMock(typeof(SqlTransaction)); connectionMock.SetReturnValue("BeginTransaction", transactionMock.MockInstance); _savingManagerMock.SetReturnValue("GetConnection", connectionMock.MockInstance); _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6); _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, transactionMock.MockInstance); _savingServices = new SavingServices( (SavingManager)_savingManagerMock.MockInstance, (SavingEventManager)_savingEventManagerMock.MockInstance, new User { Id = 6 } ); try { Assert.GreaterOrEqual(_savingServices.SaveContract(saving, client), 0); saving = new SavingBookContract( ApplicationSettings.GetInstance(""), new User { Id = 6 }, TimeProvider.Today, _savingsProduct, null) { InterestRate = 0.13, FlatWithdrawFees = 3, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6, ManagementFees = 7, AgioFees = 6 }; _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6); _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, transactionMock.MockInstance); Assert.GreaterOrEqual(_savingServices.SaveContract(saving, client), 0); } catch (OpenCbsSavingException exception) { Assert.Fail(exception.Code.ToString()); } }