public void SetUp() { _manager = Substitute.For <InvestmentManager>(null as InvestmentDal); _controller = new InvestmentController(_manager) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; }
public void GetInvestments() { CreateFakeInvestmentContext(); InvestmentController controller = new InvestmentController(db); // get all of the investments List <Investment> investments = controller.Get(); // Asserts Assert.IsNotNull(investments); }
public void Get_Investments_By_User_Should_Return_NotFound_For_An_Invalid_UserId() { // Mock the user not being found var mock = new Mock <IInvestmentRepository>(); mock.Setup(repo => repo.GetInvestmentsByUser(0)).Returns(new List <Investment>()); _investmentController = new InvestmentController(mock.Object); var result = _investmentController.GetInvestmentsByUser(0); Assert.IsInstanceOf <NotFoundResult>(result); }
public void GetInvestmentsForUser() { CreateFakeInvestmentContext(); InvestmentController controller = new InvestmentController(db); // get the investments for userId = 1 List <Investment> investments = controller.Get(1); // Asserts Assert.IsNotNull(investments); Assert.AreEqual(2, investments.Count()); }
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); }
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); }
public void Get_Investments_By_User_Should_Return_Ok_For_A_Valid_UserId() { // Mock the user being found var investments = new List <Investment>(); investments.Add(new Investment { Id = 1, Name = "Test1" }); investments.Add(new Investment { Id = 2, Name = "Test2" }); investments.Add(new Investment { Id = 3, Name = "Test3" }); var mock = new Mock <IInvestmentRepository>(); mock.Setup(repo => repo.GetInvestmentsByUser(1)).Returns(investments); _investmentController = new InvestmentController(mock.Object); var result = _investmentController.GetInvestmentsByUser(1); Assert.IsInstanceOf <OkObjectResult>(result); }
public string GetCalculatedHolding(int clientId, DateTime?holdingDate = null) { var inves = new InvestmentController(); return(inves.CalculateHoldings(clientId, holdingDate)); }