Exemple #1
0
        public void Get_InvestmentDetails_Should_Return_NotFound_For_An_Invalid_InvestmentId()
        {
            // Mock the investment detail not being found
            InvestmentPerformance investmentPerformance = null;

            var mock = new Mock <IInvestmentRepository>();

            mock.Setup(repo => repo.GetInvestmentDetail(0)).Returns(investmentPerformance);
            _investmentController = new InvestmentController(mock.Object);

            var result = _investmentController.GetInvestmentDetail(0);

            Assert.IsInstanceOf <NotFoundResult>(result);
        }
        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);
        }
Exemple #3
0
        public void Get_InvestmentDetails_Should_Return_Ok_For_A_Valid_InvestmentId()
        {
            // Mock the investment being found
            InvestmentPerformance investmentPerformance = new InvestmentPerformance
            {
                Id                = 1,
                Name              = "Test1",
                Shares            = 100,
                CostBasisPerShare = 0.1M,
                CurrentValue      = 20,
                CurrentPrice      = 0.2M,
                Term              = Term.Long,
                NetGain           = 10,
            };

            var mock = new Mock <IInvestmentRepository>();

            mock.Setup(repo => repo.GetInvestmentDetail(1)).Returns(investmentPerformance);
            _investmentController = new InvestmentController(mock.Object);

            var result = _investmentController.GetInvestmentDetail(1);

            Assert.IsInstanceOf <OkObjectResult>(result);
        }