Ejemplo n.º 1
0
        public async Task <T> GetByIdAsync <TMember>(TMember id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            ValidateIdObject(id);

            await EnsureDomainCreated();

            var resp = await _client.GetAttributesAsync(new GetAttributesRequest
            {
                DomainName = _domainName,
                ItemName   = _primitiveSerializer.Serialize(id)
            });

            if (!HttpUtility.IsSuccessStatusCode(resp.HttpStatusCode))
            {
                throw new Exception("Something went wrong");
            }
            if (resp.Attributes.Count == 0)
            {
                throw new KeyNotFoundException($"No item with id {id} was found");
            }

            return(Deserialize(resp.Attributes));
        }
Ejemplo n.º 2
0
        public IQuery <T> In <TMember>(Expression <Func <T, TMember> > member, params TMember[] values)
        {
            MemberExpression memExp = null;

            if ((memExp = member.Body as MemberExpression) == null)
            {
                throw new ArgumentException($"{nameof(In)} can not be called with an expression of type {member.Body.GetType().Name}");
            }

            var memberName = _parser.ExtractMemberName(memExp);

            EnsureMemberQueryable(memberName);
            var attrName = GetMemberAttributeName(memberName);

            var valueStrings = values.Select(v => _serializer.Serialize(v)).ToArray();

            return(new Query <T>(new InCondition(attrName, valueStrings)));
        }
Ejemplo n.º 3
0
        private void PrimitiveAttributeSerializer_SerializeNumber_RoundtripSuccessfull(object value, Type type)
        {
            // arrange
            var serializer = new PrimitiveAttributeSerializer();
            // act
            var str          = serializer.Serialize(value);
            var roundtripped = serializer.Deserialize(str, type);

            // assert
            Assert.Equal(value, roundtripped);
        }
Ejemplo n.º 4
0
        public void PrimitiveAttributeSerializer_SerializeEnum_RoundtripSuccessfull(Enum value)
        {
            // arrange
            var serializer = new PrimitiveAttributeSerializer();

            // act
            var strVal       = serializer.Serialize(value);
            var roundtripped = serializer.Deserialize(strVal, value.GetType());

            // assert
            Assert.Equal(value, roundtripped);
        }
Ejemplo n.º 5
0
        public void PrimitiveAttributeSerializer_SerializeNumber_PaddingLengthCorrect(Type type)
        {
            // arrange
            var       serializer = new PrimitiveAttributeSerializer();
            FieldInfo fi         = type.GetField("MaxValue");
            object    maxValue   = fi.GetRawConstantValue();
            object    value      = Convert.ChangeType(1, type);

            // act
            var serialized = serializer.Serialize(value);

            // assert
            Assert.Equal(maxValue.ToString().Length, serialized.Length);
        }
Ejemplo n.º 6
0
 private string ParseExpression <T>(ConstantExpression exp)
 {
     return($"'{QueryEncodingUtility.EncodeValue(_serializer.Serialize(exp.Value))}'");
 }