Exemple #1
0
    public void Applies_Filters_To_Each_Post()
    {
        // Arrange
        var c0    = Rnd.Str;
        var p0    = new Model(ULongId <WpPostId>(), c0);
        var c1    = Rnd.Str;
        var p1    = new Model(ULongId <WpPostId>(), c1);
        var posts = new[] { p0, p1 };

        var f0 = Substitute.For <IContentFilter>();

        f0.Execute(Arg.Any <string>()).Returns(x => x.ArgAt <string>(0));

        var f1 = Substitute.For <IContentFilter>();

        f1.Execute(Arg.Any <string>()).Returns(x => x.ArgAt <string>(0));

        var filters = new[] { f0, f1 };

        // Act
        QueryPostsF.ApplyContentFilters <IEnumerable <Model>, Model>(posts, filters);

        // Assert
        f0.Received(1).Execute(c0);
        f1.Received(1).Execute(c0);
        f0.Received(1).Execute(c1);
        f1.Received(1).Execute(c1);
    }
Exemple #2
0
    public void No_Filters_Does_Nothing()
    {
        // Arrange
        var posts   = new[] { new Model(ULongId <WpPostId>(), Rnd.Str) };
        var filters = Array.Empty <IContentFilter>();

        // Act
        var result = QueryPostsF.ApplyContentFilters <IEnumerable <Model>, Model>(posts, filters);

        // Assert
        var some = result.AssertSome();

        Assert.Same(posts, some);
    }
Exemple #3
0
    public void No_Posts_Does_Nothing()
    {
        // Arrange
        var posts   = Substitute.For <IEnumerable <Model> >();
        var filters = new[] { Substitute.For <IContentFilter>() };

        // Act
        var result = QueryPostsF.ApplyContentFilters <IEnumerable <Model>, Model>(posts, filters);

        // Assert
        var some = result.AssertSome();

        Assert.Same(posts, some);
    }
Exemple #4
0
    public void Catches_Exception_In_ContentFilter_Returns_None_With_ApplyContentFiltersExceptionMsg()
    {
        // Arrange
        var posts  = new[] { new Model(ULongId <WpPostId>(), Rnd.Str) };
        var filter = Substitute.For <IContentFilter>();

        filter.Execute(Arg.Any <string>()).Throws(new Exception());
        var filters = new[] { filter };

        // Act
        var result = QueryPostsF.ApplyContentFilters <IEnumerable <Model>, Model>(posts, filters);

        // Assert
        result.AssertNone().AssertType <ApplyContentFiltersExceptionMsg <Model> >();
    }