Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RepoProvider{T}"/> class.
        /// </summary>
        /// <param name="includes"></param>
        /// <param name="filter"></param>
        /// <param name="orderByObservable"></param>
        /// <param name="fetchDelay">The fetch delay.</param>
        public RepoProvider(Expression <Func <T, object> >[] includes,
                            ProviderFilter <T> filter,
                            IObservable <IOrderByExpression <T>[]> orderByObservable,
                            int fetchDelay = 0)
        {
            this.fetchDelay = fetchDelay;
            entityType      = PodboyRepository.GetEntityType <T>();

            Includes = includes;

            Filter = filter?.FilterExpression ?? (_ => true);

            if (orderByObservable == null)
            {
                orderByObservable = Observable.Return(new IOrderByExpression <T>[]
                {
                    new OrderByExpression <T, int>(_ => _.Id, true)
                });
            }
            orderByObservable.Subscribe(_ => OrderBy = _);

            var typePredicate = entityType == EntityType.None
                ? new Func <EntityType, bool>(_ => false)
                : (_ => _.HasFlag(entityType));

            var resetObservable =
                PodboyRepository.SignalReset.Where(typePredicate)
                .Select(_ => Unit.Default)
                .Merge(orderByObservable.Select(_ => Unit.Default));

            if (filter?.SignalReset != null)
            {
                resetObservable = resetObservable.Merge(filter.SignalReset);
            }

            resetObservable.Subscribe(_ => OnReset());
        }
Ejemplo n.º 2
0
        public void GetEntityTypeTest(Type entityType, EntityType expected)
        {
            entityType.Should().Implement(typeof(IEntity));

            PodboyRepository.GetEntityType(entityType.InArray()).Should().Be(expected);
        }