public void TestAzureTables()
        {
            var testKey = new AzureTablesTestValue.Key(
                accountId: Guid.NewGuid(),
                secondaryId: Guid.NewGuid());

            var testValueA = new AzureTablesTestValue(
                accountId: testKey.AccountId.Value,
                secondaryId: testKey.SecondaryId.Value,
                message: "Hello, world!");

            var testValueB = new AzureTablesTestValue(
                accountId: testKey.AccountId.Value,
                secondaryId: testKey.SecondaryId.Value,
                message: "Kthx, world!");

            var dataStore = new AzureTableStore <AzureTablesTestValue.Key, AzureTablesTestValue>(
                connectionString: GetConfig("ConnectionString"),
                tableName: GetConfig("TableName"),
                keyMap: "test-values_{AccountId}|{SecondaryId}");

            ClearDataStore(dataStore);

            TestDataStore(
                dataStore,
                testKey,
                testValueA,
                testValueB);
        }
Esempio n. 2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "Post", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            log.LogInformation("Processing UpsertCellar request");
            var stream = req.Body;

            stream.Seek(0, SeekOrigin.Begin);
            var cellarString = new StreamReader(stream).ReadToEnd();
            var cellarRow    = JsonConvert.DeserializeObject <AzureTableCellarModel>(cellarString);

            if (cellarRow == null)
            {
                log.LogError($"Failed to Retireve a valid AzureTableCellarModel from Request: {cellarString}");
                return(new StatusCodeResult(400));
            }
            log.LogInformation("UpsertCellar Request initiated");
            var dataStore = new AzureTableStore(log, context);
            var result    = await dataStore.UpsertCellarRow(cellarRow);

            if (result.GetType() == typeof(StatusCodeResult))
            {
                log.LogError($"Failed to upsert the Cellar Row.");
                return((IActionResult)result);
            }
            var resultStr = JsonConvert.SerializeObject(result);

            log.LogInformation("UpsertCellar Request completed");
            return(new OkObjectResult(resultStr));
        }
        public async Task RunBulkApiTests()
        {
            var dataStore = new AzureTableStore <AzureTablesTestValue.Key, AzureTablesTestValue>(
                connectionString: GetConfig("ConnectionString"),
                tableName: GetConfig("TableName"),
                keyMap: "test-values_{AccountId}|{SecondaryId}");

            ClearDataStore(dataStore);

            await TestBulkApi(dataStore,
                              (keyGen, dataGen) =>
            {
                var partitionId = (keyGen / 100).ToGuid();
                var accountId   = keyGen.ToGuid();

                return(new KeyValuePair <AzureTablesTestValue.Key, AzureTablesTestValue>(new AzureTablesTestValue.Key(partitionId, accountId),
                                                                                         new AzureTablesTestValue(partitionId, accountId, $"Test: {dataGen}")));
            });
        }
        public void TestPartialPartitionKey()
        {
            var testKeyA = new AzureTablesTestValue.Key(
                accountId: Guid.NewGuid(),
                secondaryId: Guid.NewGuid());

            var testKeyB = new AzureTablesTestValue.Key(
                accountId: Guid.NewGuid(),
                secondaryId: Guid.NewGuid());

            var testKeyC = new AzureTablesTestValue.Key(
                accountId: testKeyB.AccountId,
                secondaryId: Guid.NewGuid());

            var testValueA = new AzureTablesTestValue(
                accountId: testKeyA.AccountId.Value,
                secondaryId: testKeyA.SecondaryId.Value,
                message: "Hello, world!");

            var testValueB = new AzureTablesTestValue(
                accountId: testKeyB.AccountId.Value,
                secondaryId: testKeyB.SecondaryId.Value,
                message: "Kthx, world!");

            var testValueC = new AzureTablesTestValue(
                accountId: testKeyC.AccountId.Value,
                secondaryId: testKeyC.SecondaryId.Value,
                message: "¡Hola, mundo!");

            var dataStore = new AzureTableStore <AzureTablesTestValue.Key, AzureTablesTestValue>(
                connectionString: GetConfig("ConnectionString"),
                tableName: GetConfig("TableName"),
                keyMap: "test-values_{AccountId}_key-map-test|{SecondaryId}");

            ClearDataStore(dataStore);

            var preResult = dataStore.ListValues().Result;

            var createAResult = dataStore.Create(testKeyA, testValueA).Result;

            var createBResult = dataStore.Create(testKeyB, testValueB).Result;

            var createCResult = dataStore.Create(testKeyC, testValueC).Result;

            var listAllResult = dataStore.ListValues().Result;

            Assert.True(listAllResult.Count() == 3);

            var listAResult = dataStore.ListValues(k => k.AccountId == testKeyA.AccountId).Result;

            Assert.True(listAResult.SingleOrDefault()?.AccountId == testKeyA.AccountId);

            var listBCResult = dataStore.ListValues(k => k.AccountId == testKeyB.AccountId).Result.ToList();

            Assert.True(
                listBCResult.Count == 2 &&
                listBCResult.Select(r => r.AccountId).Distinct().SingleOrDefault() == testKeyB.AccountId);

            var listBSpecificResult = dataStore
                                      .ListValues(k => k.AccountId == testKeyB.AccountId && k.SecondaryId == testKeyB.SecondaryId)
                                      .Result;

            Assert.True(listBSpecificResult.SingleOrDefault()?.SecondaryId == testKeyB.SecondaryId);

            var deleteAResult = dataStore.Delete(testKeyA).Result;

            var deleteBResult = dataStore.Delete(testKeyB).Result;

            var deleteCResult = dataStore.Delete(testKeyC).Result;

            var postListResult = dataStore.ListKeyValues().Result;

            Assert.True(postListResult.Count() == 0);
        }