Example #1
0
        public async Task EncryptionDekReadFeed()
        {
            DatabaseCore databaseCore = null;

            try
            {
                databaseCore = (DatabaseInlineCore)await EncryptionTests.client.CreateDatabaseAsync(Guid.NewGuid().ToString());

                ContainerCore containerCore = (ContainerInlineCore)await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/PK", 400);

                string contosoV1  = "Contoso_v001";
                string contosoV2  = "Contoso_v002";
                string fabrikamV1 = "Fabrikam_v001";
                string fabrikamV2 = "Fabrikam_v002";

                await EncryptionTests.CreateDekAsync(databaseCore, contosoV1);

                await EncryptionTests.CreateDekAsync(databaseCore, contosoV2);

                await EncryptionTests.CreateDekAsync(databaseCore, fabrikamV1);

                await EncryptionTests.CreateDekAsync(databaseCore, fabrikamV2);

                // Test getting all keys
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false);

                // Test getting specific subset of keys
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : false,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : true,
                    itemCountInPage : 1);

                // Ensure only required results are returned (ascending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : false);

                // Test startId inclusive and endId inclusive (ascending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v001",
                    endId : "Contoso_v002",
                    isDescending : false);

                // Ensure only required results are returned (descending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2, contosoV1
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : true);

                // Test startId inclusive and endId inclusive (descending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2, contosoV1
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v001",
                    endId : "Contoso_v002",
                    isDescending : true);

                // Test pagination
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false,
                    itemCountInPage : 3);
            }
            finally
            {
                if (databaseCore != null)
                {
                    await databaseCore.DeleteStreamAsync();
                }
            }
        }