Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
 public void DeleteClientAccount(Guid id)
 {
     if (ClientAccounts.ContainsKey(id))
     {
         ClientAccounts.Remove(id);
     }
 }
Ejemplo n.º 4
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, getAllocation(), null, null);
            var structure2 = new Structure(clientAccounts2, getAllocation(), null, null);

            var structures = new Structures();

            structures.Add(structure1);

            Assert.Throws <ArgumentException>(() => structures.Add(structure2));
        }
Ejemplo n.º 5
0
        private async Task prepareTestData()
        {
            ApiConsumer registerConsumer = new ApiConsumer(new ConfigBuilder("BlueApi"));

            this.TestClient = await registerConsumer.RegisterNewUser();

            await ClientAccounts.FillWalletWithAsset(TestClient.Account.Id, Constants.BALANCES_ASSET_ID, Constants.BALANCES_ASSET_AMOUNT);
        }
        public async Task CreatePledgeClientAndApiConsumer(string purpose)
        {
            ApiConsumer consumer = new ApiConsumer(_blueApiAppSettings);
            await consumer.RegisterNewUser();

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(consumer.ClientInfo.Account.Id));
            PledgeApiConsumers.Add(purpose, consumer);
        }
Ejemplo n.º 7
0
        public void ShouldCreateClientAccountsFromAccountCollection()
        {
            var clientId1      = new ClientId("ABC123");
            var clientAccounts = new ClientAccounts(new List <Account> {
                new Account(new AccountId(12341234), clientId1), new Account(new AccountId(12341235), clientId1)
            });

            Assert.AreEqual(2, clientAccounts.Count);
        }
Ejemplo n.º 8
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, null, null, null));
        }
Ejemplo n.º 9
0
        public ClientAccount AddClientAccount(string clientName)
        {
            var id            = Guid.NewGuid();
            var clientAccount = new ClientAccount().CreateAccount(id, clientName);

            ClientAccounts.Add(id, clientAccount);

            return(clientAccount);
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        public ClientAccount UpdateClientAccount(Guid id, string clientName)
        {
            if (!ClientAccounts.ContainsKey(id))
            {
                return(null);
            }

            var clientAccount = ClientAccounts[id];

            clientAccount.ClientName = clientName;

            return(clientAccount);
        }
Ejemplo n.º 12
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());
        }
Ejemplo n.º 13
0
        public UserProfile AddNewUserProfileToAccount(Guid userAccountId, Guid clientId, string emailAddress, List <AwardItem> awards = null)
        {
            if (!UserAccounts.ContainsKey(userAccountId) || !ClientAccounts.ContainsKey(clientId))
            {
                return(null);
            }

            var clientAccount = ClientAccounts[clientId];
            var newProfile    = new UserProfile().CreateUserProfile(Guid.NewGuid(), emailAddress, clientAccount, awards);

            UserAccounts[userAccountId].AddProfile(newProfile);

            return(newProfile);
        }
Ejemplo n.º 14
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, getAllocation(), null, null);
            var client    = new Client(clientId, clientAccounts);

            client.AddStructure(structure);
            Assert.IsTrue(client.Contains(structure));
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
0
        public UserProfile UpdateUserProfile(Guid profileId, Guid clientId, string emailAddress, List <AwardItem> awards = null)
        {
            if (!ClientAccounts.ContainsKey(clientId) || !UserProfiles.Any(up => up.Id == profileId))
            {
                return(null);
            }

            var clientAccount      = ClientAccounts[clientId];
            var updatedUserProfile = new UserProfile().CreateUserProfile(profileId, emailAddress, clientAccount, awards);
            var currentProfile     = UserProfiles.Single(up => up.Id == profileId);

            currentProfile.UpdateUserProfile(updatedUserProfile);

            return(currentProfile);
        }
        private async Task <List <ApiConsumer> > RegisterNUsers(int n)
        {
            List <ApiConsumer> result = new List <ApiConsumer>();

            for (int i = 0; i < n; i++)
            {
                ApiConsumer consumer = new ApiConsumer(_blueApiAppSettings);
                await consumer.RegisterNewUser();

                AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(consumer.ClientInfo.Account.Id));
                result.Add(consumer);
            }

            return(result);
        }
        public async Task CreateTestPartnerClient()
        {
            await ClientAccountConsumer.RegisterNewUser(
                new ClientRegisterDTO
            {
                Email        = Helpers.RandomString(8) + GlobalConstants.AutoTestEmail,
                FullName     = Helpers.RandomString(5) + " " + Helpers.RandomString(8),
                ContactPhone = Helpers.Random.Next(1000000, 9999999).ToString(),
                Password     = Helpers.RandomString(10),
                Hint         = Helpers.RandomString(3),
                PartnerId    = _blueApiAppSettings.TestPartnerId  //  "NewTestPartner"
            }
                );

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(ClientAccountConsumer.ClientInfo.Account.Id));
        }
        private async Task PrepareTestData()
        {
            var TestClient = await Consumer.RegisterNewUser();

            TestClientId = TestClient.Account.Id;
            var walletsFromDB    = this.WalletRepository.GetAllAsync(w => w.ClientId == TestClientId && w.State != "deleted");
            var operationsFromDB = this.OperationsRepository.GetAllAsync(o => o.PartitionKey == OperationsEntity.GeneratePartitionKey() && o.ClientId.ToString() == TestClientId);

            this.TestAssetId      = Constants.TestAssetId;
            this.AssetPrecission  = 2;
            this.AllWalletsFromDb = (await walletsFromDB).Cast <WalletEntity>().ToList();
            this.TestWallet       = await CreateTestWallet();

            //fill wallet with funds
            await MEConsumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestWallet.Id, Constants.TestAssetId, 50.0);

            this.TestWalletWithBalanceId = TestWallet.Id;


            this.TestWalletDelete = await CreateTestWallet();

            this.TestWalletAccount = await AccountRepository.TryGetAsync(TestWallet.Id) as AccountEntity;

            this.TestWalletOperations = await CreateTestWallet();

            this.TestWalletRegenerateKey = await CreateTestWallet(true);

            this.TestOperation = await CreateTestOperation();

            this.TestOperationCancel = await CreateTestOperation();

            this.TestOperationCreateDetails = await CreateTestOperation();

            this.TestOperationRegisterDetails = await CreateTestOperation();


            this.ClientInfoConsumer = new ApiConsumer(_apiV2Settings);
            await this.ClientInfoConsumer.RegisterNewUser();

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(ClientInfoConsumer.ClientInfo.Account.Id));

            // set the id to the default one in case it has been changed by any test
            BaseAssetDTO body     = new BaseAssetDTO(this.TestAssetId);
            var          response = await Consumer.ExecuteRequest(ApiPaths.ASSETS_BASEASSET_PATH, Helpers.EmptyDictionary, JsonUtils.SerializeObject(body), Method.POST);
        }
Ejemplo n.º 20
0
        public async Task CreateLykkeBluePartnerClientAndApiConsumer()
        {
            var consumer = new ApiConsumer(_configBuilder);

            await consumer.RegisterNewUser(
                new ClientRegisterDTO
            {
                Email        = Helpers.RandomString(8) + GlobalConstants.AutoTestEmail,
                FullName     = Helpers.RandomString(5) + " " + Helpers.RandomString(8),
                ContactPhone = Helpers.Random.Next(1000000, 9999999).ToString(),
                Password     = Helpers.RandomString(10),
                Hint         = Helpers.RandomString(3),
                PartnerId    = _configBuilder.Config["LykkeBluePartnerId"]  // "Lykke.blue"
            }
                );

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(consumer.ClientInfo.Account.Id));
        }
Ejemplo n.º 21
0
        private async Task prepareTestData()
        {
            ConfigBuilder apiv2Config          = new ConfigBuilder("ApiV2");
            ApiConsumer   registerConsumer1    = new ApiConsumer(apiv2Config);
            ApiConsumer   registerConsumer2    = new ApiConsumer(apiv2Config);
            var           registerTestAccount1 = registerConsumer1.RegisterNewUser();
            var           registerTestAccount2 = registerConsumer2.RegisterNewUser();

            TestAsset1 = Constants.TestAsset1;
            TestAsset2 = Constants.TestAsset2;

            TestAccountId1 = (await registerTestAccount1)?.Account.Id;
            TestAccountId2 = (await registerTestAccount2)?.Account.Id;

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(TestAccountId1));
            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(TestAccountId2));

            //give test clients some cash to work with
            List <Task> giveCashTasks = new List <Task>()
            {
                Consumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestAccountId1, TestAsset1, Constants.InitialAssetAmmount),
                Consumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestAccountId1, TestAsset2, Constants.InitialAssetAmmount),
                Consumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestAccountId2, TestAsset1, Constants.InitialAssetAmmount),
                Consumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestAccountId2, TestAsset2, Constants.InitialAssetAmmount)
            };

            if (!Int32.TryParse(_configBuilder.Config["AssetPrecission"], out AssetPrecission))
            {
                AssetPrecission = 2;
            }

            this.TestAssetPair = (AssetPairEntity)Task.Run(async() =>
            {
                return(await this.AssetPairsRepository.TryGetAsync(TestAsset1 + TestAsset2));
            }).Result;

            await Task.WhenAll(giveCashTasks);
        }
Ejemplo n.º 22
0
 public ClientAccount GetClientAccountById(Guid id)
 {
     return(ClientAccounts.ContainsKey(id) ? ClientAccounts[id] : null);
 }