コード例 #1
0
        public void GetReturnsNotFound()
        {
            // Arrange
            var mockRepository = new Mock<IProductRepository>();
            var controller = new Products2Controller(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Get(10);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
コード例 #2
0
        public void GetReturnsProductWithSameId()
        {
            // Arrange
            var mockRepository = new Mock<IProductRepository>();
            mockRepository.Setup(x => x.GetById(42))
                .Returns(new Product { Id = 42 });

            var controller = new Products2Controller(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Get(42);
            var contentResult = actionResult as OkNegotiatedContentResult<Product>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(42, contentResult.Content.Id);
        }