public async Task Calls_Db_QueryAsync() { // Arrange var(db, w, v) = Setup(); // Act await QueryPostsTaxonomyF.ExecuteAsync <Test>(db, w, opt => opt); // Assert await db.Query.Received().QueryAsync <Test>(Arg.Any <IQueryParts>(), v.Transaction); }
public async Task Catches_Opt_Exception_Returns_None_With_ErrorGettingQueryAttachmentsOptionsMsg() { // Arrange var(db, w, _) = Setup(); // Act var result = await QueryPostsTaxonomyF.ExecuteAsync <Test>(db, w, _ => throw new Exception()); // Assert result.AssertNone().AssertType <ErrorGettingQueryPostsTaxonomyOptionsMsg>(); }
/// <summary> /// Add Taxonomies to posts /// </summary> /// <typeparam name="TList">List type</typeparam> /// <typeparam name="TModel">Post type</typeparam> /// <param name="db">IWpDb</param> /// <param name="w">IUnitOfWork</param> /// <param name="posts">Posts</param> internal static Task <Maybe <TList> > AddTaxonomiesAsync <TList, TModel>(IWpDb db, IUnitOfWork w, TList posts) where TList : IEnumerable <TModel> where TModel : IWithId <WpPostId> { // If there are no posts, do nothing if (!posts.Any()) { return(F.Some(posts).AsTask()); } // Only proceed if there is at least one term list in this model var termLists = GetTermLists <TModel>(); if (termLists.Count == 0) { return(F.Some(posts).AsTask()); } // Get terms and add them to the posts return(QueryPostsTaxonomyF .ExecuteAsync <Term>(db, w, opt => opt with { PostIds = posts.Select(p => p.Id).ToImmutableList() })
/// <inheritdoc/> public async Task <Maybe <IEnumerable <T> > > PostsTaxonomyAsync <T>(Query.GetPostsTaxonomyOptions opt) where T : IWithId <WpTermId> { using var w = Db.UnitOfWork; return(await QueryPostsTaxonomyF.ExecuteAsync <T>(Db, w, opt).ConfigureAwait(false)); }