public IHttpActionResult Get([FromUri] RolePersonSearchCriteria searchCriteria) { var lookupValues = searchCriteria?.Roles == null?_rolePersonsManager.GetAll() : _rolePersonsManager.GetByGroupName(searchCriteria.Roles); var lookupValueslist = lookupValues.Select(l => new GroupNameValuePair(l)).ToList(); if (lookupValueslist.Count() == 0) { return(StatusCode(HttpStatusCode.NotFound)); } else { return(LookupResponse(lookupValueslist)); } }
public void RolePersonsLookupController_Get_Returns_OkResponse(RolePersonSearchCriteria rolePersonSearchCriteria) { var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), $"{AppSettings.BASEURL}{RouteHelper.LookupsRolePersonsRoutePrefix}/{rolePersonSearchCriteria}"); Mock <IRolePersonsManager> rolePersonsManager = new Mock <IRolePersonsManager>(); IList <LookupEntity> sampledata = new List <LookupEntity> { new LookupEntity(id: 52517, code: "Alan Dowling", description: "GlobalRe.Underwriter", isActive: true), }; if (rolePersonSearchCriteria?.Roles == null) { rolePersonsManager.Setup(p => p.GetAll()).Returns(sampledata); } else { rolePersonsManager.Setup(p => p.GetByGroupName(rolePersonSearchCriteria.Roles)).Returns(sampledata); } #region Repository Mocking (Need to fix) //SetupUserIdentity(); //Mock<IRolePersonsLookupRepository> rolePersonsLookupRepository = new Mock<IRolePersonsLookupRepository>(); //rolePersonsLookupRepository.Setup(p => p.GetLookupData()).Returns(sampledata); //cacheStoreManager.Setup(p => p.BuildKey("Lookup", "RolePersons")).Returns("LookupRolePersons"); //RolePersonsManager rPersonsManager = new RolePersonsManager(userManager.Object, cacheStoreManager.Object, rolePersonsLookupRepository.Object); #endregion RolePersonsLookupController rolePersonsLookupController = new RolePersonsLookupController(userManager.Object, rolePersonsManager.Object) { Request = httpRequest, Configuration = new HttpConfiguration() }; var response = rolePersonsLookupController.Get(rolePersonSearchCriteria); var contentResult = response as NegotiatedContentResult <ResponseLookup <GroupNameValuePair> >; Assertions.AssertOkResponse(contentResult); }