Exemple #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);
        }
Exemple #2
0
        public void DeleteLeaseDeletesLease()
        {
            //Arrange:
            // Instantiate LeasesController so its methods can be called
            // Create a new lease to be deleted, and get its lease ID
            var leaseController = new LeasesController();

            var lease = new LeaseModel
            {
                CreatedDate = new DateTime(2014, 9, 30),
                PropertyId  = 1,
                TenantId    = 1,
                StartDate   = new DateTime(2015, 1, 30),
                Rent        = 800,
                LeaseType   = Constants.RentPeriod.Monthly
            };
            IHttpActionResult result = leaseController.PostLease(lease);
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            int leaseIdToDelete = contentResult.Content.LeaseId;


            //Act: Call DeleteLease
            result = leaseController.DeleteLease(leaseIdToDelete);

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

            result = leaseController.GetLease(leaseIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Exemple #3
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));
            }
        }
        [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));
        }
        public void DeleteTenantDeletesTenant()
        {
            //Arrange:
            // Instantiate TenantsController so its methods can be called
            // Create a new tenant to be deleted, and get its tenant ID
            var tenantController = new TenantsController();

            var tenant = new TenantModel
            {
                FirstName    = "Testy",
                LastName     = "Testering",
                Telephone    = "555-1212",
                EmailAddress = "*****@*****.**"
            };
            IHttpActionResult result = tenantController.PostTenant(tenant);
            CreatedAtRouteNegotiatedContentResult <TenantModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <TenantModel>)result;

            int tenantIdToDelete = contentResult.Content.TenantId;

            // Add a lease corresponding to the tenant
            int createdLeaseId;

            using (var leaseController = new LeasesController())
            {
                var lease = new LeaseModel
                {
                    CreatedDate = new DateTime(2014, 9, 30),
                    PropertyId  = 1,
                    TenantId    = tenantIdToDelete,
                    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 DeleteTenant
            result = tenantController.DeleteTenant(tenantIdToDelete);

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

            result = tenantController.GetTenant(tenantIdToDelete);
            Assert.IsInstanceOfType(result, 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] // [1] | Get Lease
        public void GetLeaseReturnLease()
        {
            //Arrange
            var Lctrl = new LeasesController();

            //Act
            IHttpActionResult result = Lctrl.GetLease(1);

            //Assert
            //If action returns: NotFound()
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <LeaseModel>));

            //if Acction returns: Ok();
            OkNegotiatedContentResult <LeaseModel> contentReesult = (OkNegotiatedContentResult <LeaseModel>)result;

            Assert.IsTrue(contentReesult.Content.LeaseId == 1);
        }
Exemple #7
0
        public void GetLeaseReturnsLease()
        {
            int LeaseIdForTest = 1;

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

            //Act: Call the GetLease method
            IHttpActionResult result = leaseController.GetLease(LeaseIdForTest);

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

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

            Assert.IsTrue(contentResult.Content.LeaseId == LeaseIdForTest);
        }
        [TestMethod] // [4] Delete Lease
        public void DeleteLeaseDeleteLease()
        {
            //Arrange
            var lCtrl = new LeasesController();

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

            //Add 'new property to database using post'
            //Save returned value as RESULT
            IHttpActionResult result = lCtrl.PostLease(newLease);

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

            //Result contains the property I had just created
            result = lCtrl.GetLease(contentResult.Content.PropertyId);

            //Get PropertyModel from result
            OkNegotiatedContentResult <LeaseModel> leaseResult = (OkNegotiatedContentResult <LeaseModel>)result;

            //Act
            result = lCtrl.DeleteLease(contentResult.Content.LeaseId);

            //Assert

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

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