Ejemplo n.º 1
0
    public async Task Calls_Db_QueryAsync()
    {
        // Arrange
        var(db, w, v) = Setup();

        // Act
        await QueryPostsMetaF.ExecuteAsync <Test>(db, w, opt => opt);

        // Assert
        await db.Query.Received().QueryAsync <Test>(Arg.Any <IQueryParts>(), v.Transaction);
    }
Ejemplo n.º 2
0
    public async Task Catches_Opt_Exception_Returns_None_With_ErrorGettingQueryAttachmentsOptionsMsg()
    {
        // Arrange
        var(db, w, _) = Setup();

        // Act
        var result = await QueryPostsMetaF.ExecuteAsync <Test>(db, w, _ => throw new Exception());

        // Assert
        result.AssertNone().AssertType <ErrorGettingQueryPostsMetaOptionsMsg>();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Add meta dictionary to posts
    /// </summary>
    /// <typeparam name="TList">List type</typeparam>
    /// <typeparam name="TModel">Model type</typeparam>
    /// <param name="db">IWpDb</param>
    /// <param name="w">IUnitOfWork</param>
    /// <param name="posts">Posts</param>
    internal static Task <Maybe <TList> > AddMetaAsync <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());
        }

        // Get Meta values
        return(GetMetaDictionary <TModel>()
               .SwitchAsync(
                   some: x =>
                   from postMeta in QueryPostsMetaF.ExecuteAsync <PostMeta>(db, w, opt => opt with
        {
            PostIds = posts.Select(p => p.Id).ToImmutableList()
        })
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public async Task <Maybe <IEnumerable <T> > > PostsMetaAsync <T>(Query.GetPostsMetaOptions opt)
     where T : IWithId <WpPostMetaId>
 {
     using var w = Db.UnitOfWork;
     return(await QueryPostsMetaF.ExecuteAsync <T>(Db, w, opt).ConfigureAwait(false));
 }