示例#1
0
        public void Test_Return_NotFoundResult()
        {
            var mock       = new Mock <ITestService>();
            var controller = new TestDBController(mock.Object, null);

            var result = controller.GetId(null);

            Assert.IsType <NotFoundResult>(result);
        }
示例#2
0
        public void Test_Return_NotFoundResult_When_NotFound()
        {
            string testId = "5caeff79e1d244a0eccce920";
            var    mock   = new Mock <ITestService>();

            mock.Setup(repo => repo.GetbyId(testId)).Returns(null as TestDB);
            var controller = new TestDBController(mock.Object, null);

            var result = controller.GetId(testId);

            Assert.IsType <NotFoundResult>(result);
        }
示例#3
0
        public void Test_Return_By_Id_OkResult()
        {
            // не работает ? не знаю почему
            string testId = "5cb489bfa2e6bd3c6497afc0";
            var    mock   = new Mock <ITestService>();


            var controller = new TestDBController(mock.Object, null);

            var test = controller.GetId(testId);

            Assert.IsType <OkObjectResult>(test);
        }
示例#4
0
        public void Test_Match_Result()
        {
            string testId = "5cb489bfa2e6bd3c6497afc0";
            var    mock   = new Mock <ITestService>();

            mock.Setup(repo => repo.GetbyId(testId))
            .Returns(GetTest().FirstOrDefault(p => p.Id == testId));
            var controller = new TestDBController(mock.Object, null);

            var result     = controller.GetId(testId);
            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsType <TestDB>(viewResult.Value);

            Assert.Equal("Vadym", model.Name);
            Assert.Equal("Tselikin", model.Surname);
            Assert.Equal(23, model.Age);
            Assert.Equal(testId, model.Id);
        }