[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));
        }
        public void DeletePropertyDeletesProperty()
        {
            //Arrange:
            // Instantiate PropertiesController so its methods can be called
            // Create a new property to be deleted, and get its property ID

            var propertyController = new PropertiesController();

            var property = new PropertyModel
            {
                Name = "Office Space",
                Address1 = "101 Broadway",
                City = "San Francisco",
                State = "CA"
            };
            IHttpActionResult propertyResult = propertyController.PostProperty(property);
            CreatedAtRouteNegotiatedContentResult<PropertyModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<PropertyModel>)propertyResult;

            int propertyIdToDelete = contentResult.Content.PropertyId;

            // Add a lease corresponding to the property
            int createdLeaseId;
            using (var leaseController = new LeasesController())
            {
                var lease = new LeaseModel
                {
                    CreatedDate = new DateTime(2014, 9, 30),
                    PropertyId = propertyIdToDelete,
                    TenantId = 1,
                    StartDate = new DateTime(2015, 1, 30),
                    Rent = 800,
                    LeaseType = Constants.RentPeriod.Monthly
                };
                IHttpActionResult leaseResult = leaseController.PostLease(lease);
                CreatedAtRouteNegotiatedContentResult<LeaseModel> leaseContentResult =
                    (CreatedAtRouteNegotiatedContentResult<LeaseModel>)leaseResult;

                createdLeaseId = leaseContentResult.Content.LeaseId;
            }

            //Act: Call DeleteProperty
            propertyResult = propertyController.DeleteProperty(propertyIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted property returns result not found
            Assert.IsInstanceOfType(propertyResult, typeof(OkNegotiatedContentResult<PropertyModel>));

            propertyResult = propertyController.GetProperty(propertyIdToDelete);
            Assert.IsInstanceOfType(propertyResult, typeof(NotFoundResult));

            // Verify that the lease created above was deleted
            using (var leaseController = new LeasesController())
            {
                IHttpActionResult leaseResult = leaseController.GetLease(createdLeaseId);
                Assert.IsInstanceOfType(leaseResult, typeof(NotFoundResult));
            }
        }
        [TestMethod] // [0] | Get Properties
        public void GetPropertiesReturnProperties()
        {
            //Arrange
            //Properties Go Here
            var PropertiesController = new PropertiesController();

            //Act
            //Call the mthod in question that needs to be tested
            IEnumerable<PropertyModel> property = PropertiesController.GetProperties();

            //Assert
            Assert.IsTrue(property.Count() > 0);

        }
        [TestMethod] //[1] | Get Property from ID
        public void GetPropertyFromIdReturnProperty()
        {
            //Arrange
            var PropertiesController = new PropertiesController();

            //Act
            IHttpActionResult result = PropertiesController.GetProperty(1);

            //Assert
            //If action returns: NotFound()
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));

            //if Acction returns: Ok();
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PropertyModel>));
           
        }
        public void GetPropertyReturnsProperty()
        {
            int PropertyIdForTest = 1;

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

            //Act: Call the GetProperty method
            IHttpActionResult result = propertyController.GetProperty(PropertyIdForTest);

            //Assert:
            // Verify that HTTP status code is OK
            // Verify that returned property ID is correct
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PropertyModel>));

            OkNegotiatedContentResult<PropertyModel> contentResult =
                (OkNegotiatedContentResult<PropertyModel>)result;
            Assert.IsTrue(contentResult.Content.PropertyId == PropertyIdForTest);
        }
        public void GetPropertiesReturnsProperties()
        {
            //Arrange: Instantiate PropertiesController so its methods can be called
            using (var propertyController = new PropertiesController())
            {
                //Act: Call the GetProperties method
                IEnumerable<PropertyModel> properties = propertyController.GetProperties();

                //Assert: Verify that an array was returned with at least one element
                Assert.IsTrue(properties.Count() > 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);
        }
        public void PostPropertyCreatesProperty()
        {
            //Arrange: Instantiate PropertiesController so its methods can be called
            var propertyController = new PropertiesController();

            //Act:
            // Create a PropertyModel object populated with test data,
            //  and call PostProperty
            var newProperty = new PropertyModel
            {
                Name="Huge Penthouse",
                Address1="Some address",
                City="New York",
                State="NY"
            };
            IHttpActionResult result = propertyController.PostProperty(newProperty);

            //Assert:
            // Verify that the HTTP result is CreatedAtRouteNegotiatedContentResult
            // Verify that the HTTP result body contains a nonzero property ID
            Assert.IsInstanceOfType
                (result, typeof(CreatedAtRouteNegotiatedContentResult<PropertyModel>));
            CreatedAtRouteNegotiatedContentResult<PropertyModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<PropertyModel>)result;
            Assert.IsTrue(contentResult.Content.PropertyId != 0);

            // Delete the test property
            result = propertyController.DeleteProperty(contentResult.Content.PropertyId);
        }
        [TestMethod] //[3] | Create Property
        public void PostPropertyCreatesProperty()
        {
            //Arrange
            var propertiesController = new PropertiesController();

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

            //Result of the Post Request
            IHttpActionResult result = propertiesController.PostProperty(newProp);

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

            //Cast
            CreatedAtRouteNegotiatedContentResult<PropertyModel> contentResult = (CreatedAtRouteNegotiatedContentResult<PropertyModel>)result;

            Assert.IsTrue(contentResult.Content.PropertyId != 0);
        }
        [TestMethod] // [4] | Delete Property
        public void DeletePropertyDeleteProperty()
        {
            //Arrange
            var propertiesController = new PropertiesController();

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

            //Add 'new property to database using post' 
            //Save returned value as RESULT
            IHttpActionResult result = propertiesController.PostProperty(dbProp);

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

            //Result contains 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.DeleteProperty(contentResult.Content.PropertyId);

            //Assert

            //If action returns not found
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));

            //If action retruns OK()
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PropertyModel>));



        }