Ejemplo n.º 1
0
        public void PutPropertyUpdatesProperty()
        {
            int    propertyIdForTest   = 1;
            string propertyNameForTest = "Lofts";
            string address1ForTest     = "234 Smith Street";

            //Arrange: Instantiate PropertiesController so its methods can be called
            var propertyController = new PropertiesController();

            //Act:
            // Get an existing property, change it, and
            //  pass it to PutProperty

            IHttpActionResult result = propertyController.GetProperty(propertyIdForTest);
            OkNegotiatedContentResult <PropertyModel> contentResult =
                (OkNegotiatedContentResult <PropertyModel>)result;
            PropertyModel updatedProperty = (PropertyModel)contentResult.Content;

            string propertyNameBeforeUpdate     = updatedProperty.Name;
            string propertyAddress1BeforeUpdate = updatedProperty.Address1;

            updatedProperty.Name     = propertyNameForTest;
            updatedProperty.Address1 = address1ForTest;

            result = propertyController.PutProperty
                         (updatedProperty.PropertyId, updatedProperty);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the property and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = propertyController.GetProperty(propertyIdForTest);

            Assert.IsInstanceOfType(result,
                                    typeof(OkNegotiatedContentResult <PropertyModel>));

            OkNegotiatedContentResult <PropertyModel> readContentResult =
                (OkNegotiatedContentResult <PropertyModel>)result;

            updatedProperty = (PropertyModel)readContentResult.Content;

            Assert.IsTrue(updatedProperty.Name == propertyNameForTest);
            Assert.IsTrue(updatedProperty.Address1 == address1ForTest);

            updatedProperty.Name     = propertyNameBeforeUpdate;
            updatedProperty.Address1 = propertyAddress1BeforeUpdate;

            result = propertyController.PutProperty
                         (updatedProperty.PropertyId, updatedProperty);
        }
        [TestMethod] //[2] | Update Property
        public void PutPropertyUpdatesProperty()
        {
            //Arrange
            var propertiesController = new PropertiesController();

            var newProp = new PropertyModel
            {
                Name     = "Wonder Mansion",
                Address1 = "122 Wonka Way",
                Address2 = "",
                City     = "Golden Coast",
                Zip      = "23123",
                State    = "CA"
            };


            //The result of the PostRequest
            IHttpActionResult result = propertiesController.PostProperty(newProp);

            //Cast result as the content result so I can gather information from Content Result
            CreatedAtRouteNegotiatedContentResult <PropertyModel> contentResult = (CreatedAtRouteNegotiatedContentResult <PropertyModel>)result;

            //REsult containts the property I had just created
            result = propertiesController.GetProperty(contentResult.Content.PropertyId);

            //GET PropertyModel from Result
            OkNegotiatedContentResult <PropertyModel> propertyResult = (OkNegotiatedContentResult <PropertyModel>)result;

            //Act
            result = propertiesController.PutProperty(propertyResult.Content.PropertyId, newProp);

            //Assert
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
        }