public void GetStockPropertiesEquityReturnDataTest()
        {
            var           service            = new StockPropertiesService();
            IList <Stock> bonds              = MockHelper.Bonds;
            var           expectedTotalBonds = new StockProperties();

            expectedTotalBonds.TotalNumber      = bonds.Count;
            expectedTotalBonds.TotalMarketValue = bonds.Sum(x => x.MarketValue);

            IList <Stock> equities = MockHelper.Equities;
            var           expectedTotalEquities = new StockProperties();

            expectedTotalEquities.TotalNumber      = equities.Count;
            expectedTotalEquities.TotalMarketValue = equities.Sum(x => x.MarketValue);

            var totalMarketValue = expectedTotalBonds.TotalMarketValue + expectedTotalEquities.TotalMarketValue;

            expectedTotalBonds.TotalStockWeight    = expectedTotalBonds.TotalMarketValue * 100 / totalMarketValue;
            expectedTotalEquities.TotalStockWeight = expectedTotalEquities.TotalMarketValue * 100 / totalMarketValue;

            var stocks = MockHelper.GetStocks();


            var properties   = service.GetStockProperties(stocks);
            var actualBond   = properties[StockType.Bond];
            var actualEquity = properties[StockType.Equity];

            Assert.AreEqual(actualBond.TotalMarketValue, expectedTotalBonds.TotalMarketValue);
            Assert.AreEqual(actualBond.TotalNumber, expectedTotalBonds.TotalNumber);
            Assert.AreEqual(actualBond.TotalStockWeight, expectedTotalBonds.TotalStockWeight);
            Assert.AreEqual(actualEquity.TotalMarketValue, expectedTotalEquities.TotalMarketValue);
            Assert.AreEqual(actualEquity.TotalNumber, expectedTotalEquities.TotalNumber);
            Assert.AreEqual(actualEquity.TotalStockWeight, expectedTotalEquities.TotalStockWeight);
        }
Пример #2
0
        /*      // GET : /api/stocks/{id}/relativenta
         *    [Route("{id:guid}/relativenta")]
         *    [HttpGet]
         *    public ActionResult<RelativeNtaResponse> GetRelativeNta([FromRoute] Guid id, [FromQuery] DateTime? fromDate, [FromQuery] DateTime? toDate)
         *    {
         *        throw new NotSupportedException();
         *                  var stock = _StockQuery.Get(id);
         *                  if (stock == null)
         *                      return NotFound();
         *
         *                  if (stock is StapledSecurity stapledSecurity)
         *                  {
         *                      var dateRange = new DateRange((fromDate != null) ? (DateTime)fromDate : DateUtils.NoStartDate, (toDate != null) ? (DateTime)toDate : DateTime.Today);
         *
         *                      return Ok(stapledSecurity.ToRelativeNTAResponse(dateRange));
         *                  }
         *                  else
         *                  {
         *                      return BadRequest("Relative NTAs only apply stapled securities");
         *                  }
         *
         *
         *    }*/

        // POST : /api/stocks/{id}/relativenta

        /*   [Authorize(Policy.CanMantainStocks)]
         * [Route("{id:guid}/relativenta")]
         * [HttpPost]
         * public ActionResult ChangeRelativeNta([FromRoute] Guid id, [FromBody] ChangeRelativeNtaCommand command)
         * {
         *     throw new NotSupportedException();
         *                 // Check id in URL and id in command match
         *                 if (id != command.Id)
         *                     return BadRequest("Id in command doesn't match id on URL");
         *
         *                 var stock = _StockQuery.Get(id);
         *                 if (stock == null)
         *                     return NotFound();
         *
         *                 if (stock is StapledSecurity stapledSecurity)
         *                 {
         *                     if (command.RelativeNTAs.Count != stapledSecurity.ChildSecurities.Count)
         *                     {
         *                         return BadRequest(String.Format("The number of relative ntas provided ({0}) did not match the number of child securities ({1})", command.RelativeNTAs.Count, stapledSecurity.ChildSecurities.Count));
         *                     }
         *
         *                     var ntas = new decimal[stapledSecurity.ChildSecurities.Count];
         *                     for (var i = 0; i < stapledSecurity.ChildSecurities.Count; i++)
         *                     {
         *                         var nta = command.RelativeNTAs.Find(x => x.ChildSecurity == stapledSecurity.ChildSecurities[i].ASXCode);
         *                         if (nta == null)
         *                             return BadRequest(String.Format("Relative nta not provided for {0}", stapledSecurity.ChildSecurities[i].ASXCode));
         *
         *                         ntas[i] = nta.Percentage;
         *                     }
         *
         *                     try
         *                     {
         *                         _StockService.ChangeRelativeNTAs(id, command.ChangeDate, ntas);
         *                     }
         *                     catch (Exception e)
         *                     {
         *                         return BadRequest(e.Message);
         *                     }
         *
         *                     return Ok();
         *                 }
         *                 else
         *                 {
         *                     return BadRequest("Relative NTAs only apply stapled securities");
         *                 }
         *
         *
         * } */

        private bool MatchesQuery(StockProperties stock, string query)
        {
            return((stock.AsxCode.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) || (stock.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0));
        }