public async Task TestFetchDocuments() { var falseDatabaseService = new FalseDatabaseService(); var draftAccount = new Account(Guid.NewGuid(), "Alfa", "*****@*****.**", Array.Empty <byte>()); var decoyAccount = new Account(Guid.NewGuid(), "Bravo", "*****@*****.**", Array.Empty <byte>()); await falseDatabaseService.SaveAccountAsync(draftAccount, true); await falseDatabaseService.SaveAccountAsync(decoyAccount, true); var draftDocumentKeys = new[] { await falseDatabaseService.AddDocumentAsync(draftAccount.Id, "alfa", string.Empty, Enumerable.Empty <MD5Sum>()), await falseDatabaseService.AddDocumentAsync(draftAccount.Id, "bravo", string.Empty, Enumerable.Empty <MD5Sum>()) }; var decoyDocumentKeys = new[] { await falseDatabaseService.AddDocumentAsync(decoyAccount.Id, "charlie", string.Empty, Enumerable.Empty <MD5Sum>()), await falseDatabaseService.AddDocumentAsync(decoyAccount.Id, "delta", string.Empty, Enumerable.Empty <MD5Sum>()) }; var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var factory = serviceProvider.GetService <ILoggerFactory>(); var logger = factory.CreateLogger <AccountApiController>(); var accountApiController = new AccountApiController(falseDatabaseService, logger); var encodedId = WebEncoders.Base64UrlEncode(draftAccount.Id.ToByteArray()); var result = (OkObjectResult)await accountApiController.GetAccountDocuments(encodedId); var resultBody = (IEnumerable <MD5Sum>)result.Value; Assert.Equal(resultBody.Count(), draftDocumentKeys.Count()); Assert.True(resultBody.SequenceEqual(draftDocumentKeys)); }
public async Task TestFetchDocument() { var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var factory = serviceProvider.GetService <ILoggerFactory>(); var logger = factory.CreateLogger <DocumentApiController>(); var testBody = "The quick brown fox jumps over the lazy dog."; var falseDatabaseService = new FalseDatabaseService(); var draftAccount = new Account(Guid.NewGuid(), "Alfa", "*****@*****.**", Array.Empty <byte>()); await falseDatabaseService.SaveAccountAsync(draftAccount, true); var documentId = await falseDatabaseService.AddDocumentAsync(draftAccount.Id, testBody, string.Empty, Enumerable.Empty <MD5Sum>()); var options = new Options <InputConfiguration>(new InputConfiguration()); var documentApiController = new DocumentApiController(falseDatabaseService, options, logger); var result = (ContentResult)await documentApiController.GetDocument(documentId.ToString()); Assert.Equal(result.Content, testBody); Assert.Equal(result.ContentType, "text/markdown"); }