예제 #1
0
        public HotSpotModel NearestHotSpot(HotSpotModel hotspot)
        {
            var nearest = _hotSpotList.OrderBy(x => DistanceBetweenHotSpots(hotspot, x))
                          .First(x => x.Number != hotspot.Number);

            return(nearest);
        }
예제 #2
0
        public bool Update(int id, HotSpotModel hotSpotById)
        {
            var currentHotSpot = GetById(id);

            currentHotSpot.LocationName = hotSpotById.LocationName;
            currentHotSpot.LatitudeX    = hotSpotById.LatitudeX;
            currentHotSpot.LongitudeY   = hotSpotById.LongitudeY;
            return(true);
        }
예제 #3
0
        private double DistanceBetweenHotSpots(HotSpotModel x, HotSpotModel y)
        {
            var xLatitude  = double.Parse(x.LatitudeX, CultureInfo.InvariantCulture);
            var xLongitude = double.Parse(x.LongitudeY, CultureInfo.InvariantCulture);

            var yLatitude  = double.Parse(y.LatitudeX, CultureInfo.InvariantCulture);
            var yLongitude = double.Parse(y.LongitudeY, CultureInfo.InvariantCulture);

            var distance = GeoCalculator.GetDistance(xLatitude, xLongitude, yLatitude, yLongitude);

            return(distance);
        }
예제 #4
0
        public void Should_Get_All_Favorites()
        {
            //Arrange
            var hotspot        = new HotSpotService();
            var testingHotSpot = new HotSpotModel()
            {
                LocationName = "Test123",
            };

            hotspot.AddHotSpot(testingHotSpot);
            hotspot.MarkAsFavorite(testingHotSpot.Number);
            //Act
            var sut = hotspot.GetAllFavorites();

            //Assert
            Assert.Collection(sut, item => Assert.True(item.FavoriteHotSpot));
        }
예제 #5
0
        public void Should_Add_Hotspot()
        {
            //Arrange
            HotSpotService hs      = new HotSpotService();
            HotSpotModel   hotspot = new HotSpotModel()
            {
                LocationName = "Burzyńskiego 12",
                LatitudeX    = "54",
                LongitudeY   = "18",
            };
            //Act
            var sut         = hs.AddHotSpot(hotspot);
            var lastHotSpot = hs.GetAll().TakeLast(1);

            //Assert
            Assert.Collection(lastHotSpot, item => Assert.Contains("Burzyńskiego", item.LocationName));
            Assert.Collection(lastHotSpot, item => Assert.Contains("54", item.LatitudeX));
            Assert.Collection(lastHotSpot, item => Assert.Contains("18", item.LongitudeY));
        }
예제 #6
0
        public void Should_Update_Old_Data_In_Hotspot()
        {
            //Arrange
            var hotspotService = new HotSpotService();
            var allHotSpots    = hotspotService.GetAll();
            var updatedHotSpot = new HotSpotModel()
            {
                LocationName = "testing",
                LatitudeX    = "111",
                LongitudeY   = "222",
                //Number pop and FakeId prop are not taking care into consideration for the update purpose
                //Therefore it's values will be the same as used to be
                Number = 1,
                fakeID = "LOK001"
            };
            var currentHotSpot = hotspotService.GetById(1);

            //Act
            hotspotService.Update(1, updatedHotSpot);
            //Assert
            currentHotSpot.Should().BeEquivalentTo(updatedHotSpot);
        }
예제 #7
0
 public IActionResult Nearest(HotSpotModel hotspot)
 {
     return(View("Nearest", _mapper.Map <HotSpotModel, HotSpotViewModel>(hotspot)));
 }
예제 #8
0
 public HotSpotModel AddHotSpot(HotSpotModel hotspot)
 {
     hotspot.Number = _hotSpotList.Max(x => x.Number) + 1;
     _hotSpotList.Add(hotspot);
     return(hotspot);
 }