public IEnumerable <DocumentDto> GetAvailablePdfDocuments(string orderBy)
        {
            var pdfDocumentEntities = Enum.IsDefined(typeof(OrderType), orderBy)
                ? _pdfDocumentRepository.GetPdfDocuments(Enum.Parse <OrderType>(orderBy))
                : _pdfDocumentRepository.GetPdfDocuments();

            return(pdfDocumentEntities
                   .Select(documentEntity => new DocumentDto
            {
                Name = documentEntity.Id,
                FileSize = $"{documentEntity.FileSizeInKilobytes / 1000} MB",
                Path = documentEntity.Path
            }));
        }
Exemple #2
0
        public void GetPdfDocuments_OrderByType_ReturnsDocumentEntities(OrderType orderType)
        {
            //Arrange
            var documentEntities = _fixture
                                   .CreateMany <DocumentEntity>()
                                   .ToList();

            var orderedQueryable   = documentEntities.AsQueryable().OrderByDescending(entity => entity.Id);
            var documentClientMock = new Mock <IDocumentClient>();

            documentClientMock
            .Setup(client => client.CreateDocumentQuery <DocumentEntity>(It.IsAny <Uri>(), It.IsAny <FeedOptions>()))
            .Returns(orderedQueryable);
            _documentClientFactoryMock
            .Setup(factory => factory.GetClient())
            .Returns(documentClientMock.Object);

            List <DocumentEntity> expectedResult = null;

            switch (orderType)
            {
            case OrderType.Name:
                expectedResult = documentEntities.OrderBy(documentEntity => documentEntity.Id).ToList();
                break;

            case OrderType.Path:
                expectedResult = documentEntities.OrderBy(documentEntity => documentEntity.Path).ToList();
                break;

            case OrderType.Size:
                expectedResult = documentEntities.OrderBy(documentEntity => documentEntity.FileSizeInKilobytes).ToList();
                break;
            }

            //Act
            var actualDocumentEntities = _sut.GetPdfDocuments(orderType);

            //Assert
            actualDocumentEntities.ShouldBe(expectedResult);
        }