private static IQueryOver<Webpage, Webpage> ApplySort(DocumentMetadata metaData, IQueryOver<Webpage, Webpage> query) { switch (metaData.SortBy) { case SortBy.DisplayOrder: query = query.OrderBy(webpage => webpage.DisplayOrder).Asc; break; case SortBy.DisplayOrderDesc: query = query.OrderBy(webpage => webpage.DisplayOrder).Desc; break; case SortBy.PublishedOn: query = query.OrderBy(Projections.Conditional(Restrictions.IsNull(Projections.Property<Webpage>(x => x.PublishOn)), Projections.Constant(1), Projections.Constant(0))).Desc.ThenBy(webpage => webpage.PublishOn) .Asc; break; case SortBy.PublishedOnDesc: query = query.OrderBy(Projections.Conditional(Restrictions.IsNull(Projections.Property<Webpage>(x => x.PublishOn)), Projections.Constant(1), Projections.Constant(0))).Desc.ThenBy(webpage => webpage.PublishOn) .Desc; break; case SortBy.CreatedOn: query = query.OrderBy(webpage => webpage.CreatedOn).Asc; break; case SortBy.CreatedOnDesc: query = query.OrderBy(webpage => webpage.CreatedOn).Desc; break; default: throw new ArgumentOutOfRangeException(); } return query; }
public void ControllerManager_GetControllerName_HttpMethodIsPOSTReturnsWebGetController() { var metadata = new DocumentMetadata { WebPostController = "test-controller" }; var stubAllowedWebpage = new StubAllowedWebpage { Published = true }; _controllerManager.GetMetadata = document => metadata; _controllerManager.GetControllerName(stubAllowedWebpage, "POST").Should().Be("test-controller"); }
public void ControllerManager_GetControllerName_HttpMethodIsAnotherTypeReturnsNull() { var metadata = new DocumentMetadata { WebPostController = "test-controller" }; var stubAllowedWebpage = new StubAllowedWebpage { PublishOn = CurrentRequestData.Now.AddDays(-1) }; _controllerManager.GetMetadata = document => metadata; _controllerManager.GetControllerName(stubAllowedWebpage, "PUT").Should().BeNull(); }
public void ControllerManager_GetActionName_ReturnsNullIfHttpMethodIsSomethingElse() { var metadata = new DocumentMetadata { WebPostAction = "test-post-action" }; var webpage = new StubAllowedWebpage { PublishOn = CurrentRequestData.Now.AddDays(-1) }; _controllerManager.GetMetadata = document => metadata; _controllerManager.GetActionName(webpage, "PUT").Should().BeNull(); }
public void ControllerManager_GetActionName_ReturnsDefinitionWebGetActionIfHttpMethodIsPOST() { var metadata = new DocumentMetadata { WebPostAction = "test-post-action" }; var webpage = new StubAllowedWebpage { Published = true }; _controllerManager.GetMetadata = document => metadata; _controllerManager.GetActionName(webpage, "POST").Should().Be("test-post-action"); }