public async Task InsertSingleEntityWithMultipleAssociationsSingleBatch() { IDictionary <string, object> product1 = null; IDictionary <string, object> product2 = null; var batch = new ODataBatch(_serviceUri); batch += async c => product1 = await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test15" }, { "UnitPrice", 21m } }); batch += async c => product2 = await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test16" }, { "UnitPrice", 22m } }); batch += c => c.InsertEntryAsync("Categories", new Entry() { { "CategoryName", "Test17" }, { "Products", new[] { product1, product2 } } }, false); await batch.ExecuteAsync(); var category = await _client .For("Categories") .Expand("Products") .Filter("CategoryName eq 'Test17'") .FindEntryAsync(); Assert.Equal(2, (category["Products"] as IEnumerable <object>).Count()); }
public async Task InsertSingleEntityWithMultipleAssociationsSingleBatch() { var settings = CreateDefaultSettings().WithHttpMock(); var x = ODataDynamic.Expression; dynamic product1 = new { ProductName = "Test15", UnitPrice = 21m }; dynamic product2 = new { ProductName = "Test16", UnitPrice = 22m }; var batch = new ODataBatch(settings); batch += c => c .For(x.Products) .Set(product1) .InsertEntryAsync(false); batch += c => c .For <Product>() .Set(product2) .InsertEntryAsync(false); batch += async c => await c .For(x.Categories) .Set(x.CategoryName = "Test17", x.Products = new[] { product1, product2 }) .InsertEntryAsync(false); await batch.ExecuteAsync(); var client = new ODataClient(settings); var category = await client .For(x.Categories) .Expand(x.Products) .Filter(x.CategoryName == "Test17") .FindEntryAsync(); Assert.Equal(2, (category.Products as IEnumerable <dynamic>).Count()); }
public virtual async Task CallSyncTo(DtoSetSyncConfig[] toServerDtoSetSyncMaterials, CancellationToken cancellationToken) { if (toServerDtoSetSyncMaterials == null) { throw new ArgumentNullException(nameof(toServerDtoSetSyncMaterials)); } if (toServerDtoSetSyncMaterials.Any()) { await using (EfCoreDbContextBase offlineContextForSyncTo = Container.Resolve <EfCoreDbContextBase>()) { ((IsSyncDbContext)offlineContextForSyncTo).IsSyncDbContext = true; ODataBatch onlineBatchContext = Container.Resolve <ODataBatch>(); foreach (DtoSetSyncConfig toServerSyncConfig in toServerDtoSetSyncMaterials) { IQueryable <ISyncableDto> offlineSet = toServerSyncConfig.OfflineDtoSet(offlineContextForSyncTo); ISyncableDto[] recentlyChangedOfflineDtos = (await offlineSet.IgnoreQueryFilters().Where(s => EF.Property <bool>(s, "IsSynced") == false).AsNoTracking().ToArrayAsync(cancellationToken).ConfigureAwait(false)) .ToArray(); if (recentlyChangedOfflineDtos.Any() == false) { continue; } TypeInfo dtoType = offlineSet.ElementType.GetTypeInfo(); PropertyInfo[] keyProps = offlineContextForSyncTo .Model .FindEntityType(dtoType) .FindPrimaryKey() .Properties .Select(x => dtoType.GetProperty(x.Name)) .ToArray() !; foreach (ISyncableDto recentlyChangedOfflineDto in recentlyChangedOfflineDtos) { object[] keys = keyProps.Select(p => p.GetValue(recentlyChangedOfflineDto, null)).ToArray() !; if (recentlyChangedOfflineDto.IsArchived == true) { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Key(keys).DeleteEntryAsync(cancellationToken); } else if (recentlyChangedOfflineDto.Version == 0) { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Set(recentlyChangedOfflineDto).CreateEntryAsync(cancellationToken); } else { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Key(keys).Set(recentlyChangedOfflineDto).UpdateEntryAsync(cancellationToken); } } } await onlineBatchContext.ExecuteAsync(cancellationToken).ConfigureAwait(false); } } }
public async Task DeleteEntriesMultiple() { var batch = new ODataBatch(_serviceUri); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test21" }, { "UnitPrice", 111m } }); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test22" }, { "UnitPrice", 111m } }); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test23" }, { "UnitPrice", 111m } }); await batch.ExecuteAsync(); batch = new ODataBatch(_serviceUri); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=UnitPrice eq 111"); await batch.ExecuteAsync(); var product = await _client .For("Products") .Filter("UnitPrice eq 111") .FindEntryAsync(); Assert.Null(product); }
public async Task PartialFailures() { var batch = new ODataBatch(_serviceUri); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 10m }, { "SupplierID", 0xFFFF } }, false); await AssertThrowsAsync<WebRequestException>(async () => await batch.ExecuteAsync()); }
public async Task Success() { var x = ODataDynamic.Expression; var batch = new ODataBatch(_serviceUri); batch += c => c .For(x.Products) .Set(x.ProductName = "Test1", x.UnitPrice = 10m) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(x.ProductName = "Test2", x.UnitPrice = 20m) .InsertEntryAsync(false); await batch.ExecuteAsync(); var product = await _client .For(x.Products) .Filter(x.ProductName == "Test1") .FindEntryAsync(); Assert.NotNull(product); product = await _client .For(x.Products) .Filter(x.ProductName == "Test2") .FindEntryAsync(); Assert.NotNull(product); }
public async Task SuccessWithResults() { var x = ODataDynamic.Expression; dynamic product1 = null; dynamic product2 = null; var batch = new ODataBatch(_serviceUri); batch += async c => product1 = await c .For(x.Products) .Set(x.ProductName = "Test1", x.UnitPrice = 10m) .InsertEntryAsync(); batch += async c => product2 = await c .For(x.Products) .Set(x.ProductName = "Test2", x.UnitPrice = 20m) .InsertEntryAsync(); await batch.ExecuteAsync(); Assert.NotEqual(0, product1.ProductID); Assert.NotEqual(0, product2.ProductID); product1 = await _client .For(x.Products) .Filter(x.ProductName == "Test1") .FindEntryAsync(); Assert.NotNull(product1); product2 = await _client .For(x.Products) .Filter(x.ProductName == "Test2") .FindEntryAsync(); Assert.NotNull(product2); }
public async Task InsertSingleEntityWithSingleAssociationSingleBatch() { var settings = CreateDefaultSettings().WithHttpMock(); IDictionary <string, object> category = null; var batch = new ODataBatch(settings); batch += async x => category = await x.InsertEntryAsync("Categories", new Entry() { { "CategoryName", "Test13" } }); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test14" }, { "UnitPrice", 21m }, { "Category", category } }, false); await batch.ExecuteAsync(); var client = new ODataClient(settings); var product = await client .For("Products") .Expand("Category") .Filter("ProductName eq 'Test14'") .FindEntryAsync(); Assert.Equal("Test13", (product["Category"] as IDictionary <string, object>)["CategoryName"]); }
public async Task SuccessWithResults() { IDictionary <string, object> product1 = null; IDictionary <string, object> product2 = null; var batch = new ODataBatch(_serviceUri); batch += async x => { product1 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }); }; batch += async x => { product2 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m } }); }; await batch.ExecuteAsync(); Assert.NotNull(product1["ProductID"]); Assert.NotNull(product2["ProductID"]); product1 = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'"); Assert.NotNull(product1); product2 = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'"); Assert.NotNull(product2); }
private void WriteFeed(Edm edm, string absolutUri, string entitySetName, IList <IDictionary <string, object> > dataList) { ODataClient client = new ODataClient(new System.Uri(url)); ODataBatch batch = new ODataBatch(client); foreach (IDictionary <string, object> data in dataList) { batch += c => client.For("Entry").Set(data).InsertEntryAsync(); } System.Threading.Tasks.Task task = batch.ExecuteAsync(); WaitForTaskToComplete(task); Exception e = task.Exception; if (e != null) { if (e.InnerException is Simple.OData.Client.WebRequestException) { // this means we got a response from the server with a specific message. Simple.OData.Client.WebRequestException inner = (Simple.OData.Client.WebRequestException)e.InnerException; throw new System.Exception(inner.Message + " : " + inner.Response); } throw e; } }
public async Task Success() { var settings = CreateDefaultSettings().WithHttpMock(); var x = ODataDynamic.Expression; var batch = new ODataBatch(settings); batch += c => c .For(x.Products) .Set(x.ProductName = "Test1", x.UnitPrice = 10m) .InsertEntryAsync(false); batch += c => c .For <Product>() .Set(x.ProductName = "Test2", x.UnitPrice = 20m) .InsertEntryAsync(false); await batch.ExecuteAsync(); var client = new ODataClient(settings); var product = await client .For(x.Products) .Filter(x.ProductName == "Test1") .FindEntryAsync(); Assert.NotNull(product); product = await client .For(x.Products) .Filter(x.ProductName == "Test2") .FindEntryAsync(); Assert.NotNull(product); }
public async Task InsertSingleEntityWithSingleAssociationSingleBatch() { var settings = CreateDefaultSettings().WithHttpMock(); var category = new Category() { CategoryName = "Test13" }; var batch = new ODataBatch(settings); batch += async c => await c .For <Category>() .Set(category) .InsertEntryAsync().ConfigureAwait(false); batch += c => c .For <Product>() .Set(new { ProductName = "Test14", UnitPrice = 21m, Category = category }) .InsertEntryAsync(); await batch.ExecuteAsync().ConfigureAwait(false); var client = new ODataClient(settings); var product = await client .For <Product>() .Expand(x => x.Category) .Filter(x => x.ProductName == "Test14") .FindEntryAsync().ConfigureAwait(false); Assert.Equal("Test13", product.Category.CategoryName); }
public async Task Success() { var settings = CreateDefaultSettings().WithHttpMock(); var batch = new ODataBatch(settings); batch += c => c .For <Product>() .Set(new Product() { ProductName = "Test1", UnitPrice = 10m }) .InsertEntryAsync(false); batch += c => c .For <Product>() .Set(new Product() { ProductName = "Test2", UnitPrice = 20m }) .InsertEntryAsync(false); await batch.ExecuteAsync().ConfigureAwait(false); var client = new ODataClient(settings); var product = await client .For <Product>() .Filter(x => x.ProductName == "Test1") .FindEntryAsync().ConfigureAwait(false); Assert.NotNull(product); product = await client .For <Product>() .Filter(x => x.ProductName == "Test2") .FindEntryAsync().ConfigureAwait(false); Assert.NotNull(product); }
public static async Task UseBatch(ErpSession session) { // Update the quantity of several sales order lines in a batch. var order = await session.Client.For("Crm_Sales_SalesOrders") .Key(Guid.Parse("cc661805-a4be-4ad3-a2a5-08570c7d12f7")) .Select("Id,Lines") .Expand("Lines") .Top(1) .FindEntryAsync(); var lines = (IEnumerable <IDictionary <string, object> >)order["Lines"]; var batch = new ODataBatch(session.Client); foreach (var line in lines) { // Quantity is complex type consisted of Value and Unit. var quantity = (IDictionary <string, object>)line["Quantity"]; decimal value = (decimal)quantity["Value"]; string unit = (string)quantity["Unit"]; value += 5; // Update the line batch += c => c.For("Crm_Sales_SalesOrderLines") .Key(line["Id"]) .Set(new { Quantity = new { Value = value, Unit = unit } }) .UpdateEntryAsync(); } await batch.ExecuteAsync(); }
public async Task InsertSingleEntityWithSingleAssociationSingleBatch() { var settings = CreateDefaultSettings().WithHttpMock(); var x = ODataDynamic.Expression; var category = new Category() { CategoryName = "Test13" }; var batch = new ODataBatch(settings); batch += async c => await c .For(x.Categories) .Set(category) .InsertEntryAsync(); batch += c => c .For(x.Products) .Set(x.ProductName = "Test14", x.UnitPrice = 21m, x.Category = category) .InsertEntryAsync(); await batch.ExecuteAsync(); var client = new ODataClient(settings); var product = await client .For(x.Products) .Expand(x.Category) .Filter(x.ProductName == "Test14") .FindEntryAsync(); Assert.Equal("Test13", product.Category.CategoryName); }
public void Update(IEntity entity) { _batch += command => command.For(entity.GetType().Name) .Key(entity.Id) .Set(entity) .UpdateEntryAsync(); }
public async Task Success() { var x = ODataDynamic.Expression; var batch = new ODataBatch(_serviceUri); batch += c => c .For(x.Products) .Set(x.ProductName = "Test1", x.UnitPrice = 10m) .InsertEntryAsync(false); batch += c => c .For <Product>() .Set(x.ProductName = "Test2", x.UnitPrice = 20m) .InsertEntryAsync(false); await batch.ExecuteAsync(); var product = await _client .For(x.Products) .Filter(x.ProductName == "Test1") .FindEntryAsync(); Assert.NotNull(product); product = await _client .For(x.Products) .Filter(x.ProductName == "Test2") .FindEntryAsync(); Assert.NotNull(product); }
public async Task SuccessWithResults() { Product product1 = null; Product product2 = null; var batch = new ODataBatch(_serviceUri); batch += async c => product1 = await c .For<Product>() .Set(new Product() { ProductName = "Test1", UnitPrice = 10m }) .InsertEntryAsync(); batch += async c => product2 = await c .For<Product>() .Set(new Product() { ProductName = "Test2", UnitPrice = 20m }) .InsertEntryAsync(); await batch.ExecuteAsync(); Assert.NotEqual(0, product1.ProductID); Assert.NotEqual(0, product2.ProductID); product1 = await _client .For<Product>() .Filter(x => x.ProductName == "Test1") .FindEntryAsync(); Assert.NotNull(product1); product2 = await _client .For<Product>() .Filter(x => x.ProductName == "Test2") .FindEntryAsync(); Assert.NotNull(product2); }
public async Task SuccessWithResults() { var settings = CreateDefaultSettings().WithHttpMock(); IDictionary <string, object> product1 = null; IDictionary <string, object> product2 = null; var batch = new ODataBatch(settings); batch += async x => { product1 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }); }; batch += async x => { product2 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m } }); }; await batch.ExecuteAsync(); Assert.NotNull(product1["ProductID"]); Assert.NotNull(product2["ProductID"]); var client = new ODataClient(settings); product1 = await client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'"); Assert.NotNull(product1); product2 = await client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'"); Assert.NotNull(product2); }
public async Task DeleteEntriesNonExisting() { var batch = new ODataBatch(_serviceUri); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=ProductName eq 'Test99'"); await batch.ExecuteAsync(); }
public async Task LinkEntry() { var category = await _client .For("Categories") .Set(new { CategoryName = "Test4" }) .InsertEntryAsync(); var product = await _client .For("Products") .Set(new { ProductName = "Test5" }) .InsertEntryAsync(); var batch = new ODataBatch(_serviceUri); batch += async c => await c .For("Products") .Key(product) .LinkEntryAsync("Category", category); await batch.ExecuteAsync(); product = await _client .For("Products") .Filter("ProductName eq 'Test5'") .FindEntryAsync(); Assert.NotNull(product["CategoryID"]); Assert.Equal(category["CategoryID"], product["CategoryID"]); }
public async Task UpdateDeleteSingleBatch() { IDictionary <string, object> product = null; IDictionary <string, object> product1 = null; IDictionary <string, object> product2 = null; var batch = new ODataBatch(_serviceUri); batch += async x => product = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test11" }, { "UnitPrice", 21m } }, false); await batch.ExecuteAsync(); batch = new ODataBatch(_serviceUri); batch += c => c.UpdateEntryAsync("Products", product, new Entry() { { "UnitPrice", 22m } }); batch += async c => product1 = await c.FindEntryAsync("Products?$filter=ProductName eq 'Test11'"); batch += c => c.DeleteEntryAsync("Products", product); batch += async c => product2 = await c.FindEntryAsync("Products?$filter=ProductName eq 'Test11'"); await batch.ExecuteAsync(); Assert.Equal(22m, product1["UnitPrice"]); Assert.Null(product2); product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test11'"); Assert.Null(product); }
public virtual ODataBatch BuildODataBatchClient(Action <HttpRequestMessage> beforeRequest = null, Action <HttpResponseMessage> afterResponse = null, OAuthToken token = null, string route = null) { if (route == null) { route = "Test"; } ODataBatch client = new ODataBatch(new ODataClientSettings($"{Uri}odata/{route}/") { BeforeRequest = message => { if (token != null) { message.Headers.Add("Authorization", $"{token.token_type} {token.access_token}"); } if (beforeRequest != null) { beforeRequest(message); } }, AfterResponse = message => { if (afterResponse != null) { afterResponse(message); } }, OnCreateMessageHandler = () => GetHttpMessageHandler() }); return(client); }
public async Task InsertSingleEntityWithSingleAssociationSingleBatch() { var category = new Category() { CategoryName = "Test13" }; var batch = new ODataBatch(_serviceUri); batch += async c => await c .For <Category>() .Set(category) .InsertEntryAsync(); batch += c => c .For <Product>() .Set(new { ProductName = "Test14", UnitPrice = 21m, Category = category }) .InsertEntryAsync(); await batch.ExecuteAsync(); var product = await _client .For <Product>() .Expand(x => x.Category) .Filter(x => x.ProductName == "Test14") .FindEntryAsync(); Assert.Equal("Test13", product.Category.CategoryName); }
public async Task Batch() { IEnumerable <Airline> airlines1 = null; IEnumerable <Airline> airlines2 = null; var batch = new ODataBatch(_client); batch += async c => airlines1 = await c .For <Airline>() .FindEntriesAsync(); batch += c => c .For <Airline>() .Set(new Airline() { AirlineCode = "TT", Name = "Test Airline" }) .InsertEntryAsync(false); batch += async c => airlines2 = await c .For <Airline>() .FindEntriesAsync(); await batch.ExecuteAsync(); Assert.Equal(8, airlines1.Count()); Assert.Equal(8, airlines2.Count()); }
public async Task LinkEntry() { var settings = CreateDefaultSettings().WithHttpMock(); var client = new ODataClient(settings); var category = await client .For("Categories") .Set(new { CategoryName = "Test4" }) .InsertEntryAsync(); var product = await client .For("Products") .Set(new { ProductName = "Test5" }) .InsertEntryAsync(); var batch = new ODataBatch(settings); batch += async c => await c .For("Products") .Key(product) .LinkEntryAsync("Category", category); await batch.ExecuteAsync(); product = await client .For("Products") .Filter("ProductName eq 'Test5'") .FindEntryAsync(); Assert.NotNull(product["CategoryID"]); Assert.Equal(category["CategoryID"], product["CategoryID"]); }
public async Task UpdateWithResultRequired() { var settings = CreateDefaultSettings().WithHttpMock(); IDictionary <string, object> product = null; IDictionary <string, object> product1 = null; var batch = new ODataBatch(settings); batch += async x => product = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test11" }, { "UnitPrice", 21m } }, true); await batch.ExecuteAsync(); batch = new ODataBatch(settings); batch += async c => product1 = await c.UpdateEntryAsync("Products", product, new Entry() { { "UnitPrice", 22m } }, true); await batch.ExecuteAsync(); Assert.Equal(22m, product1["UnitPrice"]); }
public async Task DeleteEntriesMultiple() { var settings = CreateDefaultSettings().WithHttpMock(); var batch = new ODataBatch(settings); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test21" }, { "UnitPrice", 111m } }); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test22" }, { "UnitPrice", 111m } }); batch += async c => await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test23" }, { "UnitPrice", 111m } }); await batch.ExecuteAsync(); batch = new ODataBatch(settings); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=UnitPrice eq 111"); await batch.ExecuteAsync(); var client = new ODataClient(settings); var product = await client .For("Products") .Filter("UnitPrice eq 111") .FindEntryAsync(); Assert.Null(product); }
public async Task DeleteEntriesNonExisting() { var settings = CreateDefaultSettings().WithHttpMock(); var batch = new ODataBatch(settings); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=ProductName eq 'Test99'"); await batch.ExecuteAsync(); }
public virtual async Task LoadDataAsync(CancellationToken cancellationToken) { ODataBatch BatchClient = new ODataBatch(ODataClient, reuseSession: true); BatchClient += async client => ToDoGroups = (await client.For <ToDoGroupDto>("ToDoGroups").Function("GetMyToDoGroups").FindEntriesAsync(cancellationToken)).ToList(); BatchClient += async client => ToDoItems = (await client.For <ToDoItemDto>("ToDoItems").Function("GetMyToDoItems").FindEntriesAsync(cancellationToken)).ToList(); await BatchClient.ExecuteAsync(cancellationToken); }
public virtual async Task CallSyncTo(DtoSetSyncConfig[] toServerDtoSetSyncMaterials, CancellationToken cancellationToken) { if (toServerDtoSetSyncMaterials.Any()) { using (TDbContext offlineContextForSyncTo = _dbContextProvider()) { ((IsSyncDbContext)offlineContextForSyncTo).IsSyncDbContext = true; ODataBatch onlineBatchContext = _oDataBatchProvider(); foreach (DtoSetSyncConfig toServerSyncConfig in toServerDtoSetSyncMaterials) { IQueryable <ISyncableDto> offlineSet = toServerSyncConfig.OfflineDtoSet(offlineContextForSyncTo); ISyncableDto[] recentlyChangedOfflineDtos = (await offlineSet.IgnoreQueryFilters().Where(s => EF.Property <bool>(s, "IsSynced") == false).AsNoTracking().ToArrayAsync(cancellationToken).ConfigureAwait(false)) .Cast <ISyncableDto>() .ToArray(); ISyncableDto firstRecentlyChangedOfflineDto = recentlyChangedOfflineDtos.FirstOrDefault(); if (firstRecentlyChangedOfflineDto == null) { continue; } TypeInfo dtoType = firstRecentlyChangedOfflineDto.GetType().GetTypeInfo(); PropertyInfo[] keyProps = offlineContextForSyncTo .Model .FindEntityType(dtoType) .FindPrimaryKey() .Properties .Select(x => dtoType.GetProperty(x.Name)) .ToArray(); foreach (ISyncableDto recentlyChangedOfflineDto in recentlyChangedOfflineDtos) { object[] keys = keyProps.Select(p => p.GetValue(recentlyChangedOfflineDto, null)).ToArray(); if (recentlyChangedOfflineDto.IsArchived == true) { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Key(keys).DeleteEntryAsync(); } else if (recentlyChangedOfflineDto.Version == 0) { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Set(recentlyChangedOfflineDto).InsertEntryAsync(); } else { onlineBatchContext += c => toServerSyncConfig.OnlineDtoSet(c).Key(keys).Set(recentlyChangedOfflineDto).UpdateEntryAsync(); } } } await onlineBatchContext.ExecuteAsync(cancellationToken).ConfigureAwait(false); } } }
public async Task ExecuteXCsrfFetchPriorToBatchExecution() { IDictionary <string, object> product1 = null; IDictionary <string, object> product2 = null; // None of the existing sample service endpoints actually provide an xcsrf token, // but in scenarios where a developer may need to use a csrf token, this is an // example of how to acquire one and send it in on subsequent batch requests. var token = ""; var settings = new ODataClientSettings(_serviceUri); settings.BeforeRequest += (request) => { request.Headers.Add("x-csrf-token", "fetch"); }; settings.AfterResponse += (response) => { // Assuming that because the service end points don't return tokens at this time // that we won't be setting the value of the token here. IEnumerable <string> values; token = response.Headers.TryGetValues("x-csrf-token", out values) ? values.First() : "myToken"; }; // Execute an arbitrary request to retrieve the csrf token var client = new ODataClient(settings); await client.GetMetadataDocumentAsync(); // Since the token was never updated it should still be an empty string. Assert.NotNull(token); // Change the settings for the client so we can re-use the session and create a new request with different headers var newHeaders = new Dictionary <string, IEnumerable <string> > { { "x-csrf-token", new List <string> { token } } }; client.UpdateRequestHeaders(newHeaders); var batch = new ODataBatch(client, reuseSession: true); batch += async x => product1 = await x.InsertEntryAsync("Products", CreateProduct(5015, "Test15")); batch += async x => product2 = await x.InsertEntryAsync("Products", CreateProduct(5016, "Test16")); batch += async x => await x.InsertEntryAsync("Categories", CreateCategory(5017, "Test17", new[] { product1, product2 }), false); await batch.ExecuteAsync(); var category = await _client .For("Categories") .Key(5017) .Expand("Products") .FindEntryAsync(); Assert.Equal(2, (category["Products"] as IEnumerable <object>).Count()); }
public async Task DeleteEntryNonExisting() { var batch = new ODataBatch(_serviceUri); batch += c => c.DeleteEntryAsync("Products", new Entry { { "ProductID", 0xFFFF } }); await AssertThrowsAsync <WebRequestException>(async() => await batch.ExecuteAsync()); }
public virtual async Task EnumTest_CSClient() { using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs { })) { TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner"); IODataClient client = testEnvironment.Server.BuildODataClient(token: token); DtoWithEnum dtoWithEnum = await client.Controller <DtoWithEnumController, DtoWithEnum>() .Function(nameof(DtoWithEnumController.GetDtoWithEnumsByGender)) .Set(new { gender = TestGender.Man }) .ExecuteAsSingleAsync(); Assert.AreEqual(TestGender.Man, dtoWithEnum.Gender); Assert.AreEqual(true, await client.Controller <DtoWithEnumController, DtoWithEnum>() .Action(nameof(DtoWithEnumController.PostDtoWithEnum)) .Set(new DtoWithEnumController.PostDtoWithEnumParameters { dto = dtoWithEnum }) .ExecuteAsScalarAsync <bool>()); ODataBatch batchClient = testEnvironment.Server.BuildODataBatchClient(token: token); batchClient += bc => bc.Controller <DtoWithEnumController, DtoWithEnum>() .Function(nameof(DtoWithEnumController.GetDtoWithEnumsByGender2)) .Set(new { gender = TestGender2.Man }) .FindEntriesAsync(); batchClient += bc => bc.Controller <DtoWithEnumController, DtoWithEnum>() .Function(nameof(DtoWithEnumController.GetDtoWithEnumsByGender)) .Set(new { gender = TestGender.Man }) .FindEntriesAsync(); await batchClient.ExecuteAsync(); /*Assert.AreEqual(true, await client.Controller<DtoWithEnumController, DtoWithEnum>() * .Action(nameof(DtoWithEnumController.TestEnumsArray)) * .Set(new DtoWithEnumController.TestEnumsArrayParameters { enums = new[] { TestGender2.Man, TestGender2.Woman } }) * .ExecuteAsScalarAsync<bool>());*/ DtoWithEnumController firstCallController = TestDependencyManager.CurrentTestDependencyManager.Objects .OfType <DtoWithEnumController>() .First(); DtoWithEnumController secondCallController = TestDependencyManager.CurrentTestDependencyManager.Objects .OfType <DtoWithEnumController>() .ElementAt(2); A.CallTo(() => firstCallController.GetDtoWithEnumsByGender(TestGender.Man)) .MustHaveHappenedOnceExactly(); A.CallTo(() => secondCallController.GetDtoWithEnumsByGender2(TestGender2.Man)) .MustHaveHappenedOnceExactly(); } }
public async Task ReadOnlyBatch() { IDictionary<string, object> product = null; var batch = new ODataBatch(_serviceUri); batch += async c => product = await c.FindEntryAsync("Products"); await batch.ExecuteAsync(); Assert.NotNull(product); }
public async Task AsyncWithPartialFailures() { using (var batch = new ODataBatch(_serviceUri)) { var client = new ODataClient(batch); await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false); await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 10m }, { "SupplierID", 0xFFFF } }, false); Assert.Throws<WebRequestException>(() => batch.Complete()); } }
public async Task AsyncWithAllFailures() { using (var batch = new ODataBatch(_serviceUri)) { var client = new ODataClient(batch); await client.InsertEntryAsync("Products", new Entry() { { "UnitPrice", 10m } }, false); await client.InsertEntryAsync("Products", new Entry() { { "UnitPrice", 20m } }, false); Assert.Throws<WebRequestException>(() => batch.Complete()); } }
public async Task Success() { var batch = new ODataBatch(_serviceUri); batch += x => x.InsertEntryAsync("Products", CreateProduct(5001, "Test1"), false); batch += x => x.InsertEntryAsync("Products", CreateProduct(5002, "Test2"), false); await batch.ExecuteAsync(); var product = await _client.FindEntryAsync("Products?$filter=Name eq 'Test1'"); Assert.NotNull(product); product = await _client.FindEntryAsync("Products?$filter=Name eq 'Test2'"); Assert.NotNull(product); }
public async Task Success() { var batch = new ODataBatch(_serviceUri); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m } }, false); await batch.ExecuteAsync(); var product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'"); Assert.NotNull(product); product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'"); Assert.NotNull(product); }
public async Task InsertUpdateDeleteSingleBatch() { var key = new Entry() { { "Name", "Test11" } }; var batch = new ODataBatch(_serviceUri); batch += x => x.InsertEntryAsync("Products", CreateProduct(5011, "Test11"), false); batch += x => x.UpdateEntriesAsync("Products", "Products?$filter=Name eq 'Test11'", new Entry() { { "Price", 22m } }); batch += x => x.DeleteEntriesAsync("Products", "Products?$filter=Name eq 'Test11'"); await batch.ExecuteAsync(); var product = await _client.FindEntryAsync("Products?$filter=Name eq 'Test11'"); Assert.Equal(18d, Convert.ToDouble(product["Price"])); }
public async Task PartialFailures() { var batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Set(new { ProductName = "Test1", UnitPrice = 10m }) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(new { ProductName = "Test2", UnitPrice = 20m, SupplierID = 0xFFFF }) .InsertEntryAsync(false); await AssertThrowsAsync<WebRequestException>(async () => await batch.ExecuteAsync()); }
public async Task PartialFailures() { var x = ODataDynamic.Expression; var batch = new ODataBatch(_serviceUri); batch += c => c .For(x.Products) .Set(x.ProductName = "Test1", x.UnitPrice = 10m) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(x.ProductName = "Test2", x.UnitPrice = 20m, x.SupplierID = 0xFFFF) .InsertEntryAsync(false); await AssertThrowsAsync<WebRequestException>(async () => await batch.ExecuteAsync()); }
public async Task AsyncWithSuccess() { using (var batch = new ODataBatch(_serviceUri)) { var client = new ODataClient(batch); await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false); await client.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m } }, false); batch.Complete(); } var product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'"); Assert.NotNull(product); product = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'"); Assert.NotNull(product); }
public async Task SuccessWithResults() { IDictionary<string, object> product1 = null; IDictionary<string, object> product2 = null; var batch = new ODataBatch(_serviceUri); batch += async x => { product1 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m }}); }; batch += async x => { product2 = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 20m }}); }; await batch.ExecuteAsync(); Assert.NotNull(product1["ProductID"]); Assert.NotNull(product2["ProductID"]); product1 = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test1'"); Assert.NotNull(product1); product2 = await _client.FindEntryAsync("Products?$filter=ProductName eq 'Test2'"); Assert.NotNull(product2); }
public async Task PartialFailures() { var batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Set(new { ProductName = "Test1", UnitPrice = 10m }) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(new { ProductName = "Test2", UnitPrice = 20m, SupplierID = 0xFFFF }) .InsertEntryAsync(false); try { await batch.ExecuteAsync(); } catch (WebRequestException exception) { Assert.NotNull(exception.Response); } }
public async Task MultipleUpdatesSingleBatch() { Product product = null; Product product1 = null; Product product2 = null; var batch = new ODataBatch(_serviceUri); batch += async c => product = await c .For<Product>() .Set(new { ProductName = "Test11", UnitPrice = 21m }) .InsertEntryAsync(false); await batch.ExecuteAsync(); batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Key(product.ProductID) .Set(new { UnitPrice = 22m }) .UpdateEntryAsync(false); batch += async c => product1 = await c .For<Product>() .Filter(x => x.ProductName == "Test11") .FindEntryAsync(); batch += c => c .For<Product>() .Key(product.ProductID) .Set(new { UnitPrice = 23m }) .UpdateEntryAsync(false); batch += async c => product2 = await c .For<Product>() .Filter(x => x.ProductName == "Test11") .FindEntryAsync(); await batch.ExecuteAsync(); Assert.Equal(22m, product1.UnitPrice); Assert.Equal(23m, product2.UnitPrice); product = await _client .For<Product>() .Filter(x => x.ProductName == "Test11") .FindEntryAsync(); Assert.Equal(23m, product.UnitPrice); }
public async Task AllFailures() { var batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Set(new { UnitPrice = 10m }) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(new { UnitPrice = 20m }) .InsertEntryAsync(false); await AssertThrowsAsync<WebRequestException>(async () => await batch.ExecuteAsync()); }
public async Task Count() { var batch = new ODataBatch(_serviceUri); int count = 0; batch += async c => count = await c .For("Products") .Count() .FindScalarAsync<int>(); await batch.ExecuteAsync(); Assert.Equal(77, count); }
public async Task InsertSingleEntityWithMultipleAssociationsSingleBatch() { var product1 = new Product() {ProductName = "Test15", UnitPrice = 21m}; var product2 = new Product() {ProductName = "Test16", UnitPrice = 22m}; var batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Set(product1) .InsertEntryAsync(false); batch += c => c .For<Product>() .Set(product2) .InsertEntryAsync(false); batch += async c => await c .For<Category>() .Set(new { CategoryName = "Test17", Products = new[] { product1, product2 } }) .InsertEntryAsync(false); await batch.ExecuteAsync(); var category = await _client .For<Category>() .Expand(x => x.Products) .Filter(x => x.CategoryName == "Test17") .FindEntryAsync(); Assert.Equal(2, category.Products.Count()); }
public async Task InsertSingleEntityWithSingleAssociationSingleBatch() { var category = new Category() { CategoryName = "Test13" }; var batch = new ODataBatch(_serviceUri); batch += async c => await c .For<Category>() .Set(category) .InsertEntryAsync(); batch += c => c .For<Product>() .Set(new { ProductName = "Test14", UnitPrice = 21m, Category = category }) .InsertEntryAsync(); await batch.ExecuteAsync(); var product = await _client .For<Product>() .Expand(x => x.Category) .Filter(x => x.ProductName == "Test14") .FindEntryAsync(); Assert.Equal("Test13", product.Category.CategoryName); }
public async Task InsertUpdateDeleteSeparateBatches() { var batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Set(new { ProductName = "Test12", UnitPrice = 21m }) .InsertEntryAsync(false); await batch.ExecuteAsync(); var product = await _client .For<Product>() .Filter(x => x.ProductName == "Test12") .FindEntryAsync(); Assert.Equal(21m, product.UnitPrice); var productID = product.ProductID; batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Key(productID) .Set(new { UnitPrice = 22m }) .UpdateEntryAsync(false); await batch.ExecuteAsync(); product = await _client .For<Product>() .Filter(x => x.ProductName == "Test12") .FindEntryAsync(); Assert.Equal(22m, product.UnitPrice); batch = new ODataBatch(_serviceUri); batch += c => c .For<Product>() .Key(productID) .DeleteEntryAsync(); await batch.ExecuteAsync(); product = await _client .For<Product>() .Filter(x => x.ProductName == "Test12") .FindEntryAsync(); Assert.Null(product); }
public async Task Batch() { IEnumerable<Airline> airlines1 = null; IEnumerable<Airline> airlines2 = null; var batch = new ODataBatch(_client); batch += async c => airlines1 = await c .For<Airline>() .FindEntriesAsync(); batch += c => c .For<Airline>() .Set(new Airline() { AirlineCode = "TT", Name = "Test Airline" }) .InsertEntryAsync(false); batch += async c => airlines2 = await c .For<Airline>() .FindEntriesAsync(); await batch.ExecuteAsync(); Assert.Equal(8, airlines1.Count()); Assert.Equal(8, airlines2.Count()); }
public async Task GetInvolvedPeopleInBatch() { var batch = new ODataBatch(_client); IEnumerable<object> people = null; batch += async x => { people = await x.For<Person>() .Key("scottketchum") .NavigateTo<Trip>() .Key(0) .Function("GetInvolvedPeople") .ExecuteAsEnumerableAsync(); }; await batch.ExecuteAsync(); Assert.Equal(2, people.Count()); }
public async Task ShareTripInBatch() { var batch = new ODataBatch(_client); batch += async x => await x .For<Person>() .Key("russellwhyte") .Action("ShareTrip") .Set(new { userName = "******", tripId = 1003 }) .ExecuteAsSingleAsync(); await batch.ExecuteAsync(); }
public async Task PartialFailures() { var batch = new ODataBatch(_serviceUri); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test1" }, { "UnitPrice", 10m } }, false); batch += c => c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test2" }, { "UnitPrice", 10m }, { "SupplierID", 0xFFFF } }, false); try { await batch.ExecuteAsync(); } catch (WebRequestException exception) { Assert.NotNull(exception.Response); } }
public async Task Function() { var batch = new ODataBatch(_serviceUri); int result = 0; batch += async c => result = await c.Unbound().Function("ParseInt").Set(new Entry() { { "number", "1" } }).ExecuteAsScalarAsync<int>(); await batch.ExecuteAsync(); Assert.Equal(1, result); }
public async Task DeleteEntriesNonExistingThenInsert() { IDictionary<string, object> product = null; var batch = new ODataBatch(_serviceUri); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=ProductName eq 'Test99'"); batch += async c => product = await c.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test15" }, { "UnitPrice", 21m } }); batch += c => c.InsertEntryAsync("Categories", new Entry() { { "CategoryName", "Test17" }, { "Products", new[] { product } } }, false); await batch.ExecuteAsync(); }
public async Task DeleteEntriesNonExisting() { var batch = new ODataBatch(_serviceUri); batch += c => c.DeleteEntriesAsync("Products", "Products?$filter=ProductName eq 'Test99'"); await batch.ExecuteAsync(); }
public async Task UpdateWithResultRequired() { IDictionary<string, object> product = null; IDictionary<string, object> product1 = null; var batch = new ODataBatch(_serviceUri); batch += async x => product = await x.InsertEntryAsync("Products", new Entry() { { "ProductName", "Test11" }, { "UnitPrice", 21m } }, true); await batch.ExecuteAsync(); batch = new ODataBatch(_serviceUri); batch += async c => product1 = await c.UpdateEntryAsync("Products", product, new Entry() { { "UnitPrice", 22m } }, true); await batch.ExecuteAsync(); Assert.Equal(22m, product1["UnitPrice"]); }
public async Task LinkEntry() { var category = await _client .For("Categories") .Set(new { CategoryName = "Test4" }) .InsertEntryAsync(); var product = await _client .For("Products") .Set(new { ProductName = "Test5" }) .InsertEntryAsync(); var batch = new ODataBatch(_serviceUri); batch += async c => await c .For("Products") .Key(product) .LinkEntryAsync("Category", category); await batch.ExecuteAsync(); product = await _client .For("Products") .Filter("ProductName eq 'Test5'") .FindEntryAsync(); Assert.NotNull(product["CategoryID"]); Assert.Equal(category["CategoryID"], product["CategoryID"]); }