public async Task Test_GetUnitsByUser_PositiveScenario()
        {
            OnSetup();
            var result = await testCandidate.GetUnitsByUser(userId, postcodeTypeGUID);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ToList().Count, 1);
            Assert.AreEqual(result.ToList()[0].LocationId, new Guid("1534AA41-391F-4579-A18D-D7EDF5B5F918"));
            Assert.AreEqual(result.ToList()[0].Area, string.Empty);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get all units for a user.
        /// </summary>
        /// <param name="userId">user Id.</param>
        /// <param name="currentUserUnitType">current user unit type.</param>
        /// <returns>
        /// List of <see cref="UnitLocationDTO" />.
        /// </returns>
        public async Task <IEnumerable <UnitLocationDTO> > GetUnitsByUser(Guid userId, string currentUserUnitType)
        {
            string methodName = typeof(UnitLocationBusinessService) + "." + nameof(GetUnitsByUser);

            using (loggingHelper.RMTraceManager.StartTrace("Business.GetUnitsByUser"))
            {
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.UnitManagerAPIPriority, LoggerTraceConstants.UnitManagerBusinessServiceMethodEntryEventId);

                // reference data value for PostcodeDistrict with Category - Postcode Type
                Guid postcodeTypeGUID = unitManagerIntegrationService.GetReferenceDataGuId(PostCodeType, PostCodeTypeCategory.PostcodeDistrict.GetDescription()).Result;

                IEnumerable <UnitLocationDataDTO> unitLocationDataDtoList = null;
                if (!currentUserUnitType.Equals(UserUnit.National.GetDescription()))
                {
                    unitLocationDataDtoList = await unitLocationDataService.GetUnitsByUser(userId, postcodeTypeGUID);
                }
                else
                {
                    unitLocationDataDtoList = await unitLocationDataService.GetUnitsByUserForNational(userId, postcodeTypeGUID);
                }

                var unitLocationDtoList = unitLocationDataDtoList.Select(x => new UnitLocationDTO
                {
                    ID   = x.LocationId,
                    Area = x.Area,
                    UnitBoundryPolygon = x.Shape,
                    UnitName           = currentUserUnitType.Equals(UserUnit.National.ToString()) ? currentUserUnitType : x.Name
                }).ToList();

                foreach (var unitLocationDto in unitLocationDtoList)
                {
                    try
                    {
                        // take the unit boundry plus 1 mile envelope
                        var unitBoundary = SqlGeometry.STPolyFromWKB(new SqlBytes(unitLocationDto.UnitBoundryPolygon.Envelope.Buffer(1609.34).Envelope.AsBinary()), BNGCOORDINATESYSTEM).MakeValid();

                        unitLocationDto.BoundingBoxCenter = new List <double> {
                            unitBoundary.STCentroid().STPointN(1).STX.Value, unitBoundary.STCentroid().STPointN(1).STY.Value
                        };

                        unitLocationDto.BoundingBox = new List <double> {
                            unitBoundary.STPointN(1).STX.Value, unitBoundary.STPointN(1).STY.Value, unitBoundary.STPointN(3).STX.Value, unitBoundary.STPointN(3).STY.Value
                        };
                    }
                    catch (Exception ex)
                    {
                    }
                }

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.UnitManagerAPIPriority, LoggerTraceConstants.UnitManagerBusinessServiceMethodExitEventId);
                return(unitLocationDtoList);
            }
        }