Ejemplo n.º 1
0
 void DefaultEventHandler(IEventRecord r)
 {
     try
     {
         var obj = _propertyExtractor.Extract(r);
         lock (_lock) { _records.Add(obj.ToPSObject()); }
     }
     catch
     {
         // TODO: log bad record parse
     }
 }
Ejemplo n.º 2
0
        public void For_Extract_When_ExpressionIsNull_Then_ExceptionIsThrown()
        {
            // Arrange:
            Expression <Func <TestPerson, string> > expression = null;

            // Act & Assert:
            var extractor = new PropertyExtractor <TestPerson>();

            Assert.Throws <ArgumentNullException>(() => extractor.Extract(expression));
        }
        public void FillProps()
        {
            TestObject to = new TestObject();

            to.p1 = 10;
            to.p2 = "ab";

            Assert.AreEqual(to.p1.ToString(),
                            PropertyExtractor.Extract("p1", to));
            Assert.AreEqual(to.p2.ToString(),
                            PropertyExtractor.Extract("p2", to));
        }
        public void FillNestedProps()
        {
            TestObject to = new TestObject();

            to.nested    = new TestObject.NestedObject();
            to.nested.p3 = 20;
            to.nested.p4 = "cd";

            Assert.AreEqual(to.nested.p3.ToString(),
                            PropertyExtractor.Extract("nested.p3", to));
            Assert.AreEqual(to.nested.p4.ToString(),
                            PropertyExtractor.Extract("nested.p4", to));
        }
Ejemplo n.º 5
0
        public void For_Extract_When_ExpressionIsPropertyInfo_Then_ItIsReturned()
        {
            // Arrange:
            var testPerson = new TestPerson();
            Expression <Func <TestPerson, string> > expression = person => person.AnyProperty;

            // Act:
            var extractor = new PropertyExtractor <TestPerson>();
            var result    = extractor.Extract(expression);

            // Assert:
            result.MemberType.Should().Be(MemberTypes.Property);
        }
Ejemplo n.º 6
0
        public void For_Extract_When_ExpressionIsNotMemberExpression_Then_ExceptionIsThrown()
        {
            // Arrange:
            var testPerson = new TestPerson
            {
                AnyProperty = "PersonName"
            };
            Expression <Func <TestPerson, int> > expression = person => person.AnyMethod();

            // Act:
            var extractor = new PropertyExtractor <TestPerson>();
            var exception = Assert.Throws <ArgumentException>(() => extractor.Extract(expression));

            // Assert:
            exception.Message.Should().Contain("must be member expression");
        }
        public AsyncPropertyValidator <TProp> SetupAsync <TProp>(Expression <Func <TObject, TProp> > expression)
        {
            var memberInfo = PropertyExtractor.Extract(expression);

            if (PropertyValidators.TryGetValue(memberInfo.Name, out var propertyValidator))
            {
                if (propertyValidator is AsyncPropertyValidator <TProp> asyncPropertyValidator)
                {
                    return(asyncPropertyValidator);
                }

                throw new InvalidOperationException("Member already has assigned synchronous validator");
            }

            var newPropertyValidator = new AsyncPropertyValidator <TProp>(memberInfo);

            PropertyValidators.Add(memberInfo.Name, newPropertyValidator);

            return(newPropertyValidator);
        }
Ejemplo n.º 8
0
        internal List <TResult> LoadTo <TResult>(Expression predicate, int skip, int?limit, List <SortOrder> sortOrders, List <QueryHint> hints, Expression selector)
        {
            Func <Dictionary <PropertyInfo, object>, TResult> generator;
            var propertyExtractor = new PropertyExtractor();
            var properties        = propertyExtractor.Extract <TResult>(selector, out generator);

            var mapper       = this.m_mapper;
            var predicateDoc = mapper.GetPredicate(predicate);
            var fieldsDoc    = this.m_mapper.GetFields(properties);
            var sortDoc      = mapper.GetSortOrders(sortOrders);

            var collection = mapper.GetCollection(this.Database);

            var mongoCursor = collection.Find(predicateDoc).SetFields(fieldsDoc).SetSortOrder(sortDoc).SetSkip(skip);

            if (limit.HasValue)
            {
                mongoCursor = mongoCursor.SetLimit(limit.Value);
            }

            var hintsDoc = (hints != null && hints.Count > 0) ? mapper.GetHints(hints) : null;

            if (hintsDoc != null)
            {
                mongoCursor.SetHint(hintsDoc);
            }

            this.Log.WriteQuery(collection, predicateDoc, fieldsDoc, sortDoc, hintsDoc, skip, limit);

            var docList = mongoCursor.ToList();

            var result = new List <TResult>(docList.Count);

            foreach (var doc in docList)
            {
                var values = mapper.GetValues(properties, doc);
                result.Add(generator(values));
            }

            return(result);
        }
Ejemplo n.º 9
0
        internal void DefaultEventRecordHandler(IEventRecord record)
        {
            var obj = _propertyExtractor.Extract(record);

            _callback.Invoke(obj.ToPSObject());
        }