示例#1
0
        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));
        }
示例#2
0
        public async Task TestFetchDocumentsForNonExistentAccount()
        {
            var serviceProvider      = new ServiceCollection().AddLogging().BuildServiceProvider();
            var factory              = serviceProvider.GetService <ILoggerFactory>();
            var logger               = factory.CreateLogger <AccountApiController>();
            var falseDatabaseService = new FalseDatabaseService();
            var draftAccount         = new Account(Guid.NewGuid(), "Alfa", "*****@*****.**", Array.Empty <byte>());
            await falseDatabaseService.SaveAccountAsync(draftAccount, true);

            var accountApiController = new AccountApiController(falseDatabaseService, logger);
            var idWhichIsNotRepresentedInTheDatabase = WebEncoders.Base64UrlEncode(Guid.NewGuid().ToByteArray());
            var result = (OkObjectResult)await accountApiController.GetAccountDocuments(idWhichIsNotRepresentedInTheDatabase);

            var resultBody = (IEnumerable <MD5Sum>)result.Value;

            Assert.Empty(resultBody);
        }