public async Task TryToReadDocumentThatUserDoesNotHaveAccessTo(bool isValidToken, DefaultPartitionKind defaultPartition, string documentId) { var brokerUrl = IsAzureFunctionLocalEmulator ? _resourceTokenBrokerUrlLocalHost : _resourceTokenBrokerUrl; var userContext = CreateTestUserContext(isValidToken, IsAzureFunctionLocalEmulator); var testB2CAuthService = new TestB2CAuthService(userContext); await using var cosmosTokenClient = new CosmosTokenClient(testB2CAuthService, brokerUrl); try { var document = await cosmosTokenClient.Read <Person>(documentId, defaultPartition); } catch (Exception ex) { Assert.True(ex is DataException); } }
public async Task ReadDocumentEx(bool isValidToken, string documentPrefix, DefaultPartitionKind defaultPartition, string expectedFirstName, string expectedLastName) { var brokerUrl = IsAzureFunctionLocalEmulator ? _resourceTokenBrokerUrlLocalHost : _resourceTokenBrokerUrl; var userContext = CreateTestUserContext(isValidToken, IsAzureFunctionLocalEmulator); var testB2CAuthService = new TestB2CAuthService(userContext); await using var cosmosTokenClient = new CosmosTokenClient(testB2CAuthService, brokerUrl); var documentId = defaultPartition == DefaultPartitionKind.Shared ? documentPrefix : $"{documentPrefix}2-{userContext.UserIdentifier}"; var document = await cosmosTokenClient.Read <PersonEx>(documentId, defaultPartition); Assert.Equal(expectedFirstName, document.FirstName); Assert.Equal(expectedLastName, document.LastName); }