コード例 #1
0
        public async Task <Document> GetDocumentAsync(IDbConnection dbConnection, Guid documentId)
        {
            _logger.LogInformation($"Getting document with ID '{documentId}'...");
            var dalObject = await _dbContext.GetDocumentAsync(dbConnection, documentId);

            return(_mapper.Map <Document>(dalObject));
        }
コード例 #2
0
        public async void GetDocumentAsync()
        {
            _logger.LogInformation("GetDocumentAsync...");
            var newItem = new Document()
            {
                Name = $"DATA_ACCESS_LAYER_TEST_{DateTime.Now:yyyyMMddHHmmssfff}.jpg",
                Type = "jpg",
                Data = await File.ReadAllBytesAsync("./TestFiles/Test.jpg")
            };

            using (var dbTransaction = await _dbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertDocumentAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(newItem.DocumentId, result.DocumentId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            var pageRequest = new PageRequest()
            {
                SortBy    = "LastWrite",
                SortOrder = SortOrders.DESC,
                PageIndex = 0,
                PageSize  = 50
            };

            using (var dbConnection = await _dbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetDocumentsAsync(dbConnection, pageRequest);

                Assert.NotNull(result);

                var firstDocument = result.Items.First();
                Assert.Empty(firstDocument.Data);

                var document = await _dbContext.GetDocumentAsync(dbConnection, firstDocument.DocumentId);

                Assert.NotEmpty(document.Data);
            }
        }