Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to .Net Core style project and added package build targets #143

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mono:
solution: GoogleMapsApi.sln
install:
- nuget restore GoogleMapsApi.sln
- nuget install NUnit.ConsoleRunner -Version 3.6.1 -OutputDirectory testrunner
- nuget install NUnit.ConsoleRunner -Version 3.12.0 -OutputDirectory testrunner
script:
- xbuild /p:Configuration=Release GoogleMapsApi.sln
- mono ./testrunner/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe ./GoogleMapsApi.Test/bin/Release/GoogleMapsApi.Test.dll
- mono ./testrunner/NUnit.ConsoleRunner.3.12.0/tools/nunit3-console.exe ./GoogleMapsApi.Test/bin/Release/GoogleMapsApi.Test.dll
113 changes: 16 additions & 97 deletions GoogleMapsApi.Test/GoogleMapsApi.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,106 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AD9AD8E9-0E2C-470E-9004-373679F9D954}</ProjectGuid>
<TargetFrameworks>net6.0;</TargetFrameworks>
<LangVersion>latest</LangVersion>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GoogleMapsApi.Test</RootNamespace>
<AssemblyName>GoogleMapsApi.Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>

<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="IntegrationTests\DirectionsTests.cs" />
<Compile Include="IntegrationTests\DistanceMatrixTests.cs" />
<Compile Include="IntegrationTests\ElevationTests.cs" />
<Compile Include="IntegrationTests\GeocodingTests.cs" />
<Compile Include="IntegrationTests\BaseTestIntegration.cs" />
<Compile Include="IntegrationTests\PlacesFindTests.cs" />
<Compile Include="IntegrationTests\PlacesNearByTests.cs" />
<Compile Include="IntegrationTests\PlacesSearchTests.cs" />
<Compile Include="IntegrationTests\PlacesDetailsTests.cs" />
<Compile Include="IntegrationTests\PlacesTextTests.cs" />
<Compile Include="IntegrationTests\TimeZoneTests.cs" />
<Compile Include="IntegrationTests\PlaceAutocompleteTests.cs" />
<Compile Include="LocationToStringTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StaticMaps.cs" />
<Compile Include="UnixTimeConverterTest.cs" />
<Compile Include="Utils\AssertInconclusive.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GoogleMapsApi\GoogleMapsApi.csproj">
<Project>{61E9FC82-47B0-43C3-8749-95D3A9967060}</Project>
<Name>GoogleMapsApi</Name>
</ProjectReference>

<ItemGroup>
<ProjectReference Include="..\GoogleMapsApi\GoogleMapsApi.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
43 changes: 10 additions & 33 deletions GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Configuration;
using NUnit.Framework;
using System;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace GoogleMapsApi.Test.IntegrationTests
{
Expand All @@ -12,39 +11,17 @@ namespace GoogleMapsApi.Test.IntegrationTests

public class BaseTestIntegration
{
private string apiKey;
private readonly IConfigurationRoot Configuration;

protected string ApiKey
public BaseTestIntegration()
{
get
{
if (string.IsNullOrWhiteSpace(apiKey))
{
Assert.Inconclusive("API key not specified, please set it in the 'app.config' file");
}

return apiKey;
}
private set { apiKey = value; }
Configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
}


protected BaseTestIntegration()
{
var fromConfigManager = ConfigurationManager.AppSettings["ApiKey"];
var fromEnvironmentVariables = Environment.GetEnvironmentVariable("ApiKey");

if (!string.IsNullOrEmpty(fromConfigManager))
{
ApiKey = fromConfigManager;
} else if (!string.IsNullOrEmpty(fromEnvironmentVariables))
{
ApiKey = fromEnvironmentVariables;
}
else
{
ApiKey = string.Empty;
}
}
protected string ApiKey => Configuration.GetValue<string>("ApiKey");
}
}
46 changes: 23 additions & 23 deletions GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@
using GoogleMapsApi.Entities.Directions.Response;
using NUnit.Framework;
using GoogleMapsApi.Test.Utils;
using System.Threading.Tasks;

namespace GoogleMapsApi.Test.IntegrationTests
{
[TestFixture]
public class DirectionsTests : BaseTestIntegration
{
[Test]
public void Directions_SumOfStepDistancesCorrect()
public async Task Directions_SumOfStepDistancesCorrect()
{
var request = new DirectionsRequest { Origin = "285 Bedford Ave, Brooklyn, NY, USA", Destination = "185 Broadway Ave, Manhattan, NY, USA" };
request.ApiKey = ApiKey;
var result = GoogleMaps.Directions.Query(request);
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage);
Assert.Greater(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 100);
}

[Test]
public void Directions_ErrorMessage()
public async Task Directions_ErrorMessage()
{
var request = new DirectionsRequest
{
ApiKey = "ABCDEF", // Wrong API Key
Origin = "285 Bedford Ave, Brooklyn, NY, USA",
Destination = "185 Broadway Ave, Manhattan, NY, USA"
};
var result = GoogleMaps.Directions.Query(request);
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.AreEqual(DirectionsStatusCodes.REQUEST_DENIED, result.Status);
Expand All @@ -42,10 +43,10 @@ public void Directions_ErrorMessage()
}

[Test]
public void Directions_WithWayPoints()
public async Task Directions_WithWayPoints()
{
var request = new DirectionsRequest { Origin = "NYC, USA", Destination = "Miami, USA", Waypoints = new string[] { "Philadelphia, USA" }, OptimizeWaypoints = true, ApiKey = ApiKey };
var result = GoogleMaps.Directions.Query(request);
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage);
Expand All @@ -54,7 +55,7 @@ public void Directions_WithWayPoints()
StringAssert.Contains("Philadelphia", result.Routes.First().Legs.First().EndAddress);
}
[Test]
public void Directions_ExceedingRouteLength()
public async Task Directions_ExceedingRouteLength()
{
var request = new DirectionsRequest
{
Expand All @@ -75,29 +76,28 @@ public void Directions_ExceedingRouteLength()
},
ApiKey = ApiKey
};
var result = GoogleMaps.Directions.Query(request);
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.AreEqual(DirectionsStatusCodes.MAX_ROUTE_LENGTH_EXCEEDED, result.Status, result.ErrorMessage);
}

[Test]
public void Directions_Correct_OverviewPath()
public async Task Directions_Correct_OverviewPath()
{
DirectionsRequest request = new DirectionsRequest
var request = new DirectionsRequest
{
Destination = "maleva 10, Ahtme, Kohtla-Järve, 31025 Ida-Viru County, Estonia",
Origin = "veski 2, Jõhvi Parish, 41532 Ida-Viru County, Estonia",
ApiKey = ApiKey
};

DirectionsResponse result = GoogleMaps.Directions.Query(request);
DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);

OverviewPolyline overviewPath = result.Routes.First().OverviewPath;
OverviewPolyline polyline = result.Routes.First().Legs.First().Steps.First().PolyLine;
IEnumerable<Location> points = result.Routes.First().OverviewPath.Points;

Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage);
Assert.AreEqual(122, overviewPath.Points.Count(), 30);
Expand All @@ -118,7 +118,7 @@ public void DirectionsAsync_SumOfStepDistancesCorrect()

//The sub_steps differes between google docs documentation and implementation. We use it as google implemented, so we have test to make sure it's not broken.
[Test]
public void Directions_VerifysubSteps()
public async Task Directions_VerifysubSteps()
{
var request = new DirectionsRequest
{
Expand All @@ -128,7 +128,7 @@ public void Directions_VerifysubSteps()
ApiKey = ApiKey
};

DirectionsResponse result = GoogleMaps.Directions.Query(request);
DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);

Expand All @@ -140,7 +140,7 @@ public void Directions_VerifysubSteps()
}

[Test]
public void Directions_VerifyBounds()
public async Task Directions_VerifyBounds()
{
var request = new DirectionsRequest
{
Expand All @@ -150,7 +150,7 @@ public void Directions_VerifyBounds()
ApiKey = ApiKey
};

DirectionsResponse result = GoogleMaps.Directions.Query(request);
DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);

Expand All @@ -167,7 +167,7 @@ public void Directions_VerifyBounds()
}

[Test]
public void Directions_WithIcons()
public async Task Directions_WithIcons()
{
var dep_time = DateTime.Today
.AddDays(1)
Expand All @@ -184,7 +184,7 @@ public void Directions_WithIcons()

};

DirectionsResponse result = GoogleMaps.Directions.Query(request);
DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);

Expand All @@ -200,7 +200,7 @@ public void Directions_WithIcons()
}

[Test]
public void Directions_WithRegionSearch()
public async Task Directions_WithRegionSearch()
{
var dep_time = DateTime.Today
.AddDays(1)
Expand All @@ -216,15 +216,15 @@ public void Directions_WithRegionSearch()
ApiKey = ApiKey
};

DirectionsResponse result = GoogleMaps.Directions.Query(request);
DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.IsNotEmpty(result.Routes);
Assert.True(result.Status.Equals(DirectionsStatusCodes.OK));
}

[Test]
public void Directions_CanGetDurationWithTraffic()
public async Task Directions_CanGetDurationWithTraffic()
{
var request = new DirectionsRequest
{
Expand All @@ -233,7 +233,7 @@ public void Directions_CanGetDurationWithTraffic()
DepartureTime = DateTime.Now.Date.AddDays(1).AddHours(8),
ApiKey = ApiKey //Duration in traffic requires an API key
};
var result = GoogleMaps.Directions.Query(request);
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);

Expand All @@ -255,7 +255,7 @@ public void Directions_CanGetLongDistanceTrain()
DepartureTime = new DateTime(2018, 08, 18, 15, 30, 00)
};

Assert.DoesNotThrow(() => GoogleMaps.Directions.Query(request));
Assert.DoesNotThrowAsync(async () => await GoogleMaps.Directions.QueryAsync(request));
}
}
}
Loading