Ejemplo n.º 1
0
        public void PutLeaseUpdatesLease()
        {
            int     leaseIdForTest   = 1;
            decimal leaseRentForTest = 987654321;

            Constants.RentPeriod leaseTypeForTest = Constants.RentPeriod.Daily;

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

            //Act:
            // Get an existing lease, change it, and
            //  pass it to PutLease

            IHttpActionResult result = leaseController.GetLease(leaseIdForTest);
            OkNegotiatedContentResult <LeaseModel> contentResult =
                (OkNegotiatedContentResult <LeaseModel>)result;
            LeaseModel updatedLease = (LeaseModel)contentResult.Content;

            decimal leaseRentBeforeUpdate = updatedLease.Rent;

            Constants.RentPeriod leaseTypeBeforeUpdate = updatedLease.LeaseType;

            updatedLease.Rent      = leaseRentForTest;
            updatedLease.LeaseType = leaseTypeForTest;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);

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

            var statusCode = (StatusCodeResult)result;

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

            result = leaseController.GetLease(leaseIdForTest);

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

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

            updatedLease = (LeaseModel)readContentResult.Content;

            Assert.IsTrue(updatedLease.Rent == leaseRentForTest);
            Assert.IsTrue(updatedLease.LeaseType == leaseTypeForTest);

            updatedLease.Rent      = leaseRentBeforeUpdate;
            updatedLease.LeaseType = leaseTypeBeforeUpdate;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);
        }
        [TestMethod] // [2] Update Lease
        public void PutLeaseUpdateLease()
        {
            //Arrange
            var lCtrl = new LeasesController();

            var newLease = new LeaseModel
            {
                PropertyId = 1,
                TenantId   = 1,
                StartDate  = DateTime.Now,
                Rent       = 2000
            };

            //The result of the PostRequest
            IHttpActionResult result = lCtrl.PostLease(newLease);

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

            //REsult containts the property I had just created
            result = lCtrl.GetLease(contentResult.Content.LeaseId);

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

            //Act
            result = lCtrl.PutLease(propertyResult.Content.LeaseId, newLease);

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