Exemplo n.º 1
0
        public void GetQueryStringParametersTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key     = "key",
                PlaceId = "placeId"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var key         = queryStringParameters.FirstOrDefault(x => x.Key == "key");
            var keyExpected = request.Key;

            Assert.IsNotNull(key);
            Assert.AreEqual(keyExpected, key.Value);

            var placeId         = queryStringParameters.FirstOrDefault(x => x.Key == "placeid");
            var placeIdExpected = request.PlaceId;

            Assert.IsNotNull(placeId);
            Assert.AreEqual(placeIdExpected, placeId.Value);

            var language = queryStringParameters.FirstOrDefault(x => x.Key == "language");

            Assert.IsNotNull(language);
            Assert.AreEqual("en", language.Value);
        }
Exemplo n.º 2
0
        public void GetQueryStringParametersTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key     = "abc",
                PlaceId = "test"
            };

            Assert.DoesNotThrow(() => request.GetQueryStringParameters());
        }
Exemplo n.º 3
0
        public void GetQueryStringParametersWhenKeyIsStringEmptyTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key = string.Empty
            };

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

            Assert.AreEqual(exception.Message, "'Key' is required");
        }
Exemplo n.º 4
0
        public void GetQueryStringParametersWhenPlaceIdIsNullTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key     = "key",
                PlaceId = null
            };

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

            Assert.AreEqual(exception.Message, "'PlaceId' is required");
        }
Exemplo n.º 5
0
        public void GetQueryStringParametersWhenSessionTokenTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key          = "key",
                PlaceId      = "placeId",
                SessionToken = "sessiontoken"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var sessiontoken         = queryStringParameters.FirstOrDefault(x => x.Key == "sessiontoken");
            var sessiontokenExpected = request.SessionToken;

            Assert.IsNotNull(sessiontoken);
            Assert.AreEqual(sessiontokenExpected, sessiontoken.Value);
        }
Exemplo n.º 6
0
        public void GetQueryStringParametersWhenRegionTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key     = "key",
                PlaceId = "placeId",
                Region  = "region"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var region         = queryStringParameters.FirstOrDefault(x => x.Key == "region");
            var regionExpected = request.Region;

            Assert.IsNotNull(region);
            Assert.AreEqual(regionExpected, region.Value);
        }
Exemplo n.º 7
0
        public void GetQueryStringParametersWhenFieldsTest()
        {
            var request = new PlacesDetailsRequest
            {
                Key     = "key",
                PlaceId = "placeId",
                Fields  = FieldTypes.Basic
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var fields         = queryStringParameters.FirstOrDefault(x => x.Key == "fields");
            var fieldsExpected = Enum.GetValues(typeof(FieldTypes))
                                 .Cast <FieldTypes>()
                                 .Where(x => request.Fields.HasFlag(x) && x != FieldTypes.Basic && x != FieldTypes.Contact && x != FieldTypes.Atmosphere)
                                 .Aggregate(string.Empty, (current, x) => $"{current}{x.ToString().ToLowerInvariant()},");

            fieldsExpected = fieldsExpected.EndsWith(",") ? fieldsExpected.Substring(0, fieldsExpected.Length - 1) : fieldsExpected;

            Assert.IsNotNull(fields);
            Assert.AreEqual(fieldsExpected, fields.Value);
        }