public void GetLocationForMemberReturns() { // Arrange ILocationRecordRepository repository = new InMemoryLocationRecordRepository(); var controller = new LocationRecordController(repository); var newMemberId = Guid.NewGuid(); var newLocation = new LocationRecord() { ID = Guid.NewGuid(), MemberID = Guid.NewGuid() }; var lastLocation = new LocationRecord() { ID = Guid.NewGuid(), MemberID = Guid.NewGuid() }; repository.Add(newLocation); repository.Add(lastLocation); // Act var result = (ICollection <LocationRecord>)(controller.GetLocationsForMember(newMemberId) as ObjectResult).Value; // Assert Assert.Equal(2, result.Count); Assert.True(result.Contains(lastLocation)); Assert.True(result.Contains(newLocation)); }
//this method should return true if it finished processing, and false if it still needs to continue public bool MapFloodDijkstra() { var processedNodes = 0; while (this.Open.CountOpen() > 0) { if (processedNodes > this.NodesPerFlood) { this.InProgress = true; return(false); } LocationRecord currentRecord = this.Open.GetBestAndRemove(); this.Closed.AddToClosed(currentRecord); processedNodes++; var outConnections = currentRecord.Location.OutEdgeCount; for (int i = 0; i < outConnections; i++) { LocationRecord child = new LocationRecord(); child.Location = currentRecord.Location.EdgeOut(i).ToNode; this.ProcessChildNode(currentRecord, child); } } this.InProgress = false; // this.CleanUp(); return(true); }
public JsonResult GetLocation(int id) { var name = ""; LatLng ll = new LatLng(); LocationRecord lr = new LocationRecord(); if (Session["Ctx"] != null) { var ctx = Session["ctx"] as Ctx; MLocation loc = MLocation.Get(ctx, id, null); if (loc == null) { return(Json(lr, JsonRequestBehavior.AllowGet)); } name = loc.ToString(); ll.Longitude = loc.GetLongitude(); ll.Latitude = loc.GetLatitude(); } lr.LocItem = new KeyNamePair(id, name); lr.LocLatLng = ll; return(Json(lr, JsonRequestBehavior.AllowGet)); }
public LocationRecord Add(LocationRecord record) { var memberRecords = this.GetMemberRecords(record.MemberID); memberRecords.Add(record.Timestamp, record); return(record); }
public void GetLastLocation() { // Arrange ILocationRecordRepository repository = new InMemoryLocationRecordRepository(); var controller = new LocationRecordController(repository); var newMemberId = Guid.NewGuid(); var newLocation = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(), MemberID = Guid.NewGuid() }; var lastLocation = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(), MemberID = Guid.NewGuid() }; repository.Add(newLocation); repository.Add(lastLocation); // Act var result = (LocationRecord)(controller.GetLatestForMember(newMemberId) as ObjectResult).Value; // Assert Assert.Equal(lastLocation.ID, result.ID); }
/// <summary> /// Asynchronously registers the current location of a callsign. /// </summary> /// <param name="imei">The IMEI from the location report.</param> /// <param name="readingTime">The time the location measurement was made.</param> /// <param name="receivedTime">The time the location measurement was received by the server.</param> /// <param name="latitude">The latitude of the callsign.</param> /// <param name="longitude">The longitude of the callsign.</param> /// <returns></returns> public async Task RegisterLocation(string imei, DateTimeOffset readingTime, DateTimeOffset receivedTime, decimal latitude, decimal longitude) { if (imei == null) { throw new ArgumentNullException(nameof(imei)); } if (string.IsNullOrWhiteSpace(imei)) { throw new ArgumentException("{0} cannot be empty or only whitespace", nameof(imei)); } var vehicle = await IMEIService.GetFromIMEI(imei); var locationData = new LocationRecord { Latitude = latitude, Longitude = longitude, ReadingTime = readingTime, ReceiveTime = receivedTime, Callsign = vehicle.CallSign, Type = vehicle.Type }; _dataContext.LocationRecords.Add(locationData); await _dataContext.SaveChangesAsync(); }
public void ShouldGetAllForMember() { LocationRecordRepository repository = new LocationRecordRepository(context); Guid memberId = Guid.NewGuid(); int initialCount = repository.AllForMember(memberId).Count(); LocationRecord firstRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 1, MemberID = memberId, Latitude = 12.3f }; repository.Add(firstRecord); LocationRecord secondRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 2, MemberID = memberId, Latitude = 24.4f }; repository.Add(secondRecord); ICollection <LocationRecord> records = repository.AllForMember(memberId); int afterCount = records.Count(); Assert.Equal(initialCount + 2, afterCount); Assert.NotNull(records.FirstOrDefault(r => r.ID == firstRecord.ID)); Assert.NotNull(records.FirstOrDefault(r => r.ID == secondRecord.ID)); }
GetLatestForMember(Guid memberId) { LocationRecord locationRecord = null; using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(this.URL); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json")); HttpResponseMessage response = await httpClient.GetAsync( String.Format("/locations/{0}/latest", memberId)); if (response.IsSuccessStatusCode) { string json = await response.Content.ReadAsStringAsync(); locationRecord = JsonConvert .DeserializeObject <LocationRecord>(json); } } return(locationRecord); }
public void ShouldGetLatestForMember() { LocationRecordRepository repository = new LocationRecordRepository(context); Guid memberId = Guid.NewGuid(); LocationRecord firstRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 1, MemberID = memberId, Latitude = 12.3f }; repository.Add(firstRecord); LocationRecord secondRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 2, MemberID = memberId, Latitude = 24.4f }; repository.Add(secondRecord); LocationRecord latest = repository.GetLatestForMember(memberId); Assert.NotNull(latest); Assert.Equal(latest.ID, secondRecord.ID); Assert.NotEqual(latest.ID, firstRecord.ID); }
public void ShouldUpdateRecord() { LocationRecordRepository repository = new LocationRecordRepository(context); LocationRecord firstRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 1, MemberID = Guid.NewGuid(), Latitude = 12.3f }; repository.Add(firstRecord); LocationRecord targetRecord = repository.Get(firstRecord.MemberID, firstRecord.ID); // modify firstRecord. firstRecord.Longitude = 12.5f; firstRecord.Latitude = 47.09f; repository.Update(firstRecord); LocationRecord target2 = repository.Get(firstRecord.MemberID, firstRecord.ID); Assert.Equal(firstRecord.Timestamp, target2.Timestamp); Assert.Equal(firstRecord.Longitude, target2.Longitude); Assert.Equal(firstRecord.Latitude, target2.Latitude); Assert.Equal(firstRecord.ID, target2.ID); Assert.Equal(firstRecord.MemberID, target2.MemberID); }
public void ShouldDeleteRecord() { LocationRecordRepository repository = new LocationRecordRepository(context); Guid memberId = Guid.NewGuid(); LocationRecord firstRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 1, MemberID = memberId, Latitude = 12.3f }; repository.Add(firstRecord); LocationRecord secondRecord = new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 2, MemberID = memberId, Latitude = 24.4f }; repository.Add(secondRecord); int initialCount = repository.AllForMember(memberId).Count(); repository.Delete(memberId, secondRecord.ID); int afterCount = repository.AllForMember(memberId).Count(); LocationRecord target1 = repository.Get(firstRecord.MemberID, firstRecord.ID); LocationRecord target2 = repository.Get(firstRecord.MemberID, secondRecord.ID); Assert.Equal(initialCount - 1, afterCount); Assert.Equal(target1.ID, firstRecord.ID); Assert.NotNull(target1); Assert.Null(target2); }
public LocationRecord Add(LocationRecord locationRecord) { var memberRecords = getMemberRecords(locationRecord.MemberID); memberRecords.Add(locationRecord.Timestamp, locationRecord); return(locationRecord); }
public SimpleIntegrationTests() { testServer = new TestServer(new WebHostBuilder().UseStartup <Startup>()); testClient = testServer.CreateClient(); testClient.BaseAddress = new Uri("http://localhost/"); testServerLocation = new TestServer(new WebHostBuilder().UseStartup <Microservice.LocationService.Startup>()); testClientLocation = testServerLocation.CreateClient(); testClient.BaseAddress = new Uri("http://localhost:65390/"); teamZombie = new Team() { ID = Guid.NewGuid(), Name = "Zombie Team" }; memberZombie = new Member() { FirstName = "Rob", LastName = "Zombie", ID = Guid.NewGuid() }; locationRecord = new LocationRecord() { ID = Guid.NewGuid(), Altitude = 12.0f, Latitude = 10.0f, Longitude = 10.0f, MemberID = memberZombie.ID, Timestamp = 0 }; }
public LocationRecord GetLatestForMember(Guid memberId) { var memberRecords = getMemberRecords(memberId); LocationRecord lr = memberRecords.Values.LastOrDefault(); return(lr); }
public void LoadLocationList() { DataTable dt = new DataTable(); // Carica Location dt = Database.GetData("select * from LOC_ClientLocation", null); // carica Dictionary foreach (DataRow dr in dt.Rows) { LocationRecord item = new LocationRecord(); item.ParentKey = dr["CodiceCliente"].ToString().TrimEnd(); item.LocationKey = dr["ClientLocation_id"].ToString().TrimEnd(); item.LocationDescription = dr["LocationDescription"].ToString(); item.LocationType = "C"; // customer, usato su input.aspx.cs LocationList.Add(item); } // Carica Location dt = Database.GetData("select * from LOC_ProjectLocation", null); // carica Dictionary foreach (DataRow dr in dt.Rows) { LocationRecord item = new LocationRecord(); item.ParentKey = dr["Projects_id"].ToString(); item.LocationKey = dr["ProjectLocation_id"].ToString().TrimEnd(); item.LocationDescription = dr["LocationDescription"].ToString(); item.LocationType = "P"; // Project, usato su input.aspx.cs LocationList.Add(item); } }
public void Initialize(List <IInfluenceUnit> units) { this.Open.Initialize(); this.Closed.Initialize(); this.Units = units; foreach (var unit in units) { //I need to do this because in Recast NavMesh graph, the edges of polygons are considered to be nodes and not the connections. //Theoretically the Quantize method should then return the appropriate edge, but instead it returns a polygon //Therefore, we need to create one explicit connection between the polygon and each edge of the corresponding polygon for the search algorithm to work ((NavMeshPoly)unit.Location).AddConnectedPoly(unit.Location.Position); var locationRecord = new LocationRecord { Influence = unit.DirectInfluence, StrongestInfluenceUnit = unit, Location = unit.Location }; Open.AddToOpen(locationRecord); } this.InProgress = true; }
public void AddMultipleLocationRecordsAndFetchLatest() { var memberId = Guid.NewGuid(); long timeStamp = 0; for (int i = 0; i <= 4; i++) { var locationRecord = new LocationRecord() { ID = Guid.NewGuid(), Altitude = 1200, Latitude = 54.12f, Longitude = 12.31f, MemberID = memberId, Timestamp = GetUnixTimeStamp() }; controller.AddLocation(locationRecord.MemberID, locationRecord); Thread.Sleep(1000); if (i >= 4) { timeStamp = locationRecord.Timestamp; } } var results = controller.GetLatestLocationsForMember(memberId) as OkObjectResult; var fetchedLocationRecord = results.Value as LocationRecord; Assert.Equal(timeStamp, fetchedLocationRecord.Timestamp); }
public void ShouldTrackLatestLocationsForMember() { ILocationRecordRepository repository = new InMemoryLocationRecordRepository(); LocationRecordController controller = new LocationRecordController(repository); Guid memberGuid = Guid.NewGuid(); Guid latestId = Guid.NewGuid(); controller.AddLocation(memberGuid, new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 1, MemberID = memberGuid, Latitude = 12.3f }); controller.AddLocation(memberGuid, new LocationRecord() { ID = latestId, Timestamp = 3, MemberID = memberGuid, Latitude = 23.4f }); controller.AddLocation(memberGuid, new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 2, MemberID = memberGuid, Latitude = 23.4f }); controller.AddLocation(Guid.NewGuid(), new LocationRecord() { ID = Guid.NewGuid(), Timestamp = 4, MemberID = Guid.NewGuid(), Latitude = 23.4f }); LocationRecord latest = ((controller.GetLatestForMember(memberGuid) as ObjectResult).Value as LocationRecord); Assert.NotNull(latest); Assert.Equal(latestId, latest.ID); }
public async Task GetCallsignRecordGoodData() { GoodLocations.Clear(); var badRecord = new LocationRecord { Callsign = "WR01", ReadingTime = DateTimeOffset.Now, Latitude = 1 }; var badRecord2 = new LocationRecord { Callsign = "WR02", ReadingTime = DateTimeOffset.Now.AddDays(-1), Latitude = 1 }; GoodLocations.Add(badRecord); GoodLocations.Add(badRecord2); var goodRecords = new[] { new LocationRecord { Callsign = "WR02", ReadingTime = DateTimeOffset.Now.AddMinutes(-1), Latitude = 1 }, new LocationRecord { Callsign = "WR02", ReadingTime = DateTimeOffset.Now.AddMinutes(-2), Latitude = 1 }, new LocationRecord { Callsign = "WR02", ReadingTime = DateTimeOffset.Now.AddMinutes(-3), Latitude = 1 }, new LocationRecord { Callsign = "WR02", ReadingTime = DateTimeOffset.Now.AddMinutes(-4), Latitude = 1 }, }; GoodLocations.AddRange(goodRecords); var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations); var context = CreateMockLocationContext(locations.Object); var service = new ReportService(context.Object); var res = await service.GetCallsignRecord("WR02", DateTimeOffset.Now.AddHours(-1), DateTimeOffset.Now); Assert.True(res.OrderBy(l => l.ReadingTime).SequenceEqual(goodRecords.OrderBy(l => l.ReadingTime))); }
public LocationRecord Get(Guid memberId, Guid recordId) { var memberRecords = getMemberRecords(memberId); LocationRecord lr = memberRecords.Values.Where(l => l.ID == recordId).FirstOrDefault(); return(lr); }
public IActionResult AddLocation(Guid memberId, [FromBody] LocationRecord locationRecord) { locationRepository.Add(locationRecord); return(this.Created( $"/locations/{memberId}/{locationRecord.ID}", locationRecord)); }
public async Task <IActionResult> AddLocation(Guid memberId, [FromBody] LocationRecord locationRecord) { locationRecord.MemberId = memberId; await _locationRepository.Add(locationRecord); return(Created(Url.Link("GetLastLocationForMember", new { memberId }), locationRecord)); }
public LocationRecord Delete(Guid memberId, Guid recordId) { LocationRecord locationRecord = this.Get(memberId, recordId); _context.Remove(locationRecord); _context.SaveChanges(); return(locationRecord); }
public async Task <LocationRecord> Add(LocationRecord locationRecord) { locationRecord.Id = Guid.NewGuid(); locationRecord.CreationDate = DateTimeOffset.UtcNow; await _documentClient.CreateDocumentAsync(GetLocationsCollectionUri(), locationRecord); return(locationRecord); }
public async Task CreateLocationRecord(LocationRecord record) { await LocalDatabase.WaitInitialized; await _database.InsertAsync(record); var records = await _database.Table <LocationRecord>().CountAsync(); Console.WriteLine($"We have {records} location records"); }
public IActionResult AddLocation(Guid memberId, [FromBody] LocationRecord locationRecord) { if (locationRecord == null) { return(this.BadRequest($"Error at payload")); } _repository.Add(locationRecord); return(this.Created($"/locations/{memberId}/{locationRecord.ID}", locationRecord)); }
public LocationRecord GetLatestForMember(Guid memberId) { LocationRecord locationRecord = _context.LocationRecords. Where(lr => lr.MemberID == memberId). OrderBy(lr => lr.Timestamp). Last(); return(locationRecord); }
public LocationRecord GetLatestForMember(Guid memberId) { LocationRecord locationRecord = this.context.LocationRecords .Where(lr => lr.MemberID == memberId) .OrderByDescending(lr => lr.Timestamp) .FirstOrDefault(); return(locationRecord); }
public LocationRecord Update(LocationRecord locationRecord) { var recordToUpdate = _locationRecords.Where(l => l.MemberID == locationRecord.MemberID).FirstOrDefault(); _locationRecords.Remove(recordToUpdate); _locationRecords.Add(locationRecord); return(locationRecord); }
public void ShouldTrackNullLatestForNewMember() { ILocationRecordRepository repository = new InMemoryLocationRecordRepository(); LocationRecordController controller = new LocationRecordController(repository); Guid memberGuid = Guid.NewGuid(); LocationRecord latest = ((controller.GetLatestForMember(memberGuid) as ObjectResult).Value as LocationRecord); Assert.Null(latest); }
public LocationServiceTests() { GoodLocations = new List<LocationRecord>(Fixture.CreateMany<LocationRecord>()); GoodLocation = GoodLocations.First(); BadLandmark = Fixture.Create<Landmark>(); GoodCallsign = Fixture.Create<IMEIToCallsign>(); UnknownIMEI = Fixture.Create<string>(); GoodLandmarks = new List<Landmark>(Fixture.CreateMany<Landmark>()); GoodLandmark = GoodLandmarks.First(); }
public async Task RegisterLocation(string imei, DateTimeOffset readingTime, DateTimeOffset receivedTime, decimal latitude, decimal longitude) { var vehicle = await imeiService.GetFromIMEI(imei); var locationData = new LocationRecord { Latitude = latitude, Longitude = longitude, ReadingTime = readingTime, ReceiveTime = receivedTime, Callsign = vehicle.CallSign, Type = vehicle.Type }; dataContext.LocationRecords.Add(locationData); await dataContext.SaveChangesAsync(); }
private static bool ValidateLocationRecord(LocationRecord record, IMEIToCallsign imei, decimal latitude, decimal longitude, DateTimeOffset readingTime, DateTimeOffset receivedTime) { Assert.Equal(latitude, record.Latitude); Assert.Equal(longitude, record.Longitude); Assert.Equal(readingTime, record.ReadingTime); Assert.Equal(receivedTime, record.ReceiveTime); Assert.Equal(imei.CallSign, record.Callsign); Assert.Equal(imei.Type, record.Type); return true; }