示例#1
0
        public void GetProperties_All_Success(SModel.PropertyFilterModel filter)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <SearchController>(Permissions.PropertyView);

            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 <PropertyFilter>())).Returns(page);

            // Act
            var result = controller.GetProperties(filter);

            // Assert
            var actionResult   = Assert.IsType <JsonResult>(result);
            var actualResult   = Assert.IsType <PageModel <SModel.PropertyModel> >(actionResult.Value);
            var expectedResult = mapper.Map <SModel.PropertyModel[]>(properties);

            Assert.Equal(expectedResult, actualResult.Items, new DeepPropertyCompare());
            service.Verify(m => m.Property.GetPage(It.IsAny <PropertyFilter>()), Times.Once());
        }
示例#2
0
        public void GetProperties_OnlyBuildings_Success(SModel.PropertyFilterModel filter)
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <SearchController>(Permissions.PropertyView);

            var building1 = new Entity.Building()
            {
                Id = 1, PropertyTypeId = 1
            };
            var building2 = new Entity.Building()
            {
                Id = 2, PropertyTypeId = 1
            };
            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 <SModel.PropertyModel[]>(actionResult.Value);
            var expectedResult = mapper.Map <SModel.PropertyModel[]>(buildings);

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.Property.Get(It.IsAny <AllPropertyFilter>()), Times.Once());
        }
示例#3
0
        public void GetPropertiesPage_Success(SModel.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 <SModel.PropertyModel> >(actionResult.Value);
            var expectedResult = mapper.Map <SModel.PropertyModel[]>(parcels).JoinAll(mapper.Map <SModel.PropertyModel[]>(buildings));

            Assert.Equal(expectedResult, actualResult.Items, new ShallowPropertyCompare());
            service.Verify(m => m.Property.GetPage(It.IsAny <Entity.Models.AllPropertyFilter>()), Times.Once());
        }
示例#4
0
        public void GetProperties_All_Success(SModel.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)
            {
                PropertyTypeId = 1
            };
            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 <SModel.PropertyModel[]>(actionResult.Value);
            var expectedResult = mapper.Map <SModel.PropertyModel[]>(parcels).Concat(mapper.Map <SModel.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);
        }