Beispiel #1
0
        public void DynamicListConstructorShouldSetCorrectly()
        {
            var head = stringList.GetType().GetField("head", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(stringList);
            var tail = stringList.GetType().GetField("tail", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(stringList);

            Assert.AreEqual(0, this.stringList.Count);
            Assert.IsNull(head);
            Assert.IsNull(tail);
        }
Beispiel #2
0
        public void AddMethodShouldAddCorrectly()
        {
            var head = intList.GetType().GetField("head", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(intList);
            var tail = intList.GetType().GetField("tail", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(intList);

            Assert.AreEqual(5, head.GetType().GetProperty("Element").GetValue(head));
            Assert.AreEqual(9, tail.GetType().GetProperty("Element").GetValue(tail));
            Assert.AreEqual(5, this.intList.Count);
        }
        /// <summary>
        /// Populates a Dynamic List by executing the query it specifies.
        /// </summary>
        /// <param name="dynamicList">The Dynamic List which specifies the query and is to be populated.</param>
        /// <param name="localization">The context Localization.</param>
        public void PopulateDynamicList(DynamicList dynamicList, Localization localization)
        {
            using (new Tracer(dynamicList, localization))
            {
                SimpleBrokerQuery simpleBrokerQuery = dynamicList.GetQuery(localization) as SimpleBrokerQuery;
                if (simpleBrokerQuery == null)
                {
                    throw new DxaException($"Unexpected result from {dynamicList.GetType().Name}.GetQuery: {dynamicList.GetQuery(localization)}");
                }

                BrokerQuery brokerQuery   = new BrokerQuery(simpleBrokerQuery);
                string[]    componentUris = brokerQuery.ExecuteQuery().ToArray();
                Log.Debug($"Broker Query returned {componentUris.Length} results. HasMore={brokerQuery.HasMore}");

                if (componentUris.Length > 0)
                {
                    Type resultType = dynamicList.ResultType;
                    ComponentMetaFactory componentMetaFactory = new ComponentMetaFactory(localization.GetCmUri());
                    dynamicList.QueryResults = componentUris
                                               .Select(c => ModelBuilderPipeline.CreateEntityModel(CreateEntityModelData(componentMetaFactory.GetMeta(c)), resultType, localization))
                                               .ToList();
                }

                dynamicList.HasMore = brokerQuery.HasMore;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Populates a Dynamic List by executing the query it specifies.
        /// </summary>
        /// <param name="dynamicList">The Dynamic List which specifies the query and is to be populated.</param>
        /// <param name="localization">The context Localization.</param>
        public override void PopulateDynamicList(DynamicList dynamicList, Localization localization)
        {
            using (new Tracer(dynamicList, localization))
            {
                SimpleBrokerQuery simpleBrokerQuery = dynamicList.GetQuery(localization) as SimpleBrokerQuery;
                if (simpleBrokerQuery == null)
                {
                    throw new DxaException($"Unexpected result from {dynamicList.GetType().Name}.GetQuery: {dynamicList.GetQuery(localization)}");
                }

                // get our cursor indexer for this list
                var cursors = CursorIndexer.GetCursorIndexer(dynamicList.Id);

                // given our start index into the paged list we need to translate that to a cursor
                int start = simpleBrokerQuery.Start;
                simpleBrokerQuery.Cursor = cursors[start];

                // the cursor retrieved may of came from a different start index so we update start
                int startIndex = cursors.StartIndex;
                simpleBrokerQuery.Start = startIndex;
                dynamicList.Start       = startIndex;

                var cachedDynamicList = SiteConfiguration.CacheProvider.GetOrAdd(
                    $"PopulateDynamicList-{dynamicList.Id}-{simpleBrokerQuery.GetHashCode()}", // key
                    CacheRegions.BrokerQuery,
                    () =>
                {
                    var brokerQuery = new GraphQLQueryProvider();

                    var components = brokerQuery.ExecuteQueryItems(simpleBrokerQuery).ToList();
                    Log.Debug($"Broker Query returned {components.Count} results. HasMore={brokerQuery.HasMore}");

                    if (components.Count > 0)
                    {
                        Type resultType          = dynamicList.ResultType;
                        dynamicList.QueryResults = components
                                                   .Select(
                            c =>
                            ModelBuilderPipeline.CreateEntityModel(
                                CreateEntityModelData((Component)c), resultType,
                                localization))
                                                   .ToList();
                    }

                    dynamicList.HasMore = brokerQuery.HasMore;

                    if (brokerQuery.HasMore)
                    {
                        // update cursor
                        cursors[simpleBrokerQuery.Start + simpleBrokerQuery.PageSize] = brokerQuery.Cursor;
                    }

                    return(dynamicList);
                });

                dynamicList.QueryResults = cachedDynamicList.QueryResults;
                dynamicList.HasMore      = cachedDynamicList.HasMore;
            }
        }
Beispiel #5
0
        public void ConstructingNewEmptyDynamicListWithNoParametersMustConstructCorrectObject()
        {
            var list = new DynamicList<int>();

            Assert.AreEqual(new DynamicList<int>().GetType(),
                list.GetType(),
                String.Format("Constructing new empty DynamicList consist of Integer values"));
        }