public void InsertCommunityAdmin() { string id = com.InsertAdmin(3, "2").Result; var community = com.GetByIdAsync(3).Result; Assert.AreEqual(2, community.admins.Count); string id2 = com.DeleteAdmin(3, "2").Result; }
private async Task <OperationResult <string> > PostAdmin(int communityId, string adminId, string userId) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var community = await GetByIdAsync(communityId); var user = await userService.GetByIdAsync(userId); //var admin = await userService.GetByIdAsync(adminId); if (!community.Success) { return new OperationResult <string>() { Success = false, Message = community.Message } } ; //if (!admin.Success) return new OperationResult<int>() { Success = false, Message = user.Message }; if (!community.Result.admins.Select(elem => elem.id).Contains(adminId)) { return new OperationResult <string>() { Success = false, Message = Messages.USER_NOT_ADMIN } } ; if (!user.Success) { return new OperationResult <string>() { Success = false, Message = user.Message } } ; if (community.Result.admins.Select(elem => elem.id).Contains(userId)) { return new OperationResult <string>() { Success = false, Message = Messages.COMMUNITY_HAS_ADMIN } } ; try { var id = await communityRepo.InsertAdmin(communityId, userId); scope.Complete(); return(new OperationResult <string>() { Success = true, Message = Messages.COMMUNITY_ADMIN_INSERTED, Result = id }); } catch (Exception ex) { return(new OperationResult <string>() { Success = false, Message = ex.InnerException.Message }); } } }