コード例 #1
0
        public async Task ItReturnsAllSpeakerDescending()
        {
            // Arrange
            var spec = new SpeakerSpecification(1, 1, nameof(Direction.Desc));

            // Act
            var speakers = (List <Speaker>) await Repository.List(spec);

            // Assert
            Assert.IsAssignableFrom <IEnumerable <Speaker> >(speakers);
        }
コード例 #2
0
    public void WhenSpeakerNotFoundWithId_ThenNull()
    {
        // Arrange
        var badSpeakerId = new Guid("172B6257-582D-4453-A13F-41C6CBE4CAB2");
        var spec         = new SpeakerSpecification(badSpeakerId);

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

        // Assert
        Assert.Null(result);
    }
コード例 #3
0
    public void WhenSpeakerFoundWithId_ThenSpeakerReturned()
    {
        // Arrange
        var spec = new SpeakerSpecification(_id);

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

        // Assert
        Assert.NotNull(result);
        Assert.Equal(_id, result.Id);
    }
コード例 #4
0
    public void WhenSpeakerFoundWithSlug_ThenSpeakerReturned()
    {
        // Arrange
        var spec = new SpeakerSpecification(_slug);

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

        // Assert
        spec.AsNoTracking.Should().Be(true);
        Assert.NotNull(result);
        Assert.Equal(_slug, result.Slug);
    }
コード例 #5
0
        public async Task <SpeakersResult> GetAll(int pageIndex, int itemsPage, string?direction)
        {
            var spec = new SpeakerSpecification(itemsPage * pageIndex, itemsPage, direction);

            var speakers = await _repository.List(spec);

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

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