public IHttpActionResult List() { try { List <string> result = orgUnitService.List(); return(Ok(result)); } catch (Exception ex) { log.Error(messages.GetOuMessage(messages.READ_FAILED), ex); return(InternalServerError()); } }
private static void TestListAndReadOUs() { // small hack to ensure this test passes (the search parameters will find all ous in the organisation, and we need to test that it hits the required amount) OrganisationRegistryProperties properties = OrganisationRegistryProperties.GetInstance(); string oldUuid = properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()]; properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()] = Uuid(); OrgUnitRegistration registration1 = OUReg(); registration1.Name = "magic"; registration1.Email = "*****@*****.**"; registration1.ParentOrgUnitUuid = Uuid(); orgUnitService.Update(registration1); orgUnitService.Read(registration1.Uuid); OrgUnitRegistration registration2 = OUReg(); registration2.Name = "magic"; registration2.Email = "*****@*****.**"; registration2.ParentOrgUnitUuid = Uuid(); orgUnitService.Update(registration2); registration2.Name = "different name"; orgUnitService.Update(registration2); // TODO: a KMD bug prevents this test from working... OrgUnitRegistration registration3 = OUReg(); registration3.Name = "ou3"; registration3.Email = "*****@*****.**"; registration3.ParentOrgUnitUuid = Uuid(); orgUnitService.Update(registration3); orgUnitService.Delete(registration3.Uuid, DateTime.Now); List <string> ous = orgUnitService.List(); if (ous.Count != 2) { throw new Exception("List() returned " + ous.Count + " ous, but 2 was expected"); } foreach (var uuid in ous) { OrgUnitRegistration registration = orgUnitService.Read(uuid); if (uuid.Equals(registration1.Uuid)) { if (!registration1.Name.Equals(registration.Name)) { throw new Exception("Name does not match"); } if (!registration1.ParentOrgUnitUuid.Equals(registration.ParentOrgUnitUuid)) { throw new Exception("ParentOU UUID does not match"); } if (!registration1.Email.Equals(registration.Email)) { throw new Exception("Email does not match"); } } else if (uuid.Equals(registration2.Uuid)) { if (!registration2.Name.Equals(registration.Name)) { throw new Exception("Name does not match"); } if (!registration2.ParentOrgUnitUuid.Equals(registration.ParentOrgUnitUuid)) { throw new Exception("ParentOU UUID does not match"); } if (!registration2.Email.Equals(registration.Email)) { throw new Exception("Email does not match"); } } else { throw new Exception("List returned the uuid of an unexpected ou"); } } properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()] = oldUuid; }