コード例 #1
0
        public void GetQueryStringParametersTest()
        {
            var request = new ImageSearchRequest
            {
                Key            = "abc",
                SearchEngineId = "abc",
                Query          = "abc"
            };

            Assert.DoesNotThrow(() => request.GetQueryStringParameters());
        }
コード例 #2
0
        public void GetQueryStringParametersWhenKeyIsStringEmptyTest()
        {
            var request = new ImageSearchRequest
            {
                Key = string.Empty
            };

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

            Assert.AreEqual(exception.Message, "Key is required");
        }
コード例 #3
0
        public void GetQueryStringParametersWhenQueryIsNullTest()
        {
            var request = new ImageSearchRequest
            {
                Key   = "abc",
                Query = null
            };

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

            Assert.AreEqual(exception.Message, "Query is required");
        }
コード例 #4
0
        public void GetQueryStringParametersWhenSearchEngineIdIsNullTest()
        {
            var request = new ImageSearchRequest
            {
                Key            = this.ApiKey,
                Query          = "google",
                SearchEngineId = null
            };

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

            Assert.AreEqual(exception.Message, "SearchEngineId is required");
        }
コード例 #5
0
        public void GetQueryStringParametersWhenOptionsNumberIsGreaterThanNineTest()
        {
            var request = new ImageSearchRequest
            {
                Key            = "abc",
                Query          = "google",
                SearchEngineId = "abc",
                Options        =
                {
                    Number = 11
                }
            };

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

            Assert.AreEqual(exception.Message, "Number must be between 1 and 10");
        }
コード例 #6
0
        public void GetQueryStringParametersWhenSafetyLevelInterfaceLanguageIsNotSupportedTest()
        {
            var request = new ImageSearchRequest
            {
                Key            = "abc",
                Query          = "google",
                SearchEngineId = "abc",
                Options        =
                {
                    SafetyLevel       = SafetyLevel.Medium,
                    InterfaceLanguage = Language.Afrikaans
                }
            };

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

            Assert.AreEqual(exception.Message, $"SafetyLevel is not allowed for specified InterfaceLanguage: {request.Options.InterfaceLanguage}");
        }