コード例 #1
0
        public void GetInvestmentDetailsForInvestmentId()
        {
            CreateFakeInvestmentContext();

            InvestmentController controller = new InvestmentController(db);

            // get the investments for userId = 1
            InvestmentDetail2 investmentDetails = controller.GetInvestmentDetail(1);

            // Asserts
            Assert.IsNotNull(investmentDetails);
            Assert.AreEqual(5, investmentDetails.Shares);
            Assert.AreEqual(14, investmentDetails.CostBasisPerShare);
            Assert.AreEqual(55, investmentDetails.CurrentPrice);
            Assert.AreEqual(InvestmentHelper.GetCurrentValue(investmentDetails.Shares, investmentDetails.CurrentPrice), investmentDetails.CurrentValue);
            Assert.AreEqual(InvestmentHelper.GetTerm(investmentDetails.PurchaseDate), investmentDetails.Term);
            Assert.AreEqual(InvestmentHelper.GetNetGainLoss(investmentDetails.CurrentValue, investmentDetails.Shares, investmentDetails.CostBasisPerShare), investmentDetails.NetGainLoss);
        }
コード例 #2
0
        public InvestmentDetail2 GetInvestmentDetail(int investmentId)
        {
            InvestmentDetail investmentDetail = db.InvestmentDetails.Where(x => x.InvestmentId == investmentId).FirstOrDefault();

            if (investmentDetail == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            InvestmentDetail2 returnDetail = new InvestmentDetail2();

            returnDetail.Id                = investmentDetail.Id;
            returnDetail.InvestmentId      = investmentDetail.InvestmentId;
            returnDetail.CostBasisPerShare = investmentDetail.CostBasisPerShare;
            returnDetail.CurrentPrice      = investmentDetail.CurrentPrice;
            returnDetail.Shares            = investmentDetail.Shares;
            returnDetail.PurchaseDate      = investmentDetail.PurchaseDate;
            returnDetail.CurrentValue      = InvestmentHelper.GetCurrentValue(returnDetail.Shares, returnDetail.CurrentPrice);
            returnDetail.Term              = InvestmentHelper.GetTerm(returnDetail.PurchaseDate);
            returnDetail.NetGainLoss       = InvestmentHelper.GetNetGainLoss(returnDetail.CurrentValue, returnDetail.Shares, returnDetail.CostBasisPerShare);

            return(returnDetail);
        }