コード例 #1
0
        [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);
        }
コード例 #2
0
        [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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
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>));
        }