private int GetOrgIdCreatingIfNeeded(OrganizationRepository repo, string name) { var orgResult = repo.GetAllAsync(); Assert.IsTrue(orgResult.IsSuccessful); var orgs = orgResult.Data; var org = orgs .Where(x => x.Name == name) .SingleOrDefault(); if (org == null) { org = new Organization(0, name); var createResult = repo.CreateAsync(org); Assert.IsTrue(createResult.IsSuccessful); return(createResult.Data.Value); } return(org.Id); }