Пример #1
0
        /// <summary>
        /// Get an array of buildings within the specified filter.
        /// Will not return sensitive buildings unless the user has the `sensitive-view` claim and belongs to the owning agency.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable <Building> Get(BuildingFilter filter)
        {
            this.User.ThrowIfNotAuthorized(Permissions.PropertyView);
            var query = this.Context.GenerateQuery(this.User, filter);

            return(query.ToArray());
        }
Пример #2
0
        public void BuildingFilter_Constructor_03()
        {
            // Arrange
            var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?page=2&quantity=3&pid=323423&zoning=zone&zoningPotential=potential&minLandArea=343&maxLandArea=444&propertyType=Land&constructionTypeId=4&predominateUseId=4&floorCount=4&tenancy=ten&minRentableArea=343&maxRentableArea=444&sort=one,two");

            // Act
            var filter = new BuildingFilter(query);

            // Assert
            filter.Page.Should().Be(2);
            filter.Quantity.Should().Be(3);
            filter.PID.Should().Be("323423");
            filter.Zoning.Should().Be("zone");
            filter.ZoningPotential.Should().Be("potential");
            filter.MinLandArea.Should().Be(343);
            filter.MaxLandArea.Should().Be(444);
            filter.PropertyType.Should().Be(PropertyTypes.Land);
            filter.ConstructionTypeId.Should().Be(4);
            filter.PredominateUseId.Should().Be(4);
            filter.FloorCount.Should().Be(4);
            filter.Tenancy.Should().Be("ten");
            filter.MinRentableArea.Should().Be(343);
            filter.MaxRentableArea.Should().Be(444);
            filter.Sort.Should().BeEquivalentTo(new[] { "one", "two" });
        }
Пример #3
0
        public void GenerateQuery(BuildingFilter filter, int expectedResult)
        {
            // Arrange
            var helper  = new TestHelper();
            var user    = helper.CreateForPermission(Permissions.AdminProperties);
            var context = helper.CreatePimsContext("building-filter", user);

            // Only seed the first time the test runs.
            if (!context.Agencies.Any())
            {
                context.SeedDatabase();
                var parcel = context.CreateParcel(1234);
                parcel.Zoning          = "Zoning";
                parcel.ZoningPotential = "ZoningPotential";
                var buildings = context.CreateBuildings(null, 1, 10);
                buildings.Next(0).ProjectNumbers     = "4444,1234";
                buildings.Next(1).BuildingFloorCount = 1;
                buildings.Next(2).Parcels.Add(new ParcelBuilding(parcel, buildings.Next(2)));
                buildings.Next(3).Address.Address1 = "1243 St";
                context.SaveChanges();
            }

            // Act
            var query  = context.GenerateQuery(user, filter);
            var result = query.ToArray();

            // Assert
            Assert.NotNull(query);
            result.Count().Should().Be(expectedResult);
        }
Пример #4
0
        public void BuildingFilter_Constructor_02_NoAgency()
        {
            // Arrange
            var address            = "address";
            var constructionTypeId = 2;
            var predominateUseId   = 3;
            var floorCount         = 4;
            var tenancy            = "tenancy";
            var minRentableArea    = 5.12f;
            var maxRentableArea    = 6.55f;
            var minMarketValue     = 7.44m;
            var maxMarketValue     = 8.23m;
            var minAssessedValue   = 9.1m;
            var maxAssessedValue   = 10.2m;
            var sort = new[] { "one", "two " };

            // Act
            var filter = new BuildingFilter(address, (int?)null, constructionTypeId, predominateUseId, floorCount, tenancy, minRentableArea, maxRentableArea, minMarketValue, maxMarketValue, minAssessedValue, maxAssessedValue, sort);

            // Assert
            filter.Address.Should().Be(address);
            filter.Agencies.Should().BeNull();
            filter.ConstructionTypeId.Should().Be(constructionTypeId);
            filter.PredominateUseId.Should().Be(predominateUseId);
            filter.FloorCount.Should().Be(floorCount);
            filter.Tenancy.Should().Be(tenancy);
            filter.MinRentableArea.Should().Be(minRentableArea);
            filter.MaxRentableArea.Should().Be(maxRentableArea);
            filter.MinMarketValue.Should().Be(minMarketValue);
            filter.MaxMarketValue.Should().Be(maxMarketValue);
            filter.MinAssessedValue.Should().Be(minAssessedValue);
            filter.MaxAssessedValue.Should().Be(maxAssessedValue);
            filter.Sort.Should().BeEquivalentTo(sort);
        }
Пример #5
0
        /// <summary>
        /// Get an array of buildings within the specified filter.
        /// Will not return sensitive buildings unless the user has the `sensitive-view` claim and belongs to the owning agency.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Paged <Building> GetPage(BuildingFilter filter)
        {
            this.User.ThrowIfNotAuthorized(Permissions.PropertyView);
            var query = this.Context.GenerateQuery(this.User, filter);
            var total = query.Count();
            var items = query.Skip((filter.Page - 1) * filter.Quantity).Take(filter.Quantity);

            return(new Paged <Building>(items, filter.Page, filter.Quantity, total));
        }
Пример #6
0
        public void BuildingFilter_Base_IsValid()
        {
            // Arrange
            var filter = new BuildingFilter();

            // Act
            var result = filter.IsValid();

            // Assert
            result.Should().BeTrue();
        }
Пример #7
0
        public void BuildingFilter_False()
        {
            // Arrange
            var query  = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?page=0");
            var filter = new BuildingFilter(query);

            // Act
            var result = filter.IsValid();

            // Assert
            result.Should().BeFalse();
        }
Пример #8
0
        public void BuildingFilter_IsValid()
        {
            // Arrange
            var query  = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?constructionTypeId=3");
            var filter = new BuildingFilter(query);

            // Act
            var result = filter.IsValid();

            // Assert
            result.Should().BeTrue();
        }
Пример #9
0
        public void Get_Buildings_NotAuthorized()
        {
            // Arrange
            var helper = new TestHelper();
            var user   = PrincipalHelper.CreateForPermission();
            var filter = new BuildingFilter(50, 25, 50, 20);

            var service = helper.CreateService <BuildingService>(user);

            // Act
            // Assert
            Assert.Throws <NotAuthorizedException>(() =>
                                                   service.Get(1, 10, null));
        }
Пример #10
0
        public void BuildingFilter_Constructor_01()
        {
            // Arrange
            var nelat = 4.454;
            var nelng = 3.434;
            var swlat = 2.233;
            var swlng = 5.565;

            // Act
            var filter = new BuildingFilter(nelat, nelng, swlat, swlng);

            // Assert
            filter.NELatitude.Should().Be(nelat);
            filter.NELongitude.Should().Be(nelng);
            filter.SWLatitude.Should().Be(swlat);
            filter.SWLongitude.Should().Be(swlng);
        }
Пример #11
0
        public void BuildingFilter_Default_Constructor()
        {
            // Arrange
            // Act
            var filter = new BuildingFilter();

            // Assert
            filter.Page.Should().Be(1);
            filter.Quantity.Should().Be(10);
            filter.PID.Should().BeNull();
            filter.Zoning.Should().BeNull();
            filter.ZoningPotential.Should().BeNull();
            filter.MinLandArea.Should().BeNull();
            filter.MaxLandArea.Should().BeNull();
            filter.ConstructionTypeId.Should().BeNull();
            filter.PredominateUseId.Should().BeNull();
            filter.FloorCount.Should().BeNull();
            filter.Tenancy.Should().BeNull();
            filter.MinRentableArea.Should().BeNull();
            filter.MaxRentableArea.Should().BeNull();
        }
Пример #12
0
        public void Get_Page_AsAdmin(BuildingFilter filter, int expectedCount)
        {
            // Arrange
            var helper = new TestHelper();
            var user   = PrincipalHelper.CreateForPermission(Permissions.PropertyView, Permissions.AdminProperties);

            using var init = helper.InitializeDatabase(user);
            var parcel1   = init.CreateParcel(1);
            var buildings = init.CreateBuildings(parcel1, 10, 20);

            buildings.Next(0).Location.X                 = -123.720810;
            buildings.Next(0).Location.Y                 = 48.529338;
            buildings.Next(1).Agency                     = init.Agencies.Find(3);
            buildings.Next(1).AgencyId                   = 3;
            buildings.Next(2).ClassificationId           = 2;
            buildings.Next(3).Description                = "-DescriptionTest-";
            buildings.Next(4).BuildingTenancy            = "-BuildingTenancy-";
            buildings.Next(5).BuildingConstructionTypeId = 2;
            buildings.Next(6).BuildingPredominateUseId   = 2;
            buildings.Next(7).RentableArea               = 100;
            buildings.Next(8).RentableArea               = 50;

            var parcel2 = init.CreateParcel(2);

            parcel2.Address.AdministrativeArea = "-AdministrativeArea-";
            init.CreateBuildings(parcel2, 31, 5);

            init.SaveChanges();

            var service = helper.CreateService <BuildingService>(user);

            // Act
            var result = service.GetPage(filter);

            // Assert
            Assert.NotNull(result);
            Assert.IsAssignableFrom <IEnumerable <Entity.Building> >(result);
            result.Should().HaveCount(expectedCount);
        }
Пример #13
0
        public void Get_Buildings(BuildingFilter filter, int expectedCount)
        {
            // Arrange
            var helper = new TestHelper();
            var user   = PrincipalHelper.CreateForPermission(Permissions.PropertyView).AddAgency(1, 3);

            using var init = helper.InitializeDatabase(user);
            var parcel1   = init.CreateParcel(1);
            var buildings = init.CreateBuildings(parcel1, 2, 20);

            buildings.Next(0).Latitude                   = 50;
            buildings.Next(0).Longitude                  = 25;
            buildings.Next(1).Agency                     = init.Agencies.Find(3);
            buildings.Next(1).AgencyId                   = 3;
            buildings.Next(2).ClassificationId           = 2;
            buildings.Next(3).Description                = "-DescriptionTest-";
            buildings.Next(4).BuildingTenancy            = "-BuildingTenancy-";
            buildings.Next(5).BuildingConstructionTypeId = 2;
            buildings.Next(6).BuildingPredominateUseId   = 2;
            buildings.Next(7).RentableArea               = 100;
            buildings.Next(8).RentableArea               = 50;

            var parcel2 = init.CreateParcel(22);

            parcel2.Municipality = "-Municipality-";
            init.CreateBuildings(parcel2, 23, 5);
            init.SaveChanges();

            var service = helper.CreateService <BuildingService>(user);

            // Act
            var result = service.Get(filter);

            // Assert
            Assert.NotNull(result);
            Assert.IsAssignableFrom <IEnumerable <Entity.Building> >(result);
            result.Should().HaveCount(expectedCount);
        }
Пример #14
0
        private static IRestRequest CreateBackendListRequest(
            int?offset,
            int?limit,
            Taal language,
            string sort,
            string status)
        {
            var filter = new BuildingFilter
            {
                Status = status
            };

            var sortMapping = new Dictionary <string, string>
            {
                { "Id", "PersistentLocalId" },
            };

            return(new RestRequest("gebouwen?taal={language}")
                   .AddParameter("language", language, ParameterType.UrlSegment)
                   .AddPagination(offset, limit)
                   .AddFiltering(filter)
                   .AddSorting(sort, sortMapping));
        }
Пример #15
0
    public static Building GetClosest(Vector3 position, BuildingFilter filter = null, bool finished = true, float maxDistance = 0)
    {
        Building closest         = null;
        var      closestDistance = float.MaxValue;

        foreach (var building in FindObjectsOfType <Building>())
        {
            if (building.IsGhost || finished != building.IsFinished)
            {
                continue;
            }
            if (filter != null && !filter(building))
            {
                continue;
            }
            var dist = (position - building.transform.position).sqrMagnitude;
            if (dist < closestDistance && (maxDistance == 0 || dist < maxDistance * maxDistance))
            {
                closestDistance = dist;
                closest         = building;
            }
        }
        return(closest);
    }
Пример #16
0
            /// <summary>
            /// Extract from RaycastLogic::GameTick
            /// Use to filter buidling
            /// </summary>
            public static void Select(RaycastLogic __instance, BuildingFilter filter)
            {
                int activeColHashCount = Traverse.Create((object)__instance).Field("activeColHashCount").GetValue <int>();

                int[] activeColHashes         = Traverse.Create((object)__instance).Field("activeColHashes").GetValue <int[]>();
                ColliderContainer[] colChunks = Traverse.Create((object)__instance).Field("colChunks").GetValue <ColliderContainer[]>();

                if (!__instance.doCast || GameMain.localPlanet != __instance.planet || (VFInput.inFullscreenGUI || !Application.isFocused))
                {
                    return;
                }

                for (int i = 0; i < activeColHashCount; i++)
                {
                    int            activeColHash = activeColHashes[i];
                    ColliderData[] colliderPool  = colChunks[activeColHash].colliderPool;

                    for (int j = 1; j < colChunks[activeColHash].cursor; j++)
                    {
                        if (colliderPool[j].idType != 0)
                        {
                            EObjectType objType  = colliderPool[j].objType;
                            bool        typeFlag = objType == EObjectType.Vein || objType == EObjectType.Vegetable;
                            if (!typeFlag || !__instance.ignoreVegeAndVein)
                            {
                                if ((colliderPool[j].usage == EColliderUsage.Build || typeFlag) &&
                                    colliderPool[j].shape == EColliderShape.Box)
                                {
                                    //Send to filter
                                    filter(colliderPool[j]);
                                }
                            }
                        }
                    }
                }
            }