public void FilterThrowingExceptionIsTrigged()
        {
            var action     = new ThrowsExceptionFilterDecoratedAction();
            var controller = new DynamicActionExecutorTestCase.DummyController();


            var controllerContext = services.ControllerContextFactory.Create("area", "controller", "action", services.ControllerDescriptorProvider.BuildDescriptor(controller));
            var thrownexception   = new Exception(string.Format("thrown at {0}", DateTime.Now));

            controllerContext.DynamicActions["action"] = action;
            var filterMock = new ThrowsExceptionFilter(() => thrownexception);            //mockRepository.DynamicMock<IFilter>();

            using (mockRepository.Record()) {
                Expect.Call(filterFactoryMock.Create(typeof(ThrowsExceptionFilter))).Return(filterMock);


                filterFactoryMock.Release(filterMock);
                LastCall.Repeat.Once();
            }

            using (mockRepository.Playback())
            {
                Assert.Throws(
                    thrownexception.GetType()
                    , () => controller.Process(engineContext, controllerContext)
                    , thrownexception.Message
                    );

                controller.Dispose();
                Console.WriteLine(engStubViewEngineManager.TemplateRendered);
                Assert.IsTrue(action.executed);
                Assert.IsTrue(filterMock.executed);
            }
        }
        public async Task <ISearchResponse <T> > Search <T, TRequest>(TRequest request) where T : class where TRequest : class
        {
            try
            {
                var esNodes = string.Join(';', _esClient.ConnectionSettings.ConnectionPool.Nodes.Select(x => x.Uri));
                _logger.LogDebug($"ElasticSearch Search begins {esNodes}");

                if (request == null)
                {
                    return(new SearchResponse <T>());
                }

                HousingSearchRequest searchRequest = (HousingSearchRequest)(object)request;

                var pageOffset = _pagingHelper.GetPageOffset(searchRequest.PageSize, searchRequest.Page);

                var result = await _esClient.SearchAsync <T>(x => x.Index(_indexSelector.Create <T>())
                                                             .Query(q => BaseQuery <T>().Create(request, q))
                                                             .PostFilter(q => _filterFactory.Create <T, TRequest>(request).GetDescriptor(q, request))
                                                             .Sort(_sortFactory.Create <T, TRequest>(request).GetSortDescriptor)
                                                             .Size(searchRequest.PageSize)
                                                             .Skip(pageOffset)
                                                             .TrackTotalHits()).ConfigureAwait(false);

                _logger.LogDebug("ElasticSearch Search ended");

                return(result);
            }
            catch (ElasticsearchClientException e)
            {
                _logger.LogError(e, "ElasticSearch Search threw an ElasticSearchClientException. DebugInfo: " + e.DebugInformation);
                throw;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "ElasticSearch Search threw an exception");
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method obtains filtered or all scores.
        /// </summary>
        /// <param name="scoreFilters">Score filters</param>
        /// <returns>Multiple filtered game scores</returns>
        public GameScore[] GetScores(Filter[] scoreFilters = null)
        {
            var games = dbUnit.Games.Get();

            if (scoreFilters == null || !scoreFilters.Any())
            {
                return(CreateGameScores(games));
            }

            var filteredGames = new List <Game>();
            var firstFilter   = true;

            foreach (var filter in scoreFilters)
            {
                var testFilter = filters.Create(filter);
                var tempGames  = games.Where(g => testFilter.Check(g));

                if (firstFilter)
                {
                    filteredGames = tempGames.ToList();
                    firstFilter   = false;
                    continue;
                }

                if (filter.Relation == FilterRelation.AND)
                {
                    filteredGames = filteredGames.Intersect(tempGames).ToList();
                }
                else
                {
                    filteredGames = filteredGames.Union(tempGames).ToList();
                }
            }

            return(CreateGameScores(filteredGames));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a feature.
 /// </summary>
 /// <returns>A filter bank feature</returns>
 public IFeature <ImageDataPoint <float>, float[]> Create()
 {
     return(new FilterFeature(_factory.Create()));
 }