public IQueryConstraints GetQueryConstraints() { var constraints = new QueryConstraints(); if (GlasswareId.HasValue) { constraints.AddFilter("glasswareId", GlasswareId.Value); } if (StyleId.HasValue) { constraints.AddFilter("styleId", StyleId.Value); } if (AvailabilityId.HasValue) { constraints.AddFilter("availableId", AvailabilityId.Value); } if (!String.IsNullOrEmpty(Sort)) { constraints.SortBy(Sort); } if (!String.IsNullOrEmpty(Order)) { if (Order.ToLower().Equals("desc")) { constraints.Descending(); } } if (Page.HasValue) { constraints.Page(Page.Value); } return(constraints); }
public void GivenRestRequestExtensions_When_ConstraintsAppliedToRestRequest_ParameterListShouldBeCunstractedAsExpected() { var request = new RestRequest(); var constraints = new QueryConstraints(); constraints.Page(2).SortBy("name").Descending(); constraints.AddFilter("glasswareId", 1); request.ApplyConstraints(constraints); Assert.AreEqual(2, (int)request.Parameters.Single(p => p.Name == "p").Value); Assert.AreEqual(constraints.GetSortParameterString(), request.Parameters.Single(p => p.Name == "sort").Value); Assert.AreEqual(constraints.SortPropertyName, request.Parameters.Single(p => p.Name == "order").Value); Assert.AreEqual(1, (int)request.Parameters.Single(p => p.Name == "glasswareId").Value); }