internal static Guid NotFoundEntity <TEntity>(this IBasicRepository <TEntity, Guid> repo) where TEntity : BaseEntity { var id = Guid.NewGuid(); repo.Get(id).Returns(new Result <TEntity>().AddErrorMessage("Not found")); return(id); }
public RootFolder Get(int id) { var rootFolder = _rootFolderRepository.Get(id); rootFolder.FreeSpace = _diskProvider.GetAvailableSpace(rootFolder.Path); rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path); return(rootFolder); }
internal static TEntity FoundEntity <TEntity>(this IBasicRepository <TEntity, Guid> repo, Guid id) where TEntity : BaseEntity { var entity = Activator.CreateInstance <TEntity>(); entity.Id = id; repo.Get(id).Returns(new Result <TEntity>() { Return = entity }); return(entity); }
public static IEnumerable <TParent> LoadSubtype <TParent, TChild>(this IEnumerable <TParent> parents, Func <TParent, int> foreignKeySelector, IBasicRepository <TChild> childRepository) where TChild : ModelBase, new() where TParent : RestResource { var parentList = parents.Where(p => foreignKeySelector(p) != 0).ToList(); if (!parentList.Any()) { return(parents); } var ids = parentList.Select(foreignKeySelector).Distinct(); var childDictionary = childRepository.Get(ids).ToDictionary(child => child.Id, child => child); var childSetter = GetChildSetter <TParent, TChild>(); foreach (var episode in parentList) { childSetter.Invoke(episode, new object[] { childDictionary[foreignKeySelector(episode)] }); } return(parents); }