public static IncPaginatedResult <TEntity> Paginated <TEntity>(this IQueryable <TEntity> source, OrderSpecification <TEntity> orderSpecification, Specification <TEntity> whereSpecification, FetchSpecification <TEntity> fetchSpecification, PaginatedSpecification paginatedSpecification) where TEntity : class, IEntity
        {
            int totalCount     = source.Query(null, whereSpecification, null, null).Count();
            var paginatedItems = source.Query(orderSpecification, whereSpecification, fetchSpecification, paginatedSpecification).ToList();

            return(new IncPaginatedResult <TEntity>(paginatedItems, totalCount));
        }
        public static IQueryable <TEntity> Query <TEntity>(this IQueryable <TEntity> source, OrderSpecification <TEntity> orderSpecification, Specification <TEntity> whereSpecification, FetchSpecification <TEntity> fetchSpecification, PaginatedSpecification paginatedSpecification) where TEntity : class, IEntity
        {
            if (whereSpecification.With(r => r.IsSatisfiedBy()) != null)
            {
                source = source.Where(whereSpecification.IsSatisfiedBy());
            }

            if (orderSpecification != null)
            {
                var order = new AdHocOrderSpecification <TEntity>();
                orderSpecification.SortedBy()(order);
                source = order.applies.Aggregate(source, (current, apply) => apply(current));
            }

            if (paginatedSpecification != null)
            {
                source = source.Page(paginatedSpecification.CurrentPage, paginatedSpecification.PageSize);
            }

            if (fetchSpecification != null)
            {
                AdHocFetchSpecificationBase <TEntity> fetch = null;
                //string fullName = source.Provider.GetType().FullName;
                //if (fullName.EqualsWithInvariant("NHibernate.Linq.DefaultQueryProvider"))
                //    fetch = new AdHocFetchNhibernateSpecification<TEntity>();
                //else
                //if (fullName.EqualsWithInvariant("System.Data.Entity.Internal.Linq.DbQueryProvider"))
                fetch = new AdHocFetchRavenDbSpecification <TEntity>();
                //else if (fullName.Contains("Raven.Client.Linq.RavenQueryProvider"))
                //    fetch = new AdHocFetchRavenDbSpecification<TEntity>();

                //if (fetch != null)
                //{
                fetchSpecification.FetchedBy()(fetch);
                source = fetch.applies.Aggregate(source, (current, apply) => apply(current));
                //}
            }

            return(source);
        }
 public static void StubPaginated <TEntity>(this Mock <IRepository> repository, PaginatedSpecification paginatedSpecification, OrderSpecification <TEntity> orderSpecification = null, Specification <TEntity> whereSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, IncPaginatedResult <TEntity> result = null)
     where TEntity : class, IEntity, new()
 {
     repository.Setup(r => r.Paginated(Pleasure.MockIt.IsStrong(paginatedSpecification), orderSpecification, Pleasure.MockIt.IsStrong(whereSpecification, dsl => dsl.IncludeAllFields()), fetchSpecification))
     .Returns(result);
 }
 public static void StubQuery <TEntity>(this Mock <IRepository> repository, OrderSpecification <TEntity> orderSpecification = null, Specification <TEntity> whereSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, PaginatedSpecification paginatedSpecification = null, params TEntity[] entities) where TEntity : class, IEntity, new()
 {
     repository
     .Setup(r => r.Query(orderSpecification, Pleasure.MockIt.IsStrong(whereSpecification, dsl => dsl.IncludeAllFields()), fetchSpecification, Pleasure.MockIt.IsStrong(paginatedSpecification, dsl => dsl.IncludeAllFields())))
     .Returns(Pleasure.ToQueryable(entities));
 }
Beispiel #5
0
 public MockMessage <TMessage, TResult> StubPaginated <TEntity>(PaginatedSpecification paginatedSpecification, OrderSpecification <TEntity> orderSpecification = null, Specification <TEntity> whereSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, IncPaginatedResult <TEntity> result = null) where TEntity : class, IEntity, new()
 {
     return(Stub(message => message.repository.StubPaginated(paginatedSpecification, orderSpecification, whereSpecification, fetchSpecification, result)));
 }
 public IncPaginatedResult <TEntity> Paginated <TEntity>(PaginatedSpecification paginatedSpecification, Specification <TEntity> whereSpecification = null, OrderSpecification <TEntity> orderSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, bool skipInterceptions = false) where TEntity : class, IEntity, new()
 {
     Specification <TEntity> where = whereSpecification;
     if (!skipInterceptions)
     {
         foreach (var interception in interceptions)
         {
             where = interception().WhereSpec(where);
         }
     }
     return(session.Set <TEntity>().AsQueryable().Paginated(orderSpecification, where, fetchSpecification, paginatedSpecification));
 }
Beispiel #7
0
 public MockMessage <TMessage, TResult> StubEmptyQuery <TEntity>(OrderSpecification <TEntity> orderSpecification = null, Specification <TEntity> whereSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, PaginatedSpecification paginatedSpecification = null) where TEntity : class, IEntity, new()
 {
     return(Stub(message => message.repository.StubQuery(orderSpecification, whereSpecification, fetchSpecification, paginatedSpecification, Pleasure.ToArray <TEntity>())));
 }
Beispiel #8
0
 public MockMessage <TMessage, TResult> StubQuery <TEntity>(OrderSpecification <TEntity> orderSpecification = null, Specification <TEntity> whereSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, PaginatedSpecification paginatedSpecification = null, params TEntity[] entities) where TEntity : class, IEntity, new()
 {
     return(Stub(message => message.repository.StubQuery(orderSpecification, whereSpecification, fetchSpecification, paginatedSpecification, entities)));
 }
 public IQueryable <TEntity> Query <TEntity>(Specification <TEntity> whereSpecification = null, OrderSpecification <TEntity> orderSpecification = null, FetchSpecification <TEntity> fetchSpecification = null, PaginatedSpecification paginatedSpecification = null, bool skipInterceptions = false) where TEntity : class, IEntity, new()
 {
     Specification <TEntity> where = whereSpecification;
     if (!skipInterceptions)
     {
         foreach (var interception in interceptions)
         {
             where = interception().WhereSpec(where);
         }
     }
     return(session.Query <TEntity>().Query(orderSpecification, where, fetchSpecification, paginatedSpecification));
 }
 private static ISpecification <Student> Specification(string propName, string orderDirection = null)
 => OrderSpecification <Student> .FromPropertyName(propName, orderDirection);
Beispiel #11
0
        public async Task <ActionResult <OrderRepresentation> > CreateOrder([FromRoute] string customerId, [FromBody] OrderSpecification spec)
        {
            var customer = await this._customers.GetByIdAsync(customerId);

            var order = await this._orders.AddAsync(customer, spec.Description, spec.Date);

            foreach (OrderLineSpecification line in spec.Lines)
            {
                Product product = await this._products.GetByIdAsync(line.ProductId);

                this._orders.AddLine(order, product, line.Amount);
            }
            return(this.Ok(OrderRepresentation.FromEntity(order)));
        }