Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public void PostLeaseCreatesLease()
        {
            //Arrange: Instantiate LeasesController so its methods can be called
            var leaseController = new LeasesController();

            //Act:
            // Create a LeaseModel object populated with test data,
            //  and call PostLease
            var newLease = 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(newLease);

            //Assert:
            // Verify that the HTTP result is CreatedAtRouteNegotiatedContentResult
            // Verify that the HTTP result body contains a nonzero lease ID
            Assert.IsInstanceOfType
                (result, typeof(CreatedAtRouteNegotiatedContentResult <LeaseModel>));
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            Assert.IsTrue(contentResult.Content.LeaseId != 0);

            // Delete the test lease
            result = leaseController.DeleteLease(contentResult.Content.LeaseId);
        }
        [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>));
        }