Example #1
0
        public IEnumerable <AreaMetadataResponseDto> GetMultipleAreasMetadata(MultipleAreasMetadataRequestDto areas)
        {
            var areaEntities = this._unitOfWork.AreaRepository.GetAreas().Where(a => areas.AreaIds.Contains(a.Id));

            var areaDtos = this._mapper.Map <IEnumerable <Area>, IEnumerable <AreaDto> >(areaEntities);

            var areaEntitiesAsMetadataList =
                areaDtos.Select(
                    a =>
                    GetAreaMetadata(new GeoCoordinate(areas.Latitude, areas.Longitude),
                                    new GeoCoordinate(a.Latitude, a.Longitude), a));

            return(areaEntitiesAsMetadataList);
        }
Example #2
0
        public IHttpActionResult GetMultipleAreasMetadata([FromBody] MultipleAreasMetadataRequestDto areas)
        {
            try
            {
                var result = this._areaService.GetMultipleAreasMetadata(areas);

                if (result == null || !result.Any())
                {
                    _apiLogger.LogError($"Non of the areas with ids: {areas.AreaIds} could not be found.", null);
                    return(InternalServerError());
                }

                // TODO: If result is empty throw an error. BadRequest or InternalServer error. Add it to the tests.

                return(Ok(result));
            }
            catch (Exception ex)
            {
                var errorMessage = _apiLogger.OnActionException(ActionContext, ex);
                return(InternalServerError(new HttpException(errorMessage)));
            }
        }
Example #3
0
        public void We_Can_Get_Metadata_For_Multiple_Areas()
        {
            // arrange
            var myLocationLatitude  = 10;
            var myLocationLongitude = 10;

            var groupOneId = Guid.NewGuid();
            var groupTwoId = Guid.NewGuid();

            var workingTag = new Tag()
            {
                Id   = Guid.Parse("caf77dee-a94f-49cb-b51f-e0c0e1067541"),
                Name = "Help"
            };

            var groupOne = new Group()
            {
                Id    = groupOneId,
                Name  = "GroupOne",
                Users = new List <User>(),
                Tags  = new List <Tag>()
                {
                    workingTag
                }
            };
            var groupTwo = new Group()
            {
                Id = groupTwoId, Name = "GroupTwo", Users = new List <User>(), Tags = new List <Tag>()
                {
                    workingTag
                }
            };

            var firstAreaId = Guid.NewGuid();
            var firstArea   = new Area()
            {
                Id        = firstAreaId,
                Latitude  = 10,
                Longitude = 10,
                Groups    = new List <Group>()
                {
                    groupOne, groupTwo
                },
                Radius = RadiusRangeEnum.FiftyMeters
            };

            var secondAreaId = Guid.NewGuid();
            var secondArea   = new Area()
            {
                Id        = firstAreaId,
                Latitude  = 10.00001,
                Longitude = 10.00001,
                Groups    = new List <Group>()
                {
                    groupOne, groupTwo
                },
                Radius = RadiusRangeEnum.FiveHundredMeters
            };

            groupOne.Areas = new List <Area>()
            {
                firstArea, secondArea
            };
            groupTwo.Areas = new List <Area>()
            {
                firstArea, secondArea
            };

            var userId = Guid.NewGuid();
            var user   = new User()
            {
                Id            = userId,
                FirstName     = "Stefcho",
                LastName      = "Stefchev",
                Email         = "*****@*****.**",
                IdsrvUniqueId = Guid.NewGuid().ToString()
            };

            var populatedDatabase = new FakeLikkleDbContext()
            {
                Groups = new FakeDbSet <Group>()
                {
                    groupOne, groupTwo
                },
                Areas = new FakeDbSet <Area>()
                {
                    firstArea, secondArea
                },
                Users = new FakeDbSet <User>()
                {
                    user
                }
            }
            .Seed();

            this._mockedLikkleUoW.Setup(uow => uow.AreaRepository).Returns(new AreaRepository(populatedDatabase));
            this._mockedLikkleUoW.Setup(uow => uow.GroupRepository).Returns(new GroupRepository(populatedDatabase));
            this._mockedLikkleUoW.Setup(uow => uow.UserRepository).Returns(new UserRepository(populatedDatabase));

            // act
            var multipleAreasMetadataRequestDto = new MultipleAreasMetadataRequestDto()
            {
                AreaIds = new List <Guid>()
                {
                    firstAreaId, secondAreaId
                },
                Latitude  = myLocationLatitude,
                Longitude = myLocationLongitude
            };

            var multipleAreasMetadata = this._areaService.GetMultipleAreasMetadata(multipleAreasMetadataRequestDto);

            // assert
            Assert.IsNotNull(multipleAreasMetadata);
            Assert.AreEqual(multipleAreasMetadata.Count(), 2);
            Assert.IsTrue(multipleAreasMetadata.Any(a => a.DistanceTo == 0));
        }