public void TestParseFilters_MultipleFilters() { var expressionFilter1 = new ExpressionFilter <PagingQueryBindingModelTestClass>(x => x.A, ComparisonType.Equal, "S"); var longValue = 1L; var expressionFilter2 = new ExpressionFilter <PagingQueryBindingModelTestClass>(x => x.Id, ComparisonType.Equal, longValue); var json1 = JsonConvert.SerializeObject(expressionFilter1); var json2 = JsonConvert.SerializeObject(expressionFilter2); var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Filter = new List <string> { json1, json2 }; var parsedFilters = model.ParseFilters(model.Filter); Assert.AreEqual(2, parsedFilters.Count); var firstParsedFilter = parsedFilters.First(); Assert.AreEqual(expressionFilter1.Comparison, firstParsedFilter.Comparison); Assert.AreEqual(expressionFilter1.Value, firstParsedFilter.Value); Assert.AreEqual(expressionFilter1.Property, firstParsedFilter.Property); var lastParsedFilter = parsedFilters.Last(); Assert.AreEqual(expressionFilter2.Comparison, lastParsedFilter.Comparison); Assert.AreEqual(expressionFilter2.Value, lastParsedFilter.Value); Assert.AreEqual(expressionFilter2.Property, lastParsedFilter.Property); }
public void TestConstructor() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); Assert.IsNotNull(model.Filter); Assert.IsNotNull(model.Keyword); }
public void TestToQueryableOperator_ToManyProperties() { var start = 0; var limit = 10; var defaultSorter = new ExpressionSorter <PagingQueryBindingModelTestClass>(x => x.A, SortDirection.Ascending); var sorter = new ExpressionSorter <PagingQueryBindingModelTestClass>(x => x.A, SortDirection.Ascending); var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass> { Start = start, Limit = limit }; var keyword = "hello"; model.Keyword.Add(keyword); var queryOperator = model.ToQueryableOperator(defaultSorter, x => x.A, x => x.B, x => x.C, x => x.D, x => x.E, x => x.F, x => x.G, x => x.H, x => x.I, x => x.J, x => x.K); }
public async Task TestGetCollaboratorsAsync() { var projectId = 10; var queryModel = new PagingQueryBindingModel <ResourceAuthorization>(); queryModel.Start = 0; queryModel.Limit = 10; Action <QueryableOperator <ResourceAuthorization> > callbackTester = (op) => { Assert.AreEqual(2, op.Filters.Count); var filters = op.Filters.ToList().Select(x => (ExpressionFilter <ResourceAuthorization>)x).ToList(); var foreignResourceIdFilter = filters.Where(x => x.Property == "ForeignResourceId").FirstOrDefault(); Assert.IsNotNull(foreignResourceIdFilter, "The foreign resource filter must exist."); Assert.AreEqual(ComparisonType.Equal.Value, foreignResourceIdFilter.Comparison); Assert.AreEqual(projectId, foreignResourceIdFilter.Value); var resourceTypeFilter = filters.Where(x => x.Property == "ResourceTypeId").FirstOrDefault(); Assert.IsNotNull(resourceTypeFilter, "The resource type filter must exist."); Assert.AreEqual(ComparisonType.Equal.Value, resourceTypeFilter.Comparison); Assert.AreEqual(ResourceType.Project.Id, resourceTypeFilter.Value); }; resourceService.Setup(x => x.GetResourceAuthorizationsAsync(It.IsAny <QueryableOperator <ResourceAuthorization> >())) .ReturnsAsync(new PagedQueryResults <ResourceAuthorization>(0, new List <ResourceAuthorization>())) .Callback(callbackTester); var response = await controller.GetCollaboratorsAsync(projectId, queryModel); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <PagedQueryResults <ResourceAuthorization> >)); }
public async Task TestGetLocationTypesAsync() { var model = new PagingQueryBindingModel <SimpleLookupDTO>(); var response = await controller.GetLocationTypesAsync(model); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <PagedQueryResults <SimpleLookupDTO> >)); locationTypeService.Verify(x => x.GetAsync(It.IsAny <QueryableOperator <SimpleLookupDTO> >()), Times.Once()); }
public async Task TestGetLocationTypesAsync_InvalidModel() { controller.ModelState.AddModelError("key", "error"); var model = new PagingQueryBindingModel <SimpleLookupDTO>(); var response = await controller.GetLocationTypesAsync(model); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public void TestToString_OnlyStartAndLimitInitialized() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Start = 0; model.Limit = 10; Assert.IsNotNull(model.ToString()); }
public void TestGetFilters_KeywordAndFilterNull() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Filter = null; model.Keyword = null; Assert.IsNotNull(model.GetFilters()); }
public void TestToString_HasKeywords() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Start = 0; model.Limit = 10; model.Keyword.Add("hello"); Assert.IsNotNull(model.ToString()); }
public void TestGetFilters_NoKeywordAndNoFilter() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Filter = new List <string>(); model.Keyword = new List <string>(); Assert.IsNotNull(model.GetFilters()); Assert.AreEqual(0, model.GetFilters().Count); }
public async Task <IHttpActionResult> GetEmploymentsAsync(int personId, [FromUri] PagingQueryBindingModel <EducationEmploymentDTO> queryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var employments = await service.GetEmploymentsAsync(personId, queryModel.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(employments)); }
public async Task TestGetParticipantPersonsSevisCommStatusesByIdAsync() { var projectId = 1; var participantId = 2; var model = new PagingQueryBindingModel <ParticipantPersonSevisCommStatusDTO>(); var response = await controller.GetParticipantPersonsSevisCommStatusesByIdAsync(projectId, participantId, model); participantPersonSevisService.Verify(x => x.GetSevisCommStatusesByParticipantIdAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <QueryableOperator <ParticipantPersonSevisCommStatusDTO> >()), Times.Once()); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <PagedQueryResults <ParticipantPersonSevisCommStatusDTO> >)); }
public async Task <IHttpActionResult> GetAsync([FromUri] PagingQueryBindingModel <EvaluationNoteDTO> queryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dtos = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(dtos)); }
public void TestToString_SorterStrings() { var model = new PagingQueryBindingModel <PagingQueryBindingModelTestClass>(); model.Start = 0; model.Limit = 10; model.Sort = new List <string> { "sort1" }; Assert.IsNotNull(model.ToString()); }
public async Task <IHttpActionResult> GetOrganizationTypesAsync([FromUri] PagingQueryBindingModel <OrganizationTypeDTO> queryModel) { if (ModelState.IsValid) { return(Ok(await organizationTypeService.GetAsync(queryModel.ToQueryableOperator(DEFAULT_ORGANIZATION_TYPE_SORTER)))); } else { return(BadRequest(ModelState)); } }
public async Task TestGetParticipantPersonsSevisCommStatusesByIdAsync_InvalidModel() { var projectId = 1; var participantId = 2; var model = new PagingQueryBindingModel <ParticipantPersonSevisCommStatusDTO>(); controller.ModelState.AddModelError("key", "error"); var response = await controller.GetParticipantPersonsSevisCommStatusesByIdAsync(projectId, participantId, model); participantPersonSevisService.Verify(x => x.GetSevisCommStatusesByParticipantIdAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <QueryableOperator <ParticipantPersonSevisCommStatusDTO> >()), Times.Never()); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public async Task <IHttpActionResult> GetContactsAsync([FromUri] PagingQueryBindingModel <ContactDTO> queryModel) { if (ModelState.IsValid) { var results = await this.service.GetContactsAsync(queryModel.ToQueryableOperator(DEFAULT_SORTER, x => x.FullName, x => x.Position)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }
/// <summary> /// Gets list of genders /// </summary> /// <param name="queryModel">The queryModel to use</param> /// <returns>A list of genders</returns> public async Task <IHttpActionResult> GetGenders([FromUri] PagingQueryBindingModel <SimpleLookupDTO> queryModel) { if (ModelState.IsValid) { var genders = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_GENDER_DTO_SORTER)); return(Ok(genders)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetBirthCountryReasonsAsync([FromUri] PagingQueryBindingModel <BirthCountryReasonDTO> model) { if (ModelState.IsValid) { var results = await this.birthCountryReasonService.GetAsync(model.ToQueryableOperator(DEFAULT_BIRTH_COUNTRY_REASON_SORTER)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetResourceAuthorizationsAsync(int id, [FromUri] PagingQueryBindingModel <ResourceAuthorization> queryOperator) { if (ModelState.IsValid) { var authorizations = await resourceService.GetResourceAuthorizationsAsync(queryOperator.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(authorizations)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetOrganizationRolesAsync([FromUri] PagingQueryBindingModel <SimpleLookupDTO> queryModel) { if (ModelState.IsValid) { var organizationRoles = await organizationService.GetOrganizationRolesAsync(queryModel.ToQueryableOperator(DEFAULT_ORGANIZATION_ROLE_SORTER)); return(Ok(organizationRoles)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetAsync([FromUri] PagingQueryBindingModel <ParticipantStatusDTO> queryModel) { if (ModelState.IsValid) { var dtos = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(dtos)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetUsersAsync([FromUri] PagingQueryBindingModel <UserDTO> model) { if (ModelState.IsValid) { var users = await userService.GetUsersAsync(model.ToQueryableOperator(DEFAULT_USER_SORTER)); return(Ok(users)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetLocationTypesAsync([FromUri] PagingQueryBindingModel <SimpleLookupDTO> queryModel) { if (ModelState.IsValid) { var types = await this.locationTypeService.GetAsync(queryModel.ToQueryableOperator(DEFAULT_LOCATION_TYPE_SORTER)); return(Ok(types)); } else { return(BadRequest(ModelState)); } }
/// <summary> /// Gets list of marital statuses /// </summary> /// <param name="queryModel">The queryModel to use</param> /// <returns>A list of marital statuses</returns> public async Task <IHttpActionResult> GetMaritalStatuses([FromUri] PagingQueryBindingModel <SimpleLookupDTO> queryModel) { if (ModelState.IsValid) { var maritalStatuses = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_MARITAL_STATUS_DTO_SORTER)); return(Ok(maritalStatuses)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetStudentCreationsAsync([FromUri] PagingQueryBindingModel <SimpleSevisLookupDTO> queryModel) { if (ModelState.IsValid) { var results = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_SEVIS_COMM_STATUS_DTO_SORTER)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetThemesAsync([FromUri] PagingQueryBindingModel <ThemeDTO> queryModel) { if (ModelState.IsValid) { var results = await this.service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetEmailAddressTypesAsync([FromUri] PagingQueryBindingModel <EmailAddressTypeDTO> model) { if (ModelState.IsValid) { var dtos = await emailAddressTypeService.GetAsync(model.ToQueryableOperator(DEFAULT_SORTER)); return(Ok(dtos)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetFieldOfStudiesAsync([FromUri] PagingQueryBindingModel <SimpleSevisLookupDTO> queryModel) { if (ModelState.IsValid) { var results = await service.GetAsync(queryModel.ToQueryableOperator(DEFAULT_FIELD_OF_STUDIES_DTO_SORTER, x => x.Description, x => x.Code)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetDependentTypesAsync([FromUri] PagingQueryBindingModel <DependentTypeDTO> model) { if (ModelState.IsValid) { var results = await this.dependentTypeService.GetAsync(model.ToQueryableOperator(DEFAULT_PERSON_TYPE_SORTER)); return(Ok(results)); } else { return(BadRequest(ModelState)); } }