[TestMethod] // [2] Update Tenant public void PutTenantUpdatesTenant() { //Arrange var tCtrl = new TenantsController(); var newTenant = new TenantModel { FirstName = "Test", LastName = "LastNameTest", Telephone = "12223334444", EmailAddress = "*****@*****.**" }; //The result of the Post Request IHttpActionResult result = tCtrl.PostTenant(newTenant); //Cast result of the content result so that I can gether information form the Contente CreatedAtRouteNegotiatedContentResult<TenantModel> contentResult = (CreatedAtRouteNegotiatedContentResult<TenantModel>)result; //Result containts the tenant I have just created result = tCtrl.GetTenant(contentResult.Content.TenantId); //Get tenant model from result OkNegotiatedContentResult<TenantModel> tenantResult = (OkNegotiatedContentResult<TenantModel>)result; //Act result = tCtrl.PutTenant(tenantResult.Content.TenantId, newTenant); //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 Tenant public void GetTenantFromIDReturnTenant() { //Arrange var Tctrl = new TenantsController(); //Act IHttpActionResult result = Tctrl.GetTenant(1); //If action returns: NotFound() Assert.IsNotInstanceOfType(result, typeof(NotFoundResult)); //if Acction returns: Ok(); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TenantModel>)); }
[TestMethod] // [4] Delete Tenant public void DeletePropertyDeleteProperty() { //Arrange var tctrl = new TenantsController(); //Act var newTenant = new TenantModel { FirstName = "Test", LastName = "LastNameTest", Telephone = "12223334444", EmailAddress = "*****@*****.**" }; //Add 'new tenant' to database using post //save returned value as result IHttpActionResult result = tctrl.PostTenant(newTenant); //Cast result as content result so I can gather intel on it CreatedAtRouteNegotiatedContentResult<TenantModel> contentResult = (CreatedAtRouteNegotiatedContentResult<TenantModel>)result; //Result contains the property I had just created result = tctrl.GetTenant(contentResult.Content.TenantId); //get tenantmodel from result OkNegotiatedContentResult<TenantModel> tenantResult = (OkNegotiatedContentResult<TenantModel>)result; //Act result = tctrl.DeleteTenant(contentResult.Content.TenantId); //Assert //If action returns not found Assert.IsNotInstanceOfType(result, typeof(NotFoundResult)); //If action retruns OK() Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TenantModel>)); }
public void GetTenantReturnsTenant() { int TenantIdForTest = 1; //Arrange: Instantiate TenantsController so its methods can be called var tenantController = new TenantsController(); //Act: Call the GetTenant method IHttpActionResult result = tenantController.GetTenant(TenantIdForTest); //Assert: // Verify that HTTP status code is OK // Verify that returned tenant ID is correct Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TenantModel>)); OkNegotiatedContentResult<TenantModel> contentResult = (OkNegotiatedContentResult<TenantModel>)result; Assert.IsTrue(contentResult.Content.TenantId == TenantIdForTest); }
public void PutTenantUpdatesTenant() { int tenantIdForTest = 1; string tenantFirstNameForTest = "Testy"; string tenantLastNameForTest = "Testerson"; //Arrange: Instantiate TenantsController so its methods can be called var tenantController = new TenantsController(); //Act: // Get an existing tenant, change it, and // pass it to PutTenant IHttpActionResult result = tenantController.GetTenant(tenantIdForTest); OkNegotiatedContentResult<TenantModel> contentResult = (OkNegotiatedContentResult<TenantModel>)result; TenantModel updatedTenant = (TenantModel)contentResult.Content; string tenantFirstNameBeforeUpdate = updatedTenant.FirstName; string tenantLastNameBeforeUpdate = updatedTenant.LastName; updatedTenant.FirstName = tenantFirstNameForTest; updatedTenant.LastName = tenantLastNameForTest; result = tenantController.PutTenant (updatedTenant.TenantId, updatedTenant); //Assert: // Verify that HTTP status code is OK // Get the tenant and verify that it was updated var statusCode = (StatusCodeResult)result; Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent); result = tenantController.GetTenant(tenantIdForTest); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TenantModel>)); OkNegotiatedContentResult<TenantModel> readContentResult = (OkNegotiatedContentResult<TenantModel>)result; updatedTenant = (TenantModel)readContentResult.Content; Assert.IsTrue(updatedTenant.FirstName == tenantFirstNameForTest); Assert.IsTrue(updatedTenant.LastName == tenantLastNameForTest); updatedTenant.FirstName = tenantFirstNameBeforeUpdate; updatedTenant.LastName = tenantLastNameBeforeUpdate; result = tenantController.PutTenant (updatedTenant.TenantId, updatedTenant); }