Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }