Esempio n. 1
0
        private void SetupProcessorFactoryForResourceDefinition <TModel>(Mock <IGenericServiceFactory> processorFactory,
                                                                         IResourceHookContainer <TModel> modelResource, IHooksDiscovery <TModel> discovery, AppDbContext dbContext = null, IResourceGraph resourceGraph = null)
            where TModel : class, IIdentifiable <int>
        {
            processorFactory.Setup(factory => factory.Get <IResourceHookContainer>(typeof(ResourceHooksDefinition <>), typeof(TModel))).Returns(modelResource);

            processorFactory.Setup(factory => factory.Get <IHooksDiscovery>(typeof(IHooksDiscovery <>), typeof(TModel))).Returns(discovery);

            if (dbContext != null)
            {
                Type idType = ObjectFactory.GetIdType(typeof(TModel));

                if (idType == typeof(int))
                {
                    IResourceReadRepository <TModel, int> repo = CreateTestRepository <TModel>(dbContext, resourceGraph);

                    processorFactory.Setup(factory =>
                                           factory.Get <IResourceReadRepository <TModel, int> >(typeof(IResourceReadRepository <,>), typeof(TModel), typeof(int))).Returns(repo);
                }
                else
                {
                    throw new TypeLoadException("Test not set up properly");
                }
            }
        }
Esempio n. 2
0
        private IEnumerable <TResource> GetWhereWithInclude <TResource, TId>(IReadOnlyCollection <TId> ids, RelationshipAttribute[] relationshipsToNextLayer)
            where TResource : class, IIdentifiable <TId>
        {
            if (!ids.Any())
            {
                return(Array.Empty <TResource>());
            }

            ResourceContext  resourceContext  = _resourceContextProvider.GetResourceContext <TResource>();
            FilterExpression filterExpression = CreateFilterByIds(ids, resourceContext);

            var queryLayer = new QueryLayer(resourceContext)
            {
                Filter = filterExpression
            };

            List <ResourceFieldChainExpression> chains = relationshipsToNextLayer.Select(relationship => new ResourceFieldChainExpression(relationship))
                                                         .ToList();

            if (chains.Any())
            {
                queryLayer.Include = IncludeChainConverter.FromRelationshipChains(chains);
            }

            IResourceReadRepository <TResource, TId> repository = GetRepository <TResource, TId>();

            return(repository.GetAsync(queryLayer, CancellationToken.None).Result);
        }