public void null_value_cannot_be_crawled()
        {
            ObjectCrawler objectCrawler = new ObjectCrawler();

            Action action = () => objectCrawler.Crawl(null);

            action.Should().Throw <ArgumentNullException>();
        }
        public void Crawl()
        {
            DictionaryToken token = new DictionaryToken(_parentToken, _type, _value);

            _objectCrawler.AcceptVisitors(token);
            if (token.IgnoreCrawl)
            {
                return;
            }
            IDictionary dictionary = (IDictionary)_value;

            foreach (object key in dictionary.Keys)
            {
                _objectCrawler.Crawl(key.GetType(), token, key);
                var value = dictionary[key];
                _objectCrawler.Crawl(key.GetType(), token, value);
            }
        }
Example #3
0
        public void Crawl()
        {
            FieldToken token = new FieldToken(_parentToken, _field, () => _field.GetValue(_declaringValue), o => _field.SetValue(_declaringValue, o));

            _objectCrawler.AcceptVisitors(token);
            if (token.IgnoreCrawl)
            {
                return;
            }
            _objectCrawler.Crawl(token.Field.FieldType, token, token.Value);
        }
Example #4
0
        public void Crawl()
        {
            PropertyToken token = new PropertyToken(_parentToken, _property, () => _property.GetValue(_declaringValue), o => _property.SetValue(_declaringValue, o));

            _objectCrawler.AcceptVisitors(token);
            if (token.IgnoreCrawl)
            {
                return;
            }
            _objectCrawler.Crawl(token.Property.PropertyType, token, token.Value);
        }
Example #5
0
        public void dictionary_should_be_detected()
        {
            Dictionary <int, int>         someDictionary = new Dictionary <int, int>();
            ObjectCrawler                 crawler        = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor        = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(someDictionary);

            visitor.Enumerable?.Type.Should().NotBeNull().And.Be <Dictionary <int, int> >();
        }
Example #6
0
        public void enumerable_should_be_detected()
        {
            List <int>    someList = new List <int>();
            ObjectCrawler crawler  = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(someList);

            visitor.Enumerable?.Type.Should().NotBeNull().And.Be <List <int> >();
        }
Example #7
0
        public void string_should_be_detected_as_value()
        {
            string        value   = "some string";
            ObjectCrawler crawler = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(value);

            visitor.Value?.Type.Should().Be <string>();
        }
Example #8
0
        public void structures_should_be_detected_as_value()
        {
            DateTime      dateTime = DateTime.Now;
            ObjectCrawler crawler  = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(dateTime);

            visitor.Value?.Type.Should().Be <DateTime>();
        }
        public void a_simple_object_should_be_detected_as_reference()
        {
            object        o       = new object();
            ObjectCrawler crawler = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(o);

            visitor.Reference?.Type.Should().NotBeNull().And.Be <object>();
        }
        public void field_should_be_detected_on_reference()
        {
            AClassWithSingleField         classWithSingleField = new AClassWithSingleField();
            ObjectCrawler                 crawler = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(classWithSingleField);

            visitor.Reference?.Type.Should().Be <AClassWithSingleField>();
            visitor.Field.Should().NotBeNull();
            visitor.Field.Field.Name.Should().Be("_singleField");
        }
        public void property_should_be_detected_on_reference()
        {
            AClassWithSingleProperty      classWithSingleProperty = new AClassWithSingleProperty();
            ObjectCrawler                 crawler = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(classWithSingleProperty);

            visitor.Reference?.Type.Should().Be <AClassWithSingleProperty>();
            visitor.Property.Should().NotBeNull();
            visitor.Property.Property.Name.Should().Be(nameof(AClassWithSingleProperty.SingleProperty));
        }
        public void self_reference_should_not_cause_stack_overflow()
        {
            AClassWithSelfReference classWithSelfReference = new AClassWithSelfReference();

            classWithSelfReference.Self = classWithSelfReference;
            ObjectCrawler crawler = new ObjectCrawler();
            ObjectGraphVisitorVisitorStub visitor = new ObjectGraphVisitorVisitorStub();

            crawler.AddVisitor(visitor);

            crawler.Crawl(classWithSelfReference);

            visitor.Reference?.Type.Should().Be <AClassWithSelfReference>();
            visitor.Property.Should().NotBeNull();
            visitor.Property.Property.Name.Should().Be(nameof(AClassWithSelfReference.Self));
        }
Example #13
0
        public void Crawl()
        {
            EnumerableToken token = new EnumerableToken(_parentToken, _type, _value);

            _objectCrawler.AcceptVisitors(token);
            if (token.IgnoreCrawl)
            {
                return;
            }
            foreach (var item in (IEnumerable)_value)
            {
                if (item == null)
                {
                    continue;
                }
                _objectCrawler.Crawl(item.GetType(), token, item);
            }
        }