public void ExportPropertiesAllFields_ExcelX_Success(PropertyFilterModel filter) { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <PropertyController>(Permissions.PropertyView); var headers = helper.GetService <Mock <Microsoft.AspNetCore.Http.IHeaderDictionary> >(); headers.Setup(m => m["Accept"]).Returns(ContentTypes.CONTENT_TYPE_EXCELX); var parcel = new Entity.Parcel(1, 51, 25); var parcels = new[] { parcel }; var building = new Entity.Building(parcel, 51, 25); var buildings = new[] { building }; var service = helper.GetService <Mock <IPimsService> >(); var mapper = helper.GetService <IMapper>(); var items = parcels.Select(p => new Entity.Views.Property(p)).Concat(buildings.Select(b => new Entity.Views.Property(b))); var page = new Paged <Entity.Views.Property>(items, filter.Page, filter.Quantity); service.Setup(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>())).Returns(page); // Act var result = controller.ExportPropertiesAllFields(filter); // Assert var actionResult = Assert.IsType <FileStreamResult>(result); Assert.Equal(ContentTypes.CONTENT_TYPE_EXCELX, actionResult.ContentType); Assert.NotNull(actionResult.FileDownloadName); Assert.True(actionResult.FileStream.Length > 0); service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>()), Times.Once()); }
public void GetProperties_OnlyBuildings_Success(PropertyFilterModel filter) { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <SearchController>(Permissions.PropertyView); var building1 = new Entity.Building() { Id = 1 }; var building2 = new Entity.Building() { Id = 2 }; var buildings = new[] { building1, building2 }; var service = helper.GetService <Mock <IPimsService> >(); var mapper = helper.GetService <IMapper>(); var items = buildings.Select(p => new ProjectProperty(new Entity.Views.Property(p))); service.Setup(m => m.Property.Get(It.IsAny <AllPropertyFilter>())).Returns(items); // Act var result = controller.GetProperties(filter); // Assert var actionResult = Assert.IsType <JsonResult>(result); var actualResult = Assert.IsType <PropertyModel[]>(actionResult.Value); var expectedResult = mapper.Map <PropertyModel[]>(buildings); Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare()); service.Verify(m => m.Property.Get(It.IsAny <AllPropertyFilter>()), Times.Once()); }
public void GetPropertiesPage_Success(PropertyFilterModel filter, bool includeParcels, bool includeBuildings) { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <SearchController>(Permissions.PropertyView); var parcel = EntityHelper.CreateParcel(1, 51, 25); var parcels = new[] { parcel }; var building = EntityHelper.CreateBuilding(parcel, 51, "p1", "l1"); var buildings = new[] { building }; var service = helper.GetService <Mock <IPimsService> >(); var mapper = helper.GetService <IMapper>(); var items = parcels.Select(p => new Entity.Views.Property(p)).Concat(buildings.Select(b => new Entity.Views.Property(b))); var page = new Paged <Entity.Views.Property>(items, filter.Page, filter.Quantity); service.Setup(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>())).Returns(page); // Act var result = controller.GetPropertiesPage(filter); // Assert var actionResult = Assert.IsType <JsonResult>(result); var actualResult = Assert.IsType <Api.Models.PageModel <PropertyModel> >(actionResult.Value); var expectedResult = mapper.Map <PropertyModel[]>(parcels).JoinAll(mapper.Map <PropertyModel[]>(buildings)); Assert.Equal(expectedResult, actualResult.Items, new ShallowPropertyCompare()); service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>()), Times.Once()); }
public void ExportProperties_Csv_Success(PropertyFilterModel filter) { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <PropertyController>(Permissions.PropertyView); var headers = helper.GetService <Mock <Microsoft.AspNetCore.Http.IHeaderDictionary> >(); headers.Setup(m => m["Accept"]).Returns(ContentTypes.CONTENT_TYPE_CSV); var properties = new[] { EntityHelper.CreateProperty(1) }; var service = helper.GetService <Mock <IPimsRepository> >(); var mapper = helper.GetService <IMapper>(); var page = new Paged <Entity.PimsProperty>(properties, filter.Page, filter.Quantity); service.Setup(m => m.Property.GetPage(It.IsAny <Entity.Models.PropertyFilter>())).Returns(page); // Act var result = controller.ExportProperties(filter); // Assert var actionResult = Assert.IsType <ContentResult>(result); var actualResult = Assert.IsType <string>(actionResult.Content); Assert.Equal(ContentTypes.CONTENT_TYPE_CSV, actionResult.ContentType); service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.PropertyFilter>()), Times.Once()); }
public void GetProperties_All_Success(PropertyFilterModel filter, bool includeParcels, bool includeBuildings) { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <SearchController>(Permissions.PropertyView); var parcel = new Entity.Parcel(1, 51, 25); var parcels = new[] { parcel }; var building = new Entity.Building(parcel, 51, 25); var buildings = new[] { building }; var service = helper.GetService <Mock <IPimsService> >(); var mapper = helper.GetService <IMapper>(); var items = parcels.Select(p => new Entity.Views.Property(p)) .Concat(buildings.Select(b => new Entity.Views.Property(b))).Select(x => new ProjectProperty(x)); service.Setup(m => m.Property.Get(It.IsAny <AllPropertyFilter>())).Returns(items); // Act var result = controller.GetProperties(filter); // Assert var actionResult = Assert.IsType <JsonResult>(result); var actualResult = Assert.IsType <PropertyModel[]>(actionResult.Value); var expectedResult = mapper.Map <PropertyModel[]>(parcels).Concat(mapper.Map <PropertyModel[]>(buildings)); Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare()); service.Verify(m => m.Property.Get(It.IsAny <AllPropertyFilter>()), Times.Once()); Assert.Equal(includeParcels, filter.IncludeParcels); Assert.Equal(includeBuildings, filter.IncludeBuildings); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyBadgeViewModel"/> class. /// </summary> public PropertyBadgeViewModel(PropertyFilterModel propertyFilter, string additionalClass, string imageClass, bool inludeAddRemoveIcon = true, bool showCount = true) { this.PropertyFilter = propertyFilter; this.AdditionalClass = additionalClass; this.ImageClass = imageClass; this.InludeAddRemoveIcon = inludeAddRemoveIcon; this.ShowCount = showCount; }
public IActionResult GetProperties([FromBody] PropertyFilterModel filter) { filter.ThrowBadRequestIfNull($"The request must include a filter."); if (!filter.IsValid()) { throw new BadRequestException("Property filter must contain valid values."); } var properties = _pimsService.Property.Get((AllPropertyFilter)filter).ToArray(); return(new JsonResult(_mapper.Map <PropertyModel[]>(properties).ToArray())); }
public IActionResult GetPropertyNames([FromQuery] PropertyFilterModel filter) { filter.ThrowBadRequestIfNull($"The request must include a filter."); if (!filter.IsValid()) { throw new BadRequestException("Property filter must contain valid values."); } var propertyNames = _pimsService.Property.GetNames((AllPropertyFilter)filter); return(new JsonResult(propertyNames)); }
public IActionResult GetProperties([FromBody] PropertyFilterModel filter) { filter.ThrowBadRequestIfNull($"The request must include a filter."); if (!filter.IsValid()) { throw new BadRequestException("Property filter must contain valid values."); } var page = _pimsService.Property.GetPage((PropertyFilter)filter); var result = _mapper.Map <BModel.PageModel <Models.Search.PropertyModel> >(page); return(new JsonResult(result)); }
public void ExportProperties_NoAcceptHeader_BadRequest() { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <PropertyController>(Permissions.PropertyView); var service = helper.GetService <Mock <IPimsRepository> >(); var filter = new PropertyFilterModel() { }; // Act // Assert Assert.Throws <BadRequestException>(() => controller.ExportProperties(filter)); service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.PropertyFilter>()), Times.Never()); }
public void ExportProperties_InvalidAcceptHeader_BadRequest() { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <PropertyController>(Permissions.PropertyView); var service = helper.GetService <Mock <IPimsRepository> >(); var headers = helper.GetService <Mock <Microsoft.AspNetCore.Http.IHeaderDictionary> >(); headers.Setup(m => m["Accept"]).Returns("invalid"); var filter = new PropertyFilterModel() { }; // Act // Assert Assert.Throws <BadRequestException>(() => controller.ExportProperties(filter)); service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.PropertyFilter>()), Times.Never()); }