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 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 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)); }
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 async Task <bool> Execute() { var repo = new LocationRecordRepository(); Console.WriteLine("Starting location tracking"); try { var request = new GeolocationRequest(GeolocationAccuracy.Medium); var location = await Geolocation.GetLocationAsync(request); if (location != null) { Console.WriteLine( $"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}"); await repo.CreateLocationRecord(new LocationRecord { Accuracy = location.Accuracy, Latitude = location.Latitude, Longitude = location.Longitude, Timestamp = location.Timestamp }); } } catch (FeatureNotSupportedException fnsEx) { Console.WriteLine(fnsEx); // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { Console.WriteLine(fneEx); // Handle not enabled on device exception } catch (PermissionException pEx) { Console.WriteLine(pEx); // Handle permission exception } catch (Exception ex) { Console.WriteLine(ex); // Unable to get location } return(true); }
public void ShouldPersistRecord() { 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); // assert values equal first and targetRecord Assert.Equal(firstRecord.Timestamp, targetRecord.Timestamp); Assert.Equal(firstRecord.MemberID, targetRecord.MemberID); Assert.Equal(firstRecord.ID, targetRecord.ID); Assert.Equal(firstRecord.Latitude, targetRecord.Latitude); }