public void GetObjects_ReturnsCorrectResult(object searchParams, string[] expectedNames, bool expectedNextPageAvailable)
            {
                // Arrange
                var parameters = searchParams as ObjectsRetrieverSearchParams;

                userClassStructureInfo.RegisterColumn(String.Format(ObjectsRetriever.ORDERING_COLUMN_VALUE_TEMPLATE, UserInfo.TYPEINFO.DisplayNameColumn, parameters.SearchTerm), typeof(string));
                contactClassStructureInfo.RegisterColumn(String.Format(ObjectsRetriever.ORDERING_COLUMN_VALUE_TEMPLATE, ContactInfo.TYPEINFO.DisplayNameColumn, parameters.SearchTerm), typeof(string));

                // Act
                var actualResult = objectsRetriever.GetObjects(parameters, out var actualNextPageAvailable);
                var actualNames  = actualResult.Select(info => info[info.TypeInfo.DisplayNameColumn].ToString());

                // Assert
                Assert.That(actualNames, Is.EquivalentTo(expectedNames));
                Assert.That(actualNextPageAvailable, Is.EqualTo(expectedNextPageAvailable));
            }
Beispiel #2
0
        public GetObjectsActionResult GetObjects(string objectType, int pageIndex, string searchTerm = null, bool identifyByGuid = false)
        {
            if (!VirtualContext.IsPreviewLinkInitialized)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            try
            {
                var infoObjects = objectsRetriever.GetObjects(new ObjectsRetrieverSearchParams
                {
                    ObjectType = objectType,
                    SearchTerm = searchTerm,
                    PageIndex  = pageIndex,
                    PageSize   = PAGE_ITEMS_COUNT,
                }, out var nextPageAvailable);

                var result = new GetObjectsActionResult
                {
                    NextPageAvailable = nextPageAvailable,
                    Items             = infoObjects.Select(info => new ObjectSelectorItemModel
                    {
                        Value = GetItem(info, identifyByGuid),
                        Text  = info[info.TypeInfo.DisplayNameColumn].ToString()
                    })
                };

                return(result);
            }
            catch (InvalidOperationException exception)
            {
                var message = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(exception.Message)
                };

                throw new HttpResponseException(message);
            }
        }