Beispiel #1
0
        public void PlacesAddWhenInvalidKeyTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = "test",
                Name        = Guid.NewGuid().ToString("N"),
                Types       = new[] { PlaceLocationType.Street_Address },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = Guid.NewGuid().ToString("N"),
                Website     = "http://www.google.com",
                Language    = Language.English
            };

            var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Add.Query(request));

            Assert.IsNotNull(exception);
            Assert.AreEqual("One or more errors occurred.", exception.Message);

            var innerException = exception.InnerExceptions.FirstOrDefault();

            Assert.IsNotNull(innerException);
            Assert.AreEqual(typeof(GoogleApiException), innerException.GetType());
            Assert.AreEqual("The provided API key is invalid.", innerException.Message);
        }
Beispiel #2
0
        public void PlacesAddWhenAsyncAndCancelledTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = this.ApiKey,
                Name        = Guid.NewGuid().ToString("N"),
                Types       = new[] { PlaceLocationType.Street_Address },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = "MyAddress",
                Website     = "http://www.google.com",
                Language    = Language.English
            };

            var cancellationTokenSource = new CancellationTokenSource();
            var task = GooglePlaces.Add.QueryAsync(request, cancellationTokenSource.Token);

            cancellationTokenSource.Cancel();

            var exception = Assert.Throws <OperationCanceledException>(() => task.Wait(cancellationTokenSource.Token));

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "The operation was canceled.");
        }
Beispiel #3
0
        public void ConstructorDefaultTest()
        {
            var request = new PlacesAddRequest();

            Assert.IsTrue(request.IsSsl);
            Assert.AreEqual(Language.English, request.Language);
        }
Beispiel #4
0
        public void PlacesDeleteWhenAsyncTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = Guid.NewGuid().ToString("N"),
                Types    = new[] { PlaceLocationType.Street_Address },
                Location = new Location(55.664425, 12.502264)
            };

            var response = GooglePlaces.Add.Query(request);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.PlaceId);

            var request2 = new PlacesDeleteRequest
            {
                Key     = this.ApiKey,
                PlaceId = response.PlaceId
            };

            var response2 = GooglePlaces.Delete.QueryAsync(request2).Result;

            Assert.IsNotNull(response2);
            Assert.AreEqual(response2.Status, Status.Ok);
        }
Beispiel #5
0
        public void PlacesAddWhenAsyncAndTimeoutTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = this.ApiKey,
                Name        = Guid.NewGuid().ToString("N"),
                Types       = new[] { PlaceLocationType.Street_Address },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = "MyAddress",
                Website     = "http://www.google.com",
                Language    = Language.English
            };

            var exception = Assert.Throws <AggregateException>(() =>
            {
                var result = GooglePlaces.Add.QueryAsync(request, TimeSpan.FromMilliseconds(1)).Result;
                Assert.IsNull(result);
            });

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "One or more errors occurred.");

            var innerException = exception.InnerException;

            Assert.IsNotNull(innerException);
            Assert.AreEqual(innerException.GetType(), typeof(TaskCanceledException));
            Assert.AreEqual(innerException.Message, "A task was canceled.");
        }
Beispiel #6
0
        public void PlacesAddWhenApiKeyIsStringEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key = string.Empty
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "ApiKey must be provided");
        }
Beispiel #7
0
        public void PlacesAddWhenNameIsStringEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key  = this.ApiKey,
                Name = string.Empty
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "Name is required");
        }
Beispiel #8
0
        public void PlacesAddWhenNameIsNullTest()
        {
            var request = new PlacesAddRequest
            {
                Key  = this.ApiKey,
                Name = null
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "Name must be provided.");
        }
Beispiel #9
0
        public void PlacesAddWhenLocationIsNullTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = "Home",
                Location = null
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "Location is required");
        }
Beispiel #10
0
        public void PlacesAddWhenKeyIsStringEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = string.Empty,
                Name     = "test",
                Location = new Location(0, 0),
                Types    = new[] { PlaceLocationType.StreetAddress }
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "Key is required.");
        }
Beispiel #11
0
        public void PlacesAddWhenTypesIsEmotyTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = "Home",
                Location = new Location(55.664425, 12.502264),
                Types    = new PlaceLocationType[0]
            };

            var exception = Assert.Throws <ArgumentException>(() => GooglePlaces.Add.Query(request));

            Assert.AreEqual(exception.Message, "Types must be provided. At least one type must be specified.");
        }
Beispiel #12
0
        public void GetQueryStringParametersWhenNameIsStringEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key  = this.ApiKey,
                Name = string.Empty
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.AreEqual(exception.Message, "Name must be provided");
        }
Beispiel #13
0
        public void GetQueryStringParametersWhenLocationIsNullTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = "Home",
                Location = null
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.AreEqual(exception.Message, "Location must be provided");
        }
Beispiel #14
0
        public void GetQueryStringParametersWhenKeyIsStringEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = string.Empty,
                Name     = "test",
                Location = new Location(0, 0),
                Types    = new[] { PlaceLocationType.Street_Address }
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.AreEqual(exception.Message, "Key is required");
        }
Beispiel #15
0
        public void GetQueryStringParametersWhenTypesIsEmptyTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = "Home",
                Location = new Location(55.664425, 12.502264),
                Types    = new PlaceLocationType[0]
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.AreEqual(exception.Message, "Types must be provided. At least one type must be specified");
        }
Beispiel #16
0
        public void PlacesDeleteTest()
        {
            var request = new PlacesAddRequest
            {
                Key      = this.ApiKey,
                Name     = Guid.NewGuid().ToString("N"),
                Types    = new[] { PlaceLocationType.Street_Address },
                Location = new Location(55.664425, 12.502264)
            };

            var response = GooglePlaces.Add.Query(request);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.PlaceId);

            var request2 = new PlacesDeleteRequest
            {
                Key     = this.ApiKey,
                PlaceId = response.PlaceId
            };

            var response2 = GooglePlaces.Delete.Query(request2);

            Assert.IsNotNull(response2);
            Assert.AreEqual(response2.Status, Status.Ok);

            var request3 = new PlacesDetailsRequest
            {
                Key     = this.ApiKey,
                PlaceId = response.PlaceId
            };

            var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.Query(request3));

            Assert.IsNotNull(exception);
            Assert.AreEqual("One or more errors occurred.", exception.Message);

            var innerException = exception.InnerExceptions.FirstOrDefault() as GoogleApiException;

            Assert.IsNotNull(innerException);
            Assert.AreEqual(typeof(GoogleApiException), innerException.GetType());
            Assert.AreEqual(Status.NotFound, innerException.Status);
            Assert.AreEqual("Exception of type 'GoogleApi.Exceptions.GoogleApiException' was thrown.", innerException.Message);
        }
Beispiel #17
0
        public void PlacesAddTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = this.ApiKey,
                Name        = Guid.NewGuid().ToString("N"),
                Types       = new[] { PlaceLocationType.Street_Address },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = Guid.NewGuid().ToString("N"),
                Website     = "http://www.google.com",
                Language    = Language.English
            };
            var response = GooglePlaces.Add.Query(request);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.PlaceId);
            Assert.AreEqual(response.Scope, Scope.App);
            Assert.AreEqual(response.Status, Status.Ok);

            var request2 = new PlacesDetailsRequest
            {
                Key     = this.ApiKey,
                PlaceId = response.PlaceId
            };

            var response2 = GooglePlaces.Details.Query(request2);

            Assert.IsNotNull(response2);
            Assert.AreEqual(Status.Ok, response2.Status);
            Assert.AreEqual(response2.Result.Name, request.Name);
            Assert.AreEqual(response2.Result.Website, request.Website);
            Assert.AreEqual(response2.Result.FormattedAddress, request.Address);
            Assert.AreEqual(response2.Result.FormattedPhoneNumber, request.PhoneNumber);
            Assert.AreEqual(response2.Result.Geometry.Location.Latitude, request.Location.Latitude);
            Assert.AreEqual(response2.Result.Geometry.Location.Longitude, request.Location.Longitude);

            Assert.AreEqual(Scope.App, response2.Result.Scope);
            Assert.AreEqual(response2.Result.PlaceId, response.PlaceId);
            Assert.AreEqual(PlaceLocationType.Street_Address, response2.Result.Types.FirstOrDefault());
        }
Beispiel #18
0
        public void PlacesAddAsyncTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = this.ApiKey,
                Name        = "Home",
                Types       = new[] { PlaceLocationType.StreetAddress },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = "J. P. E. Hartmanns Allé 35 2500 Valby, Denmark",
                Website     = "http://www.google.com",
                Language    = "en-US"
            };
            var response = GooglePlaces.Add.QueryAsync(request).Result;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.PlaceId);
            Assert.AreEqual(response.Scope, Scope.App);
            Assert.AreEqual(response.Status, Status.Ok);
        }
Beispiel #19
0
        public void PlacesAddWhenAsyncTest()
        {
            var request = new PlacesAddRequest
            {
                Key         = this.ApiKey,
                Name        = Guid.NewGuid().ToString("N"),
                Types       = new[] { PlaceLocationType.Street_Address },
                Location    = new Location(55.664425, 12.502264),
                Accuracy    = 50,
                PhoneNumber = "+45 00000000",
                Address     = "MyAddress",
                Website     = "http://www.google.com",
                Language    = Language.English
            };
            var response = GooglePlaces.Add.QueryAsync(request).Result;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.PlaceId);
            Assert.AreEqual(response.Scope, Scope.App);
            Assert.AreEqual(response.Status, Status.Ok);
        }