public async Task TestFetchAccountFastFail(string id) { var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var factory = serviceProvider.GetService <ILoggerFactory>(); var logger = factory.CreateLogger <AccountApiController>(); var accountApiController = new AccountApiController(new FalseDatabaseService(), logger); var result = await accountApiController.GetAccountMetadata(id); Assert.True(result is BadRequestResult); }
public async Task TestFetchAccount() { var falseDatabaseService = new FalseDatabaseService(); var draftAccount = new Account(Guid.NewGuid(), "Alfa", "*****@*****.**", Array.Empty <byte>()); await falseDatabaseService.SaveAccountAsync(draftAccount, true); 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.GetAccountMetadata(encodedId); var resultBody = (AccountMetadata)result.Value; Assert.Equal(draftAccount.DisplayName, resultBody.DisplayName); Assert.Equal(draftAccount.Email.ToGravatarHash(), resultBody.GravatarHash); Assert.Equal(draftAccount.Id, resultBody.Id); }
public async Task TestFetchNonExistentAccount() { var falseDatabaseService = new FalseDatabaseService(); var draftAccount = new Account(Guid.NewGuid(), "Alfa", "*****@*****.**", Array.Empty <byte>()); await falseDatabaseService.SaveAccountAsync(draftAccount, true); var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var factory = serviceProvider.GetService <ILoggerFactory>(); var logger = factory.CreateLogger <AccountApiController>(); var accountApiController = new AccountApiController(falseDatabaseService, logger); var idWhichIsNotRepresentedInTheDatabase = WebEncoders.Base64UrlEncode(Guid.NewGuid().ToByteArray()); try { var result = await accountApiController.GetAccountMetadata(idWhichIsNotRepresentedInTheDatabase); Assert.True(false); } catch (Exception ex) { Assert.True(ex is FileNotFoundException); } }