public void GetPropertyTest() { var actionResult = PropertyController.GetProperty(FakePropertyId).Result; Assert.AreEqual(((ObjectResult)actionResult).StatusCode, (int)System.Net.HttpStatusCode.OK); Assert.AreEqual(((ObjectResult)actionResult).Value.ToString().ToEntitySimple <Property>().IdProperty, FakeProperty.IdProperty); }
public void PutPropertyUpdatesProperty() { int propertyIdForTest = 1; string propertyNameForTest = "Lofts"; string address1ForTest = "234 Smith Street"; //Arrange: Instantiate PropertiesController so its methods can be called var propertyController = new PropertiesController(); //Act: // Get an existing property, change it, and // pass it to PutProperty IHttpActionResult result = propertyController.GetProperty(propertyIdForTest); OkNegotiatedContentResult <PropertyModel> contentResult = (OkNegotiatedContentResult <PropertyModel>)result; PropertyModel updatedProperty = (PropertyModel)contentResult.Content; string propertyNameBeforeUpdate = updatedProperty.Name; string propertyAddress1BeforeUpdate = updatedProperty.Address1; updatedProperty.Name = propertyNameForTest; updatedProperty.Address1 = address1ForTest; result = propertyController.PutProperty (updatedProperty.PropertyId, updatedProperty); //Assert: // Verify that HTTP status code is OK // Get the property and verify that it was updated var statusCode = (StatusCodeResult)result; Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent); result = propertyController.GetProperty(propertyIdForTest); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <PropertyModel>)); OkNegotiatedContentResult <PropertyModel> readContentResult = (OkNegotiatedContentResult <PropertyModel>)result; updatedProperty = (PropertyModel)readContentResult.Content; Assert.IsTrue(updatedProperty.Name == propertyNameForTest); Assert.IsTrue(updatedProperty.Address1 == address1ForTest); updatedProperty.Name = propertyNameBeforeUpdate; updatedProperty.Address1 = propertyAddress1BeforeUpdate; result = propertyController.PutProperty (updatedProperty.PropertyId, updatedProperty); }
[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)); }
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)); } }
public async Task GetsProperty() { // Arrange var property = new PropertyWithAlerts() { PropertyModel = _fixture.Create <PropertyModel>(), PersonAlerts = StubAlerts().Generate(5), LocationAlerts = StubAlerts().Generate(5), Contacts = _fixture.Create <List <ResidentContact> >() }; _getPropertyUseCaseMock.Setup(m => m.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(property); var query = new GetPropertyRequest { PropertyReference = property.PropertyModel.PropertyReference }; // Act var result = await _classUnderTest.GetProperty(query); var propertyResult = GetResultData <PropertyResponse>(result); var statusCode = GetStatusCode(result); // Assert statusCode.Should().Be(200); propertyResult.Property.PropertyReference.Should().Be(property.PropertyModel.PropertyReference); }
public void GetPropertyTest() { using (var controller = new PropertiesController()) { var httpResult = controller.GetProperty(1) as OkNegotiatedContentResult <PropertyModel>; Assert.IsNull(httpResult); } }
[TestMethod] //[1] | Get Property from ID public void GetPropertyFromIdReturnProperty() { //Arrange var PropertiesController = new PropertiesController(); //Act IHttpActionResult result = PropertiesController.GetProperty(1); //Assert //If action returns: NotFound() Assert.IsNotInstanceOfType(result, typeof(NotFoundResult)); //if Acction returns: Ok(); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <PropertyModel>)); }
internal void PropertyDelete() { PropertiesController pc = new PropertiesController(); PropertiesInfo prop = pc.GetProperty(Convert.ToInt32(Params["propertyid"]), PortalId); if (prop != null) { pc.DeleteProperty(PortalId, Convert.ToInt32(Params["propertyid"])); if (!(pc.ListProperties(PortalId, prop.ObjectType, prop.ObjectOwnerId).Count > 0)) { ForumController fc = new ForumController(); Forum fi = fc.GetForum(PortalId, ModuleId, prop.ObjectOwnerId, true); fi.HasProperties = false; fc.Forums_Save(PortalId, fi, false, false); } } }
public void GetPropertyReturnsProperty() { int PropertyIdForTest = 1; //Arrange: Instantiate PropertiesController so its methods can be called var propertyController = new PropertiesController(); //Act: Call the GetProperty method IHttpActionResult result = propertyController.GetProperty(PropertyIdForTest); //Assert: // Verify that HTTP status code is OK // Verify that returned property ID is correct Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <PropertyModel>)); OkNegotiatedContentResult <PropertyModel> contentResult = (OkNegotiatedContentResult <PropertyModel>)result; Assert.IsTrue(contentResult.Content.PropertyId == PropertyIdForTest); }
[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>)); }
private void UpdateSort() { int propertyId = -1; int sortOrder = -1; PropertiesController pc = new PropertiesController(); string props = Params["props"].ToString(); props = props.Remove(props.LastIndexOf("^")); foreach (string s in props.Split('^')) { if (!(string.IsNullOrEmpty(props))) { propertyId = Convert.ToInt32(s.Split('|')[0]); sortOrder = Convert.ToInt32(s.Split('|')[1]); PropertiesInfo pi = pc.GetProperty(propertyId, PortalId); if (pi != null) { pi.SortOrder = sortOrder; pc.SaveProperty(pi); } } } }
internal void PropertyDelete() { PropertiesController pc = new PropertiesController(); PropertiesInfo prop = pc.GetProperty(Convert.ToInt32(Params["propertyid"]), PortalId); if (prop != null) { pc.DeleteProperty(PortalId, Convert.ToInt32(Params["propertyid"])); if (! (pc.ListProperties(PortalId, prop.ObjectType, prop.ObjectOwnerId).Count > 0)) { ForumController fc = new ForumController(); Forum fi = fc.GetForum(PortalId, ModuleId, prop.ObjectOwnerId, true); fi.HasProperties = false; fc.Forums_Save(PortalId, fi, false, false); } } }
private void UpdateSort() { int propertyId = -1; int sortOrder = -1; PropertiesController pc = new PropertiesController(); string props = Params["props"].ToString(); props = props.Remove(props.LastIndexOf("^")); foreach (string s in props.Split('^')) { if (! (string.IsNullOrEmpty(props))) { propertyId = Convert.ToInt32(s.Split('|')[0]); sortOrder = Convert.ToInt32(s.Split('|')[1]); PropertiesInfo pi = pc.GetProperty(propertyId, PortalId); if (pi != null) { pi.SortOrder = sortOrder; pc.SaveProperty(pi); } } } }