Example #1
0
        public void ShouldBeAbleToFindIfTwoStructuresHaveSharedAccounts()
        {
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            var account3 = new Account(new AccountId(12341236), clientId);
            var account4 = new Account(new AccountId(12341237), clientId);

            var clientAccounts1 = new ClientAccounts();
            clientAccounts1.Add(account1);
            clientAccounts1.Add(account2);
            var structure1 = new Structure(clientAccounts1);

            var clientAccounts2 = new ClientAccounts();
            clientAccounts2.Add(account1);
            clientAccounts2.Add(account3);
            var structure2 = new Structure(clientAccounts2);

            var clientAccounts3 = new ClientAccounts();
            clientAccounts3.Add(account4);
            clientAccounts3.Add(account3);
            var structure3 = new Structure(clientAccounts3);

            Assert.IsTrue(structure1.SharesASourceAccountWith(structure2));
            Assert.IsFalse(structure1.SharesASourceAccountWith(structure3));
        }
 public void ShouldBeAbleToUpdateTheBalance()
 {
     var account = new Account(new AccountId(12345678), new ClientId("ABC123")) { Balance = 100, LastUpdatedDate = DateTime.Now };
     var targetAccount = new TargetAccount(account, 2);
     targetAccount.UpdateBalance(100);
     Assert.AreEqual(102, targetAccount.GetAmount());
 }
Example #3
0
        public void ShouldBeAbleToFindIfTwoStructuresHaveSharedAccounts()
        {
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            var account3 = new Account(new AccountId(12341236), clientId);
            var account4 = new Account(new AccountId(12341237), clientId);

            var clientAccounts1 = new ClientAccounts();
            clientAccounts1.Add(account1);
            clientAccounts1.Add(account2);

            var allocations = new List<Allocation> { new Allocation(new Account(new AccountId(54321439), clientId), 100) };

            var structure1 = new Structure(clientAccounts1, allocations, null, null);

            var clientAccounts2 = new ClientAccounts();
            clientAccounts2.Add(account1);
            clientAccounts2.Add(account3);
            var structure2 = new Structure(clientAccounts2, allocations, null, null);

            var clientAccounts3 = new ClientAccounts();
            clientAccounts3.Add(account4);
            clientAccounts3.Add(account3);
            var structure3 = new Structure(clientAccounts3, allocations, null, null);

            Assert.IsTrue(structure1.SharesASourceAccountWith(structure2));
            Assert.IsFalse(structure1.SharesASourceAccountWith(structure3));
        }
 public void ShouldNotBeAbleToCreateATargetAccountWithAccountAndAllocationPercentage()
 {
     var account = new Account(new AccountId(12345678), new ClientId("ABC123"))
                           {Balance = 100, LastUpdatedDate = DateTime.Now};
     var targetAccount = new TargetAccount(account, 2);
     Assert.AreEqual(targetAccount.GetAccountNumber(), account.GetAccountNumber());
 }
Example #5
0
        private void ProcessRow(string row)
        {
            var fields=row.Split(',');
            var clientId = new ClientId(fields[0]);
            var account = new Account(new AccountId(int.Parse(fields[1])), clientId) { Balance = double.Parse(fields[2].Trim()), LastUpdatedDate = DateTime.ParseExact(fields[3],"dd/mm/yyyy",null) };

            Repository.Save(account);
        }
Example #6
0
 private void Validate(Account newAccount)
 {
     string clientId = newAccount.GetClientId();
      if (accounts.Any(account => account.GetClientId() != clientId))
      {
     throw new ArgumentException("Account from two different clients cannot be added.");
      }
 }
Example #7
0
 public void ShouldNotBeAbleToCreateAStructureWithLessThanTwoSourceAccounts()
 {
     var clientId = new ClientId("ABC123");
     var account1 = new Account(new AccountId(12341234), clientId);
     var clientAccounts = new ClientAccounts();
     clientAccounts.Add(account1);
     Assert.Throws<ArgumentException>(() => new Structure(clientAccounts));
 }
 public void ShouldNotBeAbleToCreatAStructureWithAccountsFromTwoDifferentClients()
 {
     var clientId1 = new ClientId("ABC123");
     var clientId2 = new ClientId("ABC124");
     var account1 = new Account(new AccountId(12341234), clientId1);
     var account2 = new Account(new AccountId(12341235), clientId2);
     var clientAccounts = new ClientAccounts();
     clientAccounts.Add(account1);
     Assert.Throws<ArgumentException>(() => clientAccounts.Add(account2));
 }
Example #9
0
        public void ShouldBeAbleToProcessTheFeed()
        {
            var account = new Account(new AccountId(87654123), new ClientId("ABC823")) { Balance = 4000, LastUpdatedDate = DateTime.Now };
            var mockRepository = new Mock<IRepository>();
            var feedProcessor = new FeedProcessor(mockRepository.Object, "../../../Pickup/feed.csv");

            mockRepository.Setup(repo => repo.Save(account));
            feedProcessor.Process();
            mockRepository.Verify(repo => repo.Save(account));
        }
Example #10
0
 public void ShouldBeAbleAddAStructure()
 {
     var clientId = new ClientId("ABC123");
     var account1 = new Account(new AccountId(12341234), clientId);
     var account2 = new Account(new AccountId(12341235), clientId);
     var clientAccounts = new ClientAccounts();
     clientAccounts.Add(account1);
     clientAccounts.Add(account2);
     var structure = new Structure(clientAccounts);
     var client = new Client(clientId, clientAccounts);
     client.AddStructure(structure);
     Assert.IsTrue(client.Contains(structure));
 }
Example #11
0
        public void ShouldCalculateNetBalance()
        {
            var account1 = new Account(new AccountId(12341234), new ClientId("ABC123"));
            var account2 = new Account(new AccountId(12341235), new ClientId("ABC123"));

            account1.Balance = 1000.0;
            account2.Balance = -500.0;
            var clientAccounts = new ClientAccounts();
            clientAccounts.Add(account1);
            clientAccounts.Add(account2);

            Assert.AreEqual(500.0, clientAccounts.NetBalance());
        }
Example #12
0
 public void ShouldSaveAccountToRepository()
 {
     var clientId = new ClientId("ABC123");
     var account = new Account(new AccountId(12341234), clientId) { Balance = 100.00, LastUpdatedDate = DateTime.Now };
     using (var tx = session.BeginTransaction())
     {
         session.Save(account);
         var query = session.CreateQuery("from Account");
         var accounts = query.List<Account>();
         tx.Commit();
         Assert.AreEqual(1, accounts.Count());
     }
 }
Example #13
0
        public void ShouldBeAbleToAddAStructure()
        {
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            var clientAccounts = new ClientAccounts();
            clientAccounts.Add(account1);
            clientAccounts.Add(account2);
            var structure = new Structure(clientAccounts, getAllocation(), null, null);
            var structures = new Structures();
            structures.Add(structure);

            Assert.True(structures.Contains(structure));
        }
Example #14
0
        public void ShouldAllocateInterestAmountToExternalAccount()
        {
            const double netInterest = (10.0 / 365);

            var mock = new Mock<InterestRates>();

            mock.Setup(i => i.PositiveInterestRate()).Returns(2.0);
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(43214321), clientId);
            var allocations = new List<Allocation> { new Allocation(account1, 100) };

            var expectedMap = new Dictionary<Account, double> { { account1, netInterest } };

            Assert.AreEqual(expectedMap[account1], GetTestStructure(1000.0, -500.0, allocations, mock.Object, null).GetAllocation()[account1]);

            mock.VerifyAll();
        }
Example #15
0
        public void ShouldAllocateInterestAmountToPooledAccount()
        {
            const double netInterest = (10.0 / 365);

            var mock = new Mock<InterestRates>();

            mock.Setup(i => i.PositiveInterestRate()).Returns(2.0);
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            account1.Balance = 1000.0;
            account2.Balance = -500.0;
            var allocations = new List<Allocation> { new Allocation(account1, 30) , new Allocation(account2, 70)};

            var expectedMap = new Dictionary<Account, double> { {account1, netInterest * 0.3} , {account2 , netInterest * 0.7}};

            Assert.AreEqual(expectedMap[account1], GetTestStructure(1000.0, -500.0, allocations, mock.Object, null).GetAllocation()[account1]);
            Assert.AreEqual(expectedMap[account2], GetTestStructure(1000.0, -500.0, allocations, mock.Object, null).GetAllocation()[account2]);

            mock.VerifyAll();
        }
Example #16
0
        public void ShouldNotBeAbleToCreateClientStructuresWithTwoRepeatingAccounts()
        {
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            var account3 = new Account(new AccountId(12341236), clientId);
            var clientAccounts1 = new ClientAccounts();
            clientAccounts1.Add(account1);
            clientAccounts1.Add(account2);

            var clientAccounts2 = new ClientAccounts();
            clientAccounts2.Add(account1);
            clientAccounts2.Add(account3);

            var structure1 = new Structure(clientAccounts1);
            var structure2 = new Structure(clientAccounts2);

            var structures = new Structures();
            structures.Add(structure1);

            Assert.Throws<ArgumentException>(() => structures.Add(structure2));
        }
        public void ShouldBeAbleToFindTwoClientAccountsShareACommonAccount()
        {
            var account1 = new Account(new AccountId(12341234), new ClientId("ABC123"));
            var account2 = new Account(new AccountId(12341235), new ClientId("ABC123"));
            var account3 = new Account(new AccountId(12341236), new ClientId("ABC123"));
            var account4 = new Account(new AccountId(12341237), new ClientId("ABC123"));

            var clientAccounts1 = new ClientAccounts();
            clientAccounts1.Add(account1);
            clientAccounts1.Add(account2);

            var clientAccounts2 = new ClientAccounts();
            clientAccounts2.Add(account1);
            clientAccounts2.Add(account3);

            var clientAccounts3 = new ClientAccounts();
            clientAccounts3.Add(account3);
            clientAccounts3.Add(account4);

            Assert.IsTrue(clientAccounts1.SharesAccountWith(clientAccounts2));
            Assert.IsFalse(clientAccounts1.SharesAccountWith(clientAccounts3));
        }
Example #18
0
 public void Add(Account newAccount)
 {
     Validate(newAccount);
      accounts.Add(newAccount);
 }
Example #19
0
        public void ShouldNotCreateStructureWithout100PercentAllocation()
        {
            var mock = new Mock<InterestRates>();

             mock.Setup(i => i.PositiveInterestRate()).Returns(2.0);
             var clientId = new ClientId("ABC123");
             var account1 = new Account(new AccountId(12341234), clientId);
             var account2 = new Account(new AccountId(12341235), clientId);
             var allocations = new List<Allocation> { new Allocation(account1, 30) , new Allocation(account2, 30)};

             try
             {
                 GetTestStructure(1000.0, -500.0, allocations, mock.Object, null);
                 Assert.Fail("Should Not create Structure with Allocation interest percent sum not equal to 100");
             }
             catch (ArgumentException)
             {
             }
        }
Example #20
0
 private List<Allocation> getAllocation()
 {
     var clientId = new ClientId("ABC123");
     var account1 = new Account(new AccountId(43214321), clientId);
     return new List<Allocation> { new Allocation(account1, 100) };
 }
Example #21
0
 public void TestFixtureSetUp()
 {
     var type = new Account().GetType();
     var assembly = Assembly.GetAssembly(type);
     InitalizeSessionFactory(assembly);
 }
Example #22
0
 public bool Equals(Account other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.AccountNo, AccountNo) && Equals(other.ClientId, ClientId);
 }
Example #23
0
 private void ProcessRow(string row)
 {
     var clientId = new ClientId("ABC123");
     var account = new Account(new AccountId(12341234), clientId) { Balance = 100.00, LastUpdatedDate = DateTime.Now };
     Repository.Save(account);
 }
Example #24
0
        public void ShouldGeneratePaymentInstructionForStructure()
        {
            var mock = new Mock<InterestRates>();
            mock.Setup(i => i.PositiveInterestRate()).Returns(2.0);

            var paymentInstructionService = new Mock<PaymentInstructionService>();
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            account1.Balance = 1000.0;
            account2.Balance = -500.0;
            var allocations = new List<Allocation> { new Allocation(account1, 70), new Allocation(account2, 30) };

            Structure structure = GetTestStructure(1000.0, -500.0, allocations, mock.Object, paymentInstructionService.Object);

            const decimal amount1 = (decimal) (0.7*10/365);
            paymentInstructionService.Setup(
                pis => pis.Generate(new Payment("12341234", amount1, DateTime.Now)));

            const decimal amount2 = (decimal) (0.3*10/365);
            paymentInstructionService.Setup(
                pis => pis.Generate(new Payment("12341235", amount2, DateTime.Now)));

            structure.GeneratePaymentInstruction();

            paymentInstructionService.VerifyAll();
        }
Example #25
0
        private static Structure GetTestStructure(double balance1, double balance2, List<Allocation> allocations, InterestRates interestRates, PaymentInstructionService paymentInstructionService)
        {
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(12341235), clientId);
            account1.Balance = balance1;
            account2.Balance = balance2;

            var clientAccounts = new ClientAccounts();
            clientAccounts.Add(account1);
            clientAccounts.Add(account2);
            return new Structure(clientAccounts, allocations, interestRates, paymentInstructionService);
        }
Example #26
0
 public bool Contains(Account account)
 {
     return accounts.Contains(account);
 }
Example #27
0
 public void Save(Account account)
 {
     Accounts.Add(account);
 }
Example #28
0
        public void ShouldNotHaveAllocationToPoolAndExternalAccount()
        {
            var mock = new Mock<InterestRates>();

            mock.Setup(i => i.PositiveInterestRate()).Returns(2.0);
            var clientId = new ClientId("ABC123");
            var account1 = new Account(new AccountId(12341234), clientId);
            var account2 = new Account(new AccountId(43121235), clientId);
            var allocations = new List<Allocation> { new Allocation(account1, 70), new Allocation(account2, 30) };
            try
            {
                GetTestStructure(1000.0, -500.0, allocations, mock.Object, null);
                Assert.Fail("Should not Allocate Interest to both Pool And External Account");
            }
            catch (ArgumentException)
            {
            }
        }