Beispiel #1
0
    public void WhenCommunityFoundWithId_ThenCommunityReturned()
    {
        // Arrange
        var spec = new CommunitySpecification(_id);

        // Act
        var result = spec.Evaluate(GetTestCollection()).Single();

        // Assert
        Assert.NotNull(result);
        Assert.Equal(_id, result.Id);
    }
Beispiel #2
0
    public void WhenCommunityNotFoundWithId_ThenNull()
    {
        // Arrange
        var badCommunityId = new Guid("172B6257-582D-4453-A13F-41C6CBE4CAB2");
        var spec           = new CommunitySpecification(badCommunityId);

        // Act
        var result = spec.Evaluate(GetTestCollection()).SingleOrDefault();

        // Assert
        Assert.Null(result);
    }
Beispiel #3
0
    public void WhenCommunityFoundWithSlug_ThenCommunityReturned()
    {
        // Arrange
        var spec = new CommunitySpecification(_slug);

        // Act
        var result = spec.Evaluate(GetTestCollection()).Single();

        // Assert
        spec.AsNoTracking.Should().Be(true);
        Assert.NotNull(result);
        Assert.Equal(_slug, result.Slug);
    }
        public async Task <CommunitiesResult> GetAll(int pageIndex, int itemsPage, string?direction)
        {
            var spec = new CommunitySpecification(itemsPage * pageIndex, itemsPage, direction);

            var communities = await _repository.List(spec);

            var total = await _repository.Count <Community>();

            return(new CommunitiesResult {
                Communities = communities.Select(x => new CommunitiesResult.Community
                {
                    Id = x.Id,
                    Location = x.Location,
                    Name = x.Name,
                    Slug = x.Slug,
                    Description = x.Description,
                }).ToList(),
                PaginationInfo = new PaginationInfo(total, communities.Count, pageIndex, int.Parse(Math.Ceiling((decimal)total / itemsPage)
                                                                                                   .ToString(CultureInfo.InvariantCulture)))
            });
        }