Skip to content

Commit

Permalink
feat: more detailed GeoLocator UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkar70 committed Dec 26, 2021
1 parent 7001557 commit 744237b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/SamplesApp/SamplesApp.Droid/SamplesApp.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<TargetFrameworkVersion>v12.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<ResourcesDirectory>..\SamplesApp.Shared\Strings</ResourcesDirectory>
<AndroidUseAapt2>true</AndroidUseAapt2>
Expand Down Expand Up @@ -258,4 +257,4 @@
<_ExplicitReference Remove="@(_FilteredExplicitReference)" />
</ItemGroup>
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
</TextBlock>

<TextBox Margin="0,12,0,0" Header="Desired accuracy in meters" Text="{Binding DesiredAccuracyInMeters, Mode=TwoWay}" />
<TimePicker Name="uiMaxCacheTime" ClockIdentifier="24HourClock" Header="Max cache time (mm:ss)" SelectedTime="{Binding maximumAge, Mode=TwoWay}" />
<TimePicker Name="uiTimeout" ClockIdentifier="24HourClock" Header="Timeout (mm:ss)" SelectedTime="{Binding timeout, Mode=TwoWay}" />

<Button Margin="0,12,0,0" Command="{Binding GetGeopositionCommand}">Get geoposition</Button>
<local:GeopositionDisplayControl Geoposition="{x:Bind ViewModel.Geoposition, Mode=OneWay}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal class GeolocatorTestsViewModel : ViewModelBase
public GeolocatorTestsViewModel(CoreDispatcher dispatcher) : base(dispatcher)
{
PositionStatus = _geolocator.LocationStatus;
timeout = TimeSpan.FromSeconds(10);
maximumAge = TimeSpan.FromSeconds(15);
}

public Geoposition Geoposition
Expand All @@ -59,6 +61,9 @@ public Geoposition Geoposition
}
}

public TimeSpan timeout { get; set; }
public TimeSpan maximumAge { get; set; }

public Geoposition TrackedGeoposition
{
get => _trackedGeoposition;
Expand Down Expand Up @@ -95,6 +100,8 @@ public uint? DesiredAccuracyInMeters
set => _geolocator.DesiredAccuracyInMeters = value;
}



public PositionStatus PositionStatus
{
get => _positionStatus;
Expand All @@ -105,6 +112,7 @@ public PositionStatus PositionStatus
}
}


public string Error
{
get => _error;
Expand Down Expand Up @@ -164,7 +172,24 @@ private async void GetGeoposition()
{
try
{
Geoposition = await _geolocator.GetGeopositionAsync();
var timeout1 = new TimeSpan(0, 0, timeout.Hours, timeout.Seconds);
var maximumAge1 = new TimeSpan(0, 0, maximumAge.Hours, maximumAge.Seconds);

var startTime = DateTimeOffset.Now;

Geoposition = await _geolocator.GetGeopositionAsync(maximumAge1, timeout1);

if(Geoposition.Coordinate.Timestamp < DateTimeOffset.Now - maximumAge)
{
Error = "Implementation error: Position data is too old";
}

if (startTime < DateTimeOffset.Now - timeout)
{
Error = "Implementation error: no reaction for TimeOut parameter";
}


}
catch (Exception ex)
{
Expand Down

0 comments on commit 744237b

Please sign in to comment.