示例#1
0
        public void DepositAddressCreationFailedTest_TestsIfDepositAddressIsActuallyNotCreatedIfTier1IsNotVerified_VerfiesThroughExceptionRaised()
        {
            IDepositApplicationService    depositApplicationService = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService;

            Assert.IsNotNull(tierLevelRetrievalService);
            tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel0);

            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency("BTC", true);

            depositApplicationService.GenarateNewAddress(new GenerateNewAddressCommand(accountId.Value, currency.Name));
        }
示例#2
0
        public void DepositAddressCreationSuccessTest_TestsIfDepositAddressIsActuallyCreatedIfTier1IsVerified_VerfiesThroughReturnValueAndDatabaseQuery()
        {
            IDepositAddressRepository     depositAddressRepository  = (IDepositAddressRepository)ContextRegistry.GetContext()["DepositAddressRepository"];
            IDepositApplicationService    depositApplicationService = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService;

            Assert.IsNotNull(tierLevelRetrievalService);
            tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel1);

            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency("BTC", true);
            DepositAddressRepresentation addressResponse = depositApplicationService.GenarateNewAddress(new GenerateNewAddressCommand(accountId.Value, currency.Name));

            Assert.IsNotNull(addressResponse);
            Assert.AreEqual(AddressStatus.New.ToString(), addressResponse.Status);

            List <DepositAddress> depositAddresses = depositAddressRepository.GetDepositAddressByAccountIdAndCurrency(accountId, currency.Name);

            Assert.AreEqual(1, depositAddresses.Count);
            Assert.AreEqual(accountId.Value, depositAddresses.Single().AccountId.Value);
            Assert.AreEqual(currency.Name, depositAddresses.Single().Currency.Name);
            Assert.AreEqual(AddressStatus.New, depositAddresses.Single().Status);
        }
 public IHttpActionResult CreateDepositAddress([FromBody] GenerateAddressParams generateAddressParams)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug(string.Format("Deposit Address Generation call: Currency = {0} | Account ID = {1}",
                                 generateAddressParams.Currency, generateAddressParams.AccountId));
     }
     try
     {
         //get api key from header
         var    headers = Request.Headers;
         string apikey  = "";
         IEnumerable <string> headerParams;
         if (headers.TryGetValues("Auth", out headerParams))
         {
             string[] auth = headerParams.ToList()[0].Split(',');
             apikey = auth[0];
         }
         if (log.IsDebugEnabled)
         {
             log.Debug(string.Format("Generate Deposit Address Call: ApiKey = {0}", apikey));
         }
         if (generateAddressParams != null && !string.IsNullOrEmpty(generateAddressParams.Currency))
         {
             int accountId = _apiKeyInfoAccess.GetUserIdFromApiKey(apikey);
             return(Ok(_depositApplicationService.GenarateNewAddress(new GenerateNewAddressCommand(
                                                                         accountId, generateAddressParams.Currency))));
         }
         return(BadRequest("Currency is not provided."));
     }
     catch (InvalidOperationException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Create New Address Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (NullReferenceException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Create New Address Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (InstanceNotFoundException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Create New Address Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(string.Format("Generate Deposit Address Call Error: {0}", exception));
         }
         return(InternalServerError());
     }
 }