Beispiel #1
0
        /// <summary>
        /// Adds a query parameter.
        /// </summary>
        /// <typeparam name="U">The type of property to add the query for.</typeparam>
        /// <param name="property">The property to add the query for.</param>
        /// <param name="value">The value of the query.</param>
        /// <returns>The instance of its self with the new query parameter.</returns>
        public CardService Where <U>(Expression <Func <CardQueryParameter, U> > property, U value)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            MemberExpression expression = property.Body as MemberExpression;
            var queryName = QueryUtility.GetQueryPropertyName <CardQueryParameter>(expression.Member.Name);

            Type valueType = value.GetType();

            if (valueType.IsArray)
            {
                string val = string.Join("|", (IEnumerable <object>)value);
                this._whereQueries[queryName] = val;
            }
            else
            {
                this._whereQueries[queryName] = Convert.ToString(value);
            }

            return(this);
        }
Beispiel #2
0
 public void GetQueryPropertyName_PropertyNameNull_Throws()
 {
     // arrange
     // act
     // assert
     Assert.Throws <ArgumentNullException>(() => QueryUtility.GetQueryPropertyName <DtoTestObject>(null));
 }
Beispiel #3
0
        public void GetQueryPropertyNameTest()
        {
            try
            {
                // Test exception is thrown.
                var result = QueryUtility.GetQueryPropertyName <CardDto>(null);
                Assert.True(false);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal("propertyName", ex.ParamName);
            }
            catch
            {
                Assert.True(false);
            }

            // Property doesn't exist.
            Assert.Null(QueryUtility.GetQueryPropertyName <DtoTestObject>("fakeProperty"));

            // Attribute doesn't exist.
            Assert.Null(QueryUtility.GetQueryPropertyName <DtoTestObject>("Property1"));

            // Property exists.
            Assert.Equal("jsonProperty2", QueryUtility.GetQueryPropertyName <DtoTestObject>("Property2"));
        }
Beispiel #4
0
        /// <summary>
        /// Adds a query parameter.
        /// </summary>
        /// <typeparam name="U">The type of property to add the query for.</typeparam>
        /// <param name="property">The property to add the query for.</param>
        /// <param name="value">The value of the query.</param>
        /// <returns>The instance of its self with the new query parameter.</returns>
        public CardService Where <U>(Expression <Func <CardQueryParameter, U> > property, U value)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (EqualityComparer <U> .Default.Equals(value, default(U)))
            {
                throw new ArgumentNullException(nameof(value));
            }

            MemberExpression expression = property.Body as MemberExpression;
            var queryName = QueryUtility.GetQueryPropertyName <CardQueryParameter>(expression.Member.Name);

            Type valueType = value.GetType();

            if (valueType.IsArray)
            {
                _whereQueries[queryName] = string.Join("|", (IEnumerable <object>)value);
            }
            else
            {
                _whereQueries[queryName] = Convert.ToString(value);
            }

            return(this);
        }
Beispiel #5
0
        public void GetQueryPropertyName_AttributeDoesNotExist_ReturnsNull()
        {
            // arrange
            // act
            var result = QueryUtility.GetQueryPropertyName <DtoTestObject>("Property1");

            // assert
            Assert.Null(result);
        }
Beispiel #6
0
        public void GetQueryPropertyName_Success()
        {
            // arrange
            // act
            var result = QueryUtility.GetQueryPropertyName <DtoTestObject>("Property2");

            // assert
            Assert.Equal("jsonProperty2", result);
        }
        /// <inheritdoc />
        public ICardService Where <U>(Expression <Func <CardQueryParameter, U> > property, U value)
        {
            if (EqualityComparer <U> .Default.Equals(value, default))
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (!(property.Body is MemberExpression expression))
            {
                throw new ArgumentNullException(nameof(property));
            }

            var queryName = QueryUtility.GetQueryPropertyName <CardQueryParameter>(expression.Member.Name);

            CurrentQueryUrl.SetQueryParam(queryName, Convert.ToString(value));

            return(this);
        }
        /// <summary>
        /// Adds a query parameter.
        /// </summary>
        /// <typeparam name="U">The type of property to add the query for.</typeparam>
        /// <param name="property">The property to add the query for.</param>
        /// <param name="value">The value of the query.</param>
        /// <returns>The instance of its self with the new query parameter.</returns>
        public SetService Where <U>(Expression <Func <SetQueryParameter, U> > property, U value)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (EqualityComparer <U> .Default.Equals(value, default(U)))
            {
                throw new ArgumentNullException(nameof(value));
            }

            MemberExpression expression = property.Body as MemberExpression;
            var queryName = QueryUtility.GetQueryPropertyName <SetQueryParameter>(expression.Member.Name);

            _whereQueries[queryName] = Convert.ToString(value);

            return(this);
        }
Beispiel #9
0
        /// <summary>
        /// Adds a query parameter.
        /// </summary>
        /// <typeparam name="U">The type of property to add the query for.</typeparam>
        /// <param name="property">The property to add the query for.</param>
        /// <param name="value">The value of the query.</param>
        /// <returns>The instance of its self with the new query parameter.</returns>
        public SetService Where <U>(Expression <Func <SetQueryParameter, U> > property, U value)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            MemberExpression expression = property.Body as MemberExpression;
            var queryName = QueryUtility.GetQueryPropertyName <SetQueryParameter>(expression.Member.Name);

            _whereQueries[queryName] = Convert.ToString(value);

            return(this);
        }