public async Task when_filter_for_partition_key_then_filter_request_are_correct() { //Given var fakeValue = "{\"value\":[{\"PartitionKey\":\"1\", \"RowKey\": \"A\", \"Value\": 4},{\"PartitionKey\":\"2\", \"RowKey\": \"B\", \"Value\": 4}]}"; var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(fakeValue, Encoding.UTF8, "application/json") }); var httpClient = new HttpClient(fakeHttpMessageHandler); var apiHandler = Substitute.For <IAzureStorageHandler>(); apiHandler.GetRequest(Arg.Is(StorageType.Table), Arg.Is(HttpMethod.Get), "faketable()?$filter=PartitionKey eq 'A'").Returns( x => { return(new HttpRequestMessage(HttpMethod.Get, "http://www.justafake.com/faketable()")); } ); var servant = new AzureTableClient(apiHandler, httpClient); //When var result = await servant.GetRowsAsync("faketable", "PartitionKey eq 'A'"); //Then fakeHttpMessageHandler.Requests.Contains(new Request { Method = HttpMethod.Get, Url = "http://www.justafake.com/faketable()" }); }
public void CreateQueryWithoutFilter() { var tableClient = new AzureTableClient("myHub", ConnectionString); var stateQuery = new OrchestrationStateQuery(); TableQuery <AzureTableOrchestrationStateEntity> query = tableClient.CreateQueryInternal(stateQuery, 1, false); Assert.AreEqual("(PartitionKey eq 'IS')", query.FilterString); }
public void CreateQueryWithPrimaryFilter() { var tableClient = new AzureTableClient("myHub", ConnectionString); var stateQuery = new OrchestrationStateQuery(); stateQuery.AddInstanceFilter("myInstance"); TableQuery <AzureTableOrchestrationStateEntity> query = tableClient.CreateQueryInternal(stateQuery, 1, false); Assert.AreEqual("(PartitionKey eq 'IS') and (RowKey ge 'ID_EID_myInstance') and (RowKey lt 'ID_EID_myInstancf')", query.FilterString); }
public void TestInitialize() { var r = new Random(); tableClient = new AzureTableClient("test00" + r.Next(0, 10000), "UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1:10002/"); tableClient.CreateTableIfNotExistsAsync().Wait(); client = TestHelpers.CreateTaskHubClient(); taskHub = TestHelpers.CreateTaskHub(); taskHub.orchestrationService.CreateAsync(true).Wait(); }
private void LoadSettings(AzureStorageAccountSettings settings) { StorageSettings = settings; LoadSchemaMapping(StorageSettings.SchemaDefinition); try { AzureStorageAccount = CloudStorageAccount.Parse(settings.ConnectionString); AzureTableClient = AzureStorageAccount.CreateCloudTableClient(); StorageTable = AzureTableClient.GetTableReference(StorageSettings.TableName); } catch (Exception e) { throw new TelemetryReportingException("Unable to connect to the Azure Storage Table (" + e.Message + "). See InnerException for additional details.", e); } }
private static void Main() { const string tableName = "GeoLocations"; const string tableConString = "<YourConnectionString>"; var tableClient = new AzureTableClient(tableConString, tableName); // Insert single entity to table tableClient.InsertEntity(new GeoLocation { Latitude = "41", // Partition key Longitude = "29", // Row key Continent = "Europe", Country = "Turkey", City = "Istanbul" }); // Insert multiple entities to the table tableClient.InsertEntities(new List <GeoLocation> { new GeoLocation { Latitude = "36", // Partition key Longitude = "140", // Row key Continent = "Asia", Country = "Japan", City = "Tokio" }, new GeoLocation { Latitude = "40", // Partition key Longitude = "-74", // Row key Continent = "North America", Country = "United States", City = "New York" }, }); // Retrieve a single entity. Fast query var istanbul = tableClient.GetEntity <GeoLocation>("41", "29"); // Retrieve multiple entities that have the same partition key. Fast query var locationsByLatitude = tableClient.GetEntitiesByPartitionKey <GeoLocation>("41"); // Retrieve multiple entities that have the same row key. Fast query var locationsByLongtitude = tableClient.GetEntitiesByRowKey <GeoLocation>("29"); // Retrieve entities by custom property (not row or partition key). Slow query var locationsByCountry = tableClient.GetEntities <GeoLocation>("Country", "Turkey"); }
public void when_filtering_then_string_is_encoded_for_request() { //Given var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.NotImplemented)); var httpClient = new HttpClient(fakeHttpMessageHandler); var servant = new AzureTableClient(Substitute.For <IAzureStorageHandler>(), httpClient); var content = "test string '/?:@&=+,$ end test"; //When var result = servant.GetEncodedFilterPropertyValue(content); //Then result.Equals("test%20string%20''%2F%3F%3A%40%26%3D%2B%2C%24%20end%20test"); }
IEnumerable <AzureTableOrchestrationStateEntity> CreateStateEntities(AzureTableClient client, string instanceId, string genId) { var entities = new List <AzureTableOrchestrationStateEntity>(); var runtimeState = new OrchestrationState { OrchestrationInstance = new OrchestrationInstance { InstanceId = instanceId, ExecutionId = genId }, Name = "FooOrch", Version = "1.0", CompletedTime = DateTime.UtcNow, CreatedTime = DateTime.UtcNow, LastUpdatedTime = DateTime.UtcNow, Status = "Screwed", Input = "INPUT_" + instanceId + "_" + genId, Output = null }; entities.Add(new AzureTableOrchestrationStateEntity(runtimeState)); client.WriteEntitiesAsync(entities).Wait(); return(entities); }
IEnumerable <AzureTableOrchestrationHistoryEventEntity> CreateHistoryEntities(AzureTableClient client, string instanceId, string genId, int count) { var historyEntities = new List <AzureTableOrchestrationHistoryEventEntity>(); for (int i = 0; i < count; i++) { var eeStartedEvent = new ExecutionStartedEvent(-1, "EVENT_" + instanceId + "_" + genId + "_" + i); historyEntities.Add(new AzureTableOrchestrationHistoryEventEntity(instanceId, genId, i, DateTime.Now, eeStartedEvent)); } client.WriteEntitiesAsync(historyEntities).Wait(); return(historyEntities); }