public void GetReturnsNotFound()
        {
            // Arrange
            LandTypesController controller = new LandTypesController();

            // Act
            IHttpActionResult actionResult = controller.Get(-1);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
        public void GetByIdTest()
        {
            // arrange
            LandTypesController controller = new LandTypesController();

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

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(newId, contentResult.Content.Id);
            Assert.IsNotNull(newId, contentResult.Content.TimestampString);
            testItem.TimestampString = contentResult.Content.TimestampString;
        }
        public void DeleteTest()
        {
            // Arrange
            LandTypesController controller = new LandTypesController();

            // Act
            IHttpActionResult actionResult = controller.Delete(newId);
            var contentResult = actionResult as NegotiatedContentResult<LandTypeViewModel>;

            // Assert
            //Assert.IsInstanceOfType(actionResult, typeof(OkResult));
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(HttpStatusCode.Accepted, contentResult.StatusCode);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(testItem.Id, contentResult.Content.Id);
        }
        public void GetTest()
        {
            // arrange
            LandTypesController controller = new LandTypesController();

            // act
            var result = controller.Get();

            // assert
            Assert.IsInstanceOfType(result, typeof(IEnumerable<LandTypeViewModel>));
            Assert.IsTrue(result.Count() >= 0);
        }
        public void PutTest()
        {
            // arrange
            LandTypesController controller = new LandTypesController();

            // Act
            testItem.Id = newId;
            testItem.Type = "地目B";
            IHttpActionResult actionResult = controller.Put(newId, testItem);
            var contentResult = actionResult as NegotiatedContentResult<LandTypeViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(HttpStatusCode.Accepted, contentResult.StatusCode);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(testItem.Type, contentResult.Content.Type);
        }
        public void PostTest()
        {
            // arrange
            LandTypesController controller = new LandTypesController();

            // act
            IHttpActionResult actionResult = controller.Post(testItem);
            var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult<LandTypeViewModel>;
            newId = Convert.ToInt32(createdResult.RouteValues["Id"]);

            // Assert
            Assert.IsNotNull(createdResult);
            Assert.AreEqual("DefaultApi", createdResult.RouteName);
            Assert.IsTrue(newId > 0, "新增資料編號應大於0");
        }