Example #1
0
 public async Task <DocumentLibrariesResult> GetDocumentLibrariesAsync(string siteId)
 {
     try
     {
         var drives = await _graphServiceClient.Sites[siteId].Drives.Request().WithUsernamePassword(_username, _password).GetAsync();
         return(DocumentLibrariesResult.Success(drives.AsEnumerable().Select(DocumentLibrary.FromView).ToList()));
     }
     catch (ServiceException e)
     {
         return(DocumentLibrariesResult.Failed(e.InnerException?.Message ?? e.Error?.Message ?? e.Message));
     }
 }
Example #2
0
        public async Task GetDocumentLibraries_Returns_BadRequestObjectResult_When_AnErrorOccurred()
        {
            // Arrange
            var req    = TestFactory.CreateHttpRequest();
            var logger = TestFactory.CreateLogger(LoggerTypes.List);

            _fileServiceMock.Setup(x => x.GetDocumentLibrariesAsync(It.Is <string>(p => p == "siteId"))).ReturnsAsync(DocumentLibrariesResult.Failed("An error occurred."));

            // Act
            var httpActionResult = await _controller.GetDocumentLibraries(req, logger);

            // Assert
            Assert.IsInstanceOf(typeof(BadRequestObjectResult), httpActionResult);

            _fileServiceMock.Verify(x => x.GetDocumentLibrariesAsync(It.Is <string>(p => p == "siteId")), Times.Once);

            var result = ((BadRequestObjectResult)httpActionResult);

            Assert.IsNotNull(result);
            Assert.AreEqual("An error occurred.", result.Value);
        }
Example #3
0
        public async Task GetDocumentLibraries_Returns_EmptyArray_When_NoDocumentLibrariesFound()
        {
            // Arrange
            var req               = TestFactory.CreateHttpRequest();
            var logger            = TestFactory.CreateLogger(LoggerTypes.List);
            var documentLibraries = new List <DocumentLibrary>();

            _fileServiceMock.Setup(x => x.GetDocumentLibrariesAsync(It.Is <string>(p => p == "siteId"))).ReturnsAsync(DocumentLibrariesResult.Success(documentLibraries));

            // Act
            var httpActionResult = await _controller.GetDocumentLibraries(req, logger);

            // Assert
            Assert.IsInstanceOf(typeof(OkObjectResult), httpActionResult);

            _fileServiceMock.Verify(x => x.GetDocumentLibrariesAsync(It.Is <string>(p => p == "siteId")), Times.Once);

            var result = ((OkObjectResult)httpActionResult).Value as DocumentLibraryModelInfo[];

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Length);
        }