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

Feat/support dependency injection #115

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e7b55d3
removed sensor property
ericnewton76 Oct 29, 2017
040977d
moved types in Shared to Common
ericnewton76 Oct 29, 2017
577439a
moved serialization helpers into Internal.Serialization
ericnewton76 Oct 29, 2017
f74d340
namespace changes
ericnewton76 Oct 29, 2017
f26e118
more namespace changes
ericnewton76 Oct 29, 2017
b2d466c
rename MapColor/MapSize to GColor/GSize and move into Common namespace
ericnewton76 Oct 29, 2017
cf05261
Fixed reference to MapSize=>GSize
ericnewton76 Oct 29, 2017
bbfd5e8
Merge branch 'master' into namespaces-reorg
ericnewton76 Oct 29, 2017
8fea147
Merge branch 'namespaces-reorg' of github.com:ericnewton76/gmaps-api-…
ericnewton76 Oct 29, 2017
d62bc33
created base set of interfaces for DI containers
ericnewton76 Oct 30, 2017
1146df4
created default facade for easiest access to the services without usi…
ericnewton76 Oct 30, 2017
46ad33b
updated MapsHttp to be an IHttpService
ericnewton76 Oct 30, 2017
d3033bd
updated GeocodingService and updated the ConsoleSample program
ericnewton76 Oct 30, 2017
748452a
split up to support services that might return more than simple one r…
ericnewton76 Oct 30, 2017
835678b
change all services to utilize baseclass and constructor dependency i…
ericnewton76 Oct 30, 2017
4dcc69b
updates to test classes
ericnewton76 Oct 30, 2017
b7c3b7d
Merge branch 'master' into feat/support-dependency-injection
ericnewton76 Oct 30, 2017
c76b373
updates to get everything compiling again
ericnewton76 Oct 30, 2017
616c366
reformatting
ericnewton76 Oct 30, 2017
b54e571
fixed typo of not transferring HttpsUri correctly
ericnewton76 Oct 30, 2017
2a25a97
asynchelper to run task syncronously from Microsft.Aspnet.Identity
ericnewton76 Oct 30, 2017
843f50c
fixed notimplemented problem
ericnewton76 Oct 30, 2017
19463d7
updates to README.md regarding the dependency injection updates
ericnewton76 Oct 30, 2017
1b819de
updated appveyor version number to indicate breaking change
ericnewton76 Oct 30, 2017
e91f2e8
updated appveyor version number to indicate breaking change
ericnewton76 Oct 30, 2017
74a6e47
Merge branch 'feat/support-dependency-injection' of github.com:ericne…
ericnewton76 Feb 23, 2019
e267ae7
got project&tests building
ericnewton76 Feb 23, 2019
3590a95
Merge branch 'master' into feat/support-dependency-injection
ericnewton76 Feb 23, 2019
6f28290
remove accidental orig files
ericnewton76 Feb 23, 2019
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
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PS> Install-Package gmaps-api-net
This project attempts to provide all the features available in the Google Maps API. It is being developed in C# for the Microsoft .NET including .Net Framework v4.6.1+ and .Net Standard v1.3+. *gmaps-api-net* is a fully featured API client library, providing strongly typed access to the API.

## Notable Upcoming
* Trying to achieve a formal v1.0 release for 2018. This is basically on-track for first week of January. File any major issues quickly to get addressed before v1.0!
* Trying to achieve a formal v1.0 release. File any major issues quickly to get addressed before v1.0!
* Planning a slight namespace/usage change for v2.0 release soon thereafter to support dependency injection and mocking away the library in your own testing apparatus. Intention here is to isolate away the library returning values to returning known values during your testing. See branch [feat/support-dependency-injection](https://github.com/ericnewton76/gmaps-api-net/tree/feat/support-dependency-injection)
* In relation to above, we will begin removing our tests for specific values, and testing instead for schema changes that Google is pushing through.

Expand All @@ -41,12 +41,12 @@ Google is now requiring a proper API key for accessing the service. Create a key
Let's suppose we want to search an address and get more information about it. We can write:

```c#
//always need to use YOUR_API_KEY for requests. Do this in App_Start.
GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY"));
//always need to use YOUR_API_KEY for requests.
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

var request = new GeocodingRequest();
request.Address = "1600 Pennsylvania Ave NW, Washington, DC 20500";
var response = new GeocodingService().GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);

//The GeocodingService class submits the request to the API web service, and returns the
//response strongly typed as a GeocodeResponse object which may contain zero, one or more results.
Expand All @@ -71,11 +71,12 @@ else
Static Maps API support allows you to get a valid url or a streamed bitmap which you can use:

```c#
//always need to use YOUR_API_KEY for requests. Do this in App_Start.
GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY"));
//always need to use YOUR_API_KEY for requests.
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

var map = new StaticMapRequest();
map.Center = new Location("1600 Pennsylvania Ave NW, Washington, DC 20500");
map.Size = new System.Drawing.Size(400, 400);
map.Size = new GSize(400, 400);
map.Zoom = 14;
```

Expand Down Expand Up @@ -112,33 +113,35 @@ this.imageControl.Image = img;

```c#
//enterprise users to use your supplied information for requests. Do this in App_Start.
GoogleSigned.AssignAllServices(new GoogleSigned("gme-your-client-id", "your-signing-key", signType: GoogleSignedType.Business));
var GMaps = new Google.Maps.Services(new GoogleSigned("gme-your-client-id", "your-signing-key"));

// Then do as many requests as you like...
var request = new GeocodingRequest();
//...
var response = GeocodingService.GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);
```

### Using a Google Maps API key

```c#
//always need to use YOUR_API_KEY for requests. Do this in App_Start.
GoogleSigned.AssignAllServices(new GoogleSigned("your-api-key"));
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

// Then do as many requests as you like...
var request = new GeocodingRequest();
//...
var response = GeocodingService.GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);
```

You can also use a particular key for a single request:

```c#
const GoogleSigned apikey = new GoogleSigned("special_api_key_here");
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

var GMapsSecretKey = GMaps.WithSigningService(new GoogleApiSigningService(new GoogleSigned("special_api_key_here"));
var request = new GeocodingRequest();
//...
var service = new GeocodingService(request, apikey);
var service = GMapsSecretKey.GeocodingService.GetResponse(request);
```

## Contact
Expand All @@ -150,6 +153,7 @@ Questions, comments and/or suggestions are welcome! Please raise an [issue](http
## Contributors
A big thank you to all of our [contributors](https://github.com/ericnewton76/gmaps-api-net/graphs/contributors) including:

- [Luis Farzati](https://github.com/luisfarzati)
- [Eric Newton](https://github.com/ericnewton76)
- [Sheepzez](https://github.com/Sheepzez)
- [Mieliespoor](https://github.com/mieliespoor)
Expand Down
10 changes: 5 additions & 5 deletions src/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Google.Maps;
using Google.Maps.Geocoding;
using Google.Maps.Common;

namespace ConsoleApp1
{
Expand All @@ -27,11 +28,11 @@ static void Main(string[] args)
static void README_QuickStart_Sample1()
{
//always need to use YOUR_API_KEY for requests. Do this in App_Start.
GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY"));
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

var request = new GeocodingRequest();
request.Address = "1600 Pennsylvania Ave NW, Washington, DC 20500";
var response = new GeocodingService().GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);

//The GeocodingService class submits the request to the API web service, and returns the
//response strongly typed as a GeocodeResponse object which may contain zero, one or more results.
Expand Down Expand Up @@ -83,16 +84,15 @@ static void DoRequestsLoop()
static void DoGeocodeRequest()
{
//always need to use YOUR_API_KEY for requests. Do this in App_Start.
//GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY"));
//commented out in the loop
var GMaps = new Google.Maps.Services("YOUR_API_KEY");

Console.WriteLine();
Console.WriteLine("Enter an address to geocode: ");
string geocodeAddress = Console.ReadLine();

var request = new GeocodingRequest();
request.Address = geocodeAddress;
var response = new GeocodingService().GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);

//The GeocodingService class submits the request to the API web service, and returns the
//response strongly typed as a GeocodeResponse object which may contain zero, one or more results.
Expand Down
1 change: 1 addition & 0 deletions src/Google.Maps.Test/Direction/DirectionRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Specialized;

using NUnit.Framework;
using Google.Maps.Common;

namespace Google.Maps.Direction
{
Expand Down
13 changes: 11 additions & 2 deletions src/Google.Maps.Test/Direction/DirectionServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

using NUnit.Framework;

using Google.Maps.Shared;
using Google.Maps.ApiCore;
using Google.Maps.Common;
using Google.Maps.Internal;

namespace Google.Maps.Direction
{
Expand All @@ -32,7 +34,14 @@ class DirectionServiceTests

DirectionService CreateService()
{
var svc = new DirectionService(TestingApiKey);
var svc = new DirectionService(
new Internal.MapsHttp(
new GoogleApiSigningService(
TestingApiKey
)
),
baseUri:null);

return svc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;

using NUnit.Framework;
using Google.Maps.ApiCore;
using Google.Maps.Common;

namespace Google.Maps.DistanceMatrix
{
Expand All @@ -12,7 +14,14 @@ public class DistanceMatrixServiceTests

DistanceMatrixService CreateService()
{
var svc = new DistanceMatrixService(TestingApiKey);
var svc = new DistanceMatrixService(
new Internal.MapsHttp(
new GoogleApiSigningService(
TestingApiKey
)
),
baseUri: null
);
return svc;
}

Expand Down
12 changes: 11 additions & 1 deletion src/Google.Maps.Test/Elevation/ElevationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System;

using NUnit.Framework;
using Google.Maps.ApiCore;
using Google.Maps.Common;

namespace Google.Maps.Elevation
{
Expand All @@ -28,7 +30,15 @@ public class ElevationServiceTests

ElevationService CreateService()
{
var svc = new ElevationService(TestingApiKey);
var svc = new ElevationService(
new Internal.MapsHttp(
new GoogleApiSigningService(
TestingApiKey
)
),
baseUri:null
);

return svc;
}

Expand Down
15 changes: 12 additions & 3 deletions src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

using NUnit.Framework;

using Google.Maps.Shared;
using Google.Maps.Common;
using Google.Maps.ApiCore;
using Google.Maps.Internal;

namespace Google.Maps.Geocoding
{
Expand All @@ -32,7 +34,14 @@ class GeocodingServiceTests

GeocodingService CreateService()
{
var svc = new GeocodingService(TestingApiKey);
var svc = new GeocodingService(
new Internal.MapsHttp(
new GoogleApiSigningService(
TestingApiKey
)
),
baseUri: null
);
return svc;
}

Expand Down Expand Up @@ -230,7 +239,7 @@ public void Utf8_Request_And_Response()
Address = "AL. GRUNWALDZKA 141, Gdańsk, 80 - 264, POLAND"
};

var response = new GeocodingService().GetResponse(request);
var response = CreateService().GetResponse(request);

if(response.Status == ServiceResponseStatus.OverQueryLimit)
{
Expand Down
18 changes: 13 additions & 5 deletions src/Google.Maps.Test/GoogleMapsForBusinessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NUnit.Framework;

using Google.Maps.Geocoding;
using Google.Maps.Common;

namespace Google.Maps
{
Expand All @@ -21,6 +22,15 @@ namespace Google.Maps
[Category("External Integrations")]
class GoogleMapsForBusinessTests
{
GoogleSigned TestingApiKey;
Google.Maps.Services GMaps;

[OneTimeSetUp]
public void OneTimeSetup()
{
TestingApiKey = GetRealSigningInstance();
}

private GoogleSigned GetRealSigningInstance()
{
#if NETSTANDARD1
Expand Down Expand Up @@ -53,8 +63,7 @@ public void Geocoding_Request_Signed_With_Private_Key()
Address = "Stathern, UK"
};

GoogleSigned.AssignAllServices(GetRealSigningInstance());
var response = new GeocodingService().GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);

Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
}
Expand All @@ -64,16 +73,15 @@ public void Geocoding_Request_Signed_With_Private_Key()
public void Geocoding_Request_Signed_With_Api_Key()
{
// Arrange
var sign = new GoogleSigned("AIzaSyDV-0ftj1tsjfd6GnEbtbxwHXnv6iR3UEU");
GoogleSigned.AssignAllServices(sign);
var GMaps = new Google.Maps.Services("AIzaSyDV-0ftj1tsjfd6GnEbtbxwHXnv6iR3UEU");

var request = new GeocodingRequest
{
Address = "Stathern, UK"
};

// Act
var response = new GeocodingService().GetResponse(request);
var response = GMaps.GeocodingService.GetResponse(request);

// Assert
Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
Expand Down
1 change: 1 addition & 0 deletions src/Google.Maps.Test/LatLngComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;

using NUnit.Framework;
using Google.Maps.Internal;

namespace Google.Maps
{
Expand Down
19 changes: 10 additions & 9 deletions src/Google.Maps.Test/MapColorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using Google.Maps.Common;

namespace Google.Maps
{
Expand All @@ -8,9 +9,9 @@ public class MapColorTests
[Test]
public void IsUndefined_Works()
{
var undefined = new MapColor();
var definedName = MapColor.FromName("red");
var definedRGB = MapColor.FromArgb(255,255,255);
var undefined = new GColor();
var definedName = GColor.FromName("red");
var definedRGB = GColor.FromArgb(255,255,255);

Assert.AreEqual(true, undefined.IsUndefined);
Assert.AreEqual(false, definedName.IsUndefined);
Expand All @@ -20,9 +21,9 @@ public void IsUndefined_Works()
[Test]
public void To24BitColor_Works()
{
var namedColor = MapColor.FromName("red");
var rgbColor = MapColor.FromArgb(255, 0, 0);
var rgbaColor = MapColor.FromArgb(255, 255, 0, 0);
var namedColor = GColor.FromName("red");
var rgbColor = GColor.FromArgb(255, 0, 0);
var rgbaColor = GColor.FromArgb(255, 255, 0, 0);

Assert.AreEqual("red", namedColor.To24BitColorString());
Assert.AreEqual("0xFF0000", rgbColor.To24BitColorString());
Expand All @@ -32,9 +33,9 @@ public void To24BitColor_Works()
[Test]
public void To32BitColor_Works()
{
var namedColor = MapColor.FromName("red");
var rgbColor = MapColor.FromArgb(255, 0, 0);
var rgbaColor = MapColor.FromArgb(255, 255, 0, 0);
var namedColor = GColor.FromName("red");
var rgbColor = GColor.FromArgb(255, 0, 0);
var rgbaColor = GColor.FromArgb(255, 255, 0, 0);

Assert.AreEqual("red", namedColor.To32BitColorString());
Assert.AreEqual("0xFF0000FF", rgbColor.To32BitColorString());
Expand Down
Loading