コード例 #1
0
ファイル: OrderControllerTest.cs プロジェクト: mkwie/mobRepo
        public void FindOrder_Test()
        {

            var mockRepo = new Mock<IOrderRepository>();
            int id = 5;
            int noid = 33;

            mockRepo.Setup(s => s.Find(5)).Returns(new OrderDTO() { Id = id });

            var controller = new OrderController(mockRepo.Object);

            var getallResult = controller.Get(id);

            Assert.IsInstanceOfType(getallResult, typeof(OkNegotiatedContentResult<OrderDTO>));

            var worker = getallResult as OkNegotiatedContentResult<OrderDTO>;

            Assert.IsTrue(worker.Content.Id == id);

            var getresults2 = controller.Get(noid);
            Assert.IsInstanceOfType(getresults2, typeof(NotFoundResult));

        }
コード例 #2
0
ファイル: OrderControllerTest.cs プロジェクト: mkwie/mobRepo
        public void GetAllOrders_Test()
        {

            var mockRepo = new Mock<IOrderRepository>();
            mockRepo.Setup(s => s.GetAll()).Returns(new List<OrderDTO>() { new OrderDTO() });

            var controller = new OrderController(mockRepo.Object);

            var getallResult = controller.Get();

            Assert.IsInstanceOfType(getallResult, typeof(OkNegotiatedContentResult<IEnumerable<OrderDTO>>));

            var orders = getallResult as OkNegotiatedContentResult<IEnumerable<OrderDTO>>;
            Assert.IsTrue(orders.Content.Count() == 1);

        }