public async Task ValidVaultForUserShouldReturn() { var dbContext = MockServices.DbContextMock(); var authenticationService = MockServices.AuthenticationServiceMock().Object; var target = new VaultInformationService(authenticationService, dbContext); var validVaultId = MockEntities.TestVault().Id; var actual = await target.GetVaultForAuthorizedUser(validVaultId); Assert.AreEqual(validVaultId, actual.Id); }
public async Task ValidVaultForDifferentUserShouldNotFound() { var dbContext = MockServices.DbContextMock(); var authenticationService = MockServices.AuthenticationServiceMock(); authenticationService.Setup(x => x.UserId).Returns(777); var target = new VaultInformationService(authenticationService.Object, dbContext); var validVaultId = MockEntities.TestVault().Id; var validUserId = MockEntities.TestUser().Id; await Assert.ThrowsExceptionAsync <StatusCodeException>(async() => await target.GetVaultForAuthorizedUser(validVaultId)); }
public async Task ShouldReturnAllVaultForUser() { var dbContext = MockServices.DbContextMock(); var authenticationService = MockServices.AuthenticationServiceMock().Object; var target = new VaultInformationService(authenticationService, dbContext); var validVaultId = MockEntities.TestVault().Id; var validUserId = MockEntities.TestUser().Id; var vaults = await target.GetVaultsForAuthorizedUser(); var expectedids = await dbContext.Vaults.Where(x => x.Owners.Any(y => y.OwnerId == authenticationService.UserId)).Select(x => x.Id).ToListAsync(); var actualIds = vaults.Select(x => x.Id).ToList(); CollectionAssert.AreEqual(expectedids, actualIds); }