public BorrowingProfileFacadeTests()
 {
     AutoMapperConfiguration.Initialize();
     _filter   = BorrowingProfileFilter.Default;
     _settings = new Mock <IBorrowingProfileSettings>();
     _settings.Setup(x => x.GetBorrowingProfileServiceUrl()).Returns("http://url");
 }
        public BorrowingProfileControllerTests()
        {
            AutoMapperConfiguration.Initialize();
            _filter = BorrowingProfileFilter.Default;

            var clientSettingsMock = new Mock <IBorrowingProfileClientSettings>();

            clientSettingsMock.Setup(x => x.GetApplicationName()).Returns("App Test");
            _settingsMock = new Mock <IOptions <BorrowingProfileClientSettings> >();
            _settingsMock.Setup(x => x.Value).Returns(clientSettingsMock.Object as BorrowingProfileClientSettings);
        }
예제 #3
0
        public async Task <ProfileDataModel[]> GetProfilesDataAsync(BorrowingProfileFilter filter)
        {
            var param   = Mapper.Map <BorrowingProfileFilter, BorrowingProfileParameter>(filter);
            var request = new RestRequest(_settings.GetProfileUrl(),
                                          Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(param);
            var response = await ExecuteAsync <List <Models.BorrowingProfile.ClientModels.BorrowingProfile> >(_client, request);

            return(Mapper.Map <List <Models.BorrowingProfile.ClientModels.BorrowingProfile>, ProfileDataModel[]>(response));
        }
예제 #4
0
        public async Task <ProfileDataModel[]> GetHedgesAsync(BorrowingProfileFilter filter)
        {
            var param   = Mapper.Map <BorrowingProfileFilter, BorrowingProfileParameter>(filter);
            var request =
                new RestRequest(_settings.GetHedgesUrl(), Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(param);
            var response = await ExecuteAsync <List <BorrowingProfileHedges> >(_client, request);

            var mappedResult = Mapper.Map <List <BorrowingProfileHedges>, List <ProfileDataModel> >(response);

            return(mappedResult.ToArray());
        }
예제 #5
0
        public async Task <ProfileDealsModel> GetDealsDataAsync(BorrowingProfileFilter filter)
        {
            var request = new RestRequest(_settings.GetDealsUrl(), Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(Mapper.Map <BorrowingProfileFilter, BorrowingProfileDealParameter>(filter));
            var response = await ExecuteAsync <List <BorrowingProfileDeal> >(_client, request);

            var dealVm = new ProfileDealsModel
            {
                Deals = Mapper.Map <List <BorrowingProfileDeal>, List <ProfileDealInfoModel> >(response)
            };

            dealVm.ProfileDetailsTotal = DealsCalculator.Sum(dealVm.Deals.ToArray());
            return(dealVm);
        }
예제 #6
0
        public async Task <ProfileDetailsModel> GetDetailsAsync(BorrowingProfileFilter filter, int dealId)
        {
            var param = Mapper.Map <BorrowingProfileFilter, BorrowingTradeDetailsParameter>(filter);

            param.DealID = dealId;
            var details = new ProfileDetailsModel {
                ProfileName = filter.ProfileName
            };

            var request = new RestRequest(_settings.GetDetailsUrl() + param.DealID,
                                          Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(param);
            var response = await ExecuteAsync <List <BorrowingTradeDetails> >(_client, request);

            details.Trades = Mapper.Map <List <BorrowingTradeDetails>, TradeDetailsModel[]>(response);
            return(details);
        }
        public async Task <IActionResult> Post([FromBody] BorrowingProfileFilter filter)
        {
            if (filter == null)
            {
                filter = BorrowingProfileFilter.Default;
            }
            var vm = new BorrowingProfileViewModel {
                Filter = filter, Fiscals = FiscalYear.GetFiscals()
            };
            var fiscalYear = new FiscalYear(filter.StartFiscalYear);

            vm.Profiles = await _facade.GetProfilesDataAsync(filter);

            vm.Target = await _facade.GetTargetAsync(fiscalYear);

            vm.Hedges = await _facade.GetHedgesAsync(filter);

            if (vm.Profiles != null)
            {
                vm.ProfilesTotals = ProfileCalculator.CalculateTotals(vm.Profiles, vm.Target, fiscalYear);
                vm.ElapsedTime    = ProfileCalculator.CalculateTimeElapsed(fiscalYear);
            }
            return(Ok(vm));
        }
        public async Task <IActionResult> PostByProfileName([FromBody] BorrowingProfileFilter filter)
        {
            var details = await _facade.GetDealsDataAsync(filter);

            return(Ok(details));
        }
        public async Task <IActionResult> PostByDealId([FromBody] BorrowingProfileFilter filter, [FromQuery] int?dealId)
        {
            var details = await _facade.GetDetailsAsync(filter, dealId ?? 0);

            return(Ok(details));
        }