public void TestQueryEvents() { QueryCompletedResult result = null; object userState = this; WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; dc.BeginQuery( new EntityQuery <Product>(dc, "GetProducts", null, true, false), delegate(IAsyncResult asyncResult) { result = dc.EndQuery(asyncResult); }, userState ); EnqueueConditional(delegate { return(result != null); }); EnqueueCallback(delegate { Assert.AreEqual(504, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }
/// <summary> /// Performs one time initialization of the ChannelFactory /// </summary> private static void InitializeChannelFactory <TContract>(WebDomainClient <TContract> domainClient, ChannelFactory <TContract> channelFactory) where TContract : class { var originalSyncContext = SynchronizationContext.Current; try { foreach (OperationDescription op in channelFactory.Endpoint.Contract.Operations) { foreach (Type knownType in domainClient.KnownTypes) { op.KnownTypes.Add(knownType); } } SynchronizationContext.SetSynchronizationContext(null); channelFactory.Open(); } catch { ((IDisposable)channelFactory)?.Dispose(); throw; } finally { SynchronizationContext.SetSynchronizationContext(originalSyncContext); } }
public void TestMethodQueryMismatch() { WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.EF_Catalog) { EntityTypes = new Type[] { typeof(Product), typeof(PurchaseOrder), typeof(PurchaseOrderDetail) } }; QueryCompletedResult queryResults = null; var query = new EntityQuery <PurchaseOrder>(new EntityQuery <Product>(dc, "GetProducts", null, true, false), new PurchaseOrder[0].AsQueryable().Take(2)); query.IncludeTotalCount = true; dc.BeginQuery( query, delegate(IAsyncResult asyncResult) { queryResults = dc.EndQuery(asyncResult); }, null ); EnqueueConditional(() => queryResults != null); EnqueueCallback(delegate { Assert.AreEqual(2, queryResults.Entities.Concat(queryResults.IncludedEntities).Count()); Assert.AreEqual(504, queryResults.TotalCount); }); EnqueueTestComplete(); }
public void TestQuery() { WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; var query = from p in Array.Empty <Product>().AsQueryable() where p.Weight < 10.5M orderby p.Weight select p; var entityQuery = new EntityQuery <Product>(new EntityQuery <Product>(dc, "GetProducts", null, true, false), query); entityQuery.IncludeTotalCount = true; var queryTask = dc.QueryAsync(entityQuery, CancellationToken.None); EnqueueConditional(delegate { return(queryTask.IsCompleted); }); EnqueueCallback(delegate { var result = queryTask.Result; Assert.AreEqual(79, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }
public void AbsoluteServiceUri() { Uri uri = new Uri(@"http://mock.domain/ignored/"); WebDomainClient <CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient <CityDomainContext.ICityDomainServiceContract>(uri, /* usesHttp */ false); Assert.AreEqual(uri, client.ServiceUri, "Absoluted Uri should be the same as passed into the constructor."); }
public void UsesHttps() { #if SILVERLIGHT WebDomainClient <CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient <CityDomainContext.ICityDomainServiceContract>(new Uri("ignored/", UriKind.Relative)); Assert.AreEqual("http", client.ServiceUri.Scheme, "By default, Uri scheme should be HTTP."); client = new WebDomainClient <CityDomainContext.ICityDomainServiceContract>(new Uri("ignored/", UriKind.Relative), true); Assert.AreEqual("https", client.ServiceUri.Scheme, "Uri scheme should be HTTPS."); #endif }
public async Task TestQueryEvents() { WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; var result = await dc.QueryAsync(new EntityQuery <Product>(dc, "GetProducts", null, true, false), CancellationToken.None); Assert.AreEqual(504, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }
public void RelativeServiceUri() { #if SILVERLIGHT Uri relativeUri = new Uri("relative/", UriKind.Relative); WebDomainClient <CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient <CityDomainContext.ICityDomainServiceContract>(relativeUri); Assert.AreNotEqual(relativeUri, client.ServiceUri, "Relative Uri should not equal the absolute service uri."); Assert.IsTrue(client.ServiceUri.AbsoluteUri.Contains(@"http://"), "Absolute Uri should use HTTP scheme."); Assert.IsTrue(client.ServiceUri.AbsoluteUri.Contains(relativeUri.OriginalString), "Absolute Uri should contain the full path of the relative Uri."); client = new WebDomainClient <CityDomainContext.ICityDomainServiceContract>(relativeUri, true); Assert.AreNotEqual(relativeUri, client.ServiceUri, "Relative Uri should not equal the absolute service Uri."); Assert.IsTrue(client.ServiceUri.AbsoluteUri.Contains(@"https://"), "Absolute Uri should use HTTPS scheme."); Assert.IsTrue(client.ServiceUri.AbsoluteUri.Contains(relativeUri.OriginalString), "Absolute Uri should contain the full path of the relative Uri."); #endif }
public void TestQuery() { QueryCompletedResult result = null; object userState = this; WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; var query = from p in new Product[0].AsQueryable() where p.Weight < 10.5M orderby p.Weight select p; var entityQuery = new EntityQuery <Product>(new EntityQuery <Product>(dc, "GetProducts", null, true, false), query); entityQuery.IncludeTotalCount = true; dc.BeginQuery( entityQuery, delegate(IAsyncResult asyncResult) { result = dc.EndQuery(asyncResult); }, userState ); EnqueueConditional(delegate { return(result != null); }); EnqueueCallback(delegate { Assert.AreEqual(79, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }
public void TestQueryEvents() { WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; var queryTask = dc.QueryAsync(new EntityQuery <Product>(dc, "GetProducts", null, true, false), CancellationToken.None); EnqueueConditional(delegate { return(queryTask.IsCompleted); }); EnqueueCallback(delegate { var result = queryTask.Result; Assert.AreEqual(504, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }
public void TestMethodQueryMismatch() { WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.EF_Catalog) { EntityTypes = new Type[] { typeof(Product), typeof(PurchaseOrder), typeof(PurchaseOrderDetail) } }; var query = new EntityQuery <PurchaseOrder>(new EntityQuery <Product>(dc, "GetProducts", null, true, false), Array.Empty <PurchaseOrder>().AsQueryable().Take(2)); query.IncludeTotalCount = true; var queryTask = dc.QueryAsync(query, CancellationToken.None); EnqueueConditional(() => queryTask.IsCompleted); EnqueueCallback(delegate { var queryResults = queryTask.Result; Assert.AreEqual(2, queryResults.Entities.Concat(queryResults.IncludedEntities).Count()); Assert.AreEqual(504, queryResults.TotalCount); }); EnqueueTestComplete(); }
public void TestQueryEvents() { QueryCompletedResult result = null; object userState = this; WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; dc.BeginQuery( new EntityQuery<Product>(dc, "GetProducts", null, true, false), delegate(IAsyncResult asyncResult) { result = dc.EndQuery(asyncResult); }, userState ); EnqueueConditional(delegate { return result != null; }); EnqueueCallback(delegate { Assert.AreEqual(504, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }
public void DomainClient_SubmitWithNonexistentDomainMethod() { TestEntityContainer container = new TestEntityContainer(); WebDomainClient<CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities) { EntityTypes = new Type[] { typeof(City) } }; List<Entity> emptyList = new List<Entity>(); List<Entity> modifiedEntities = new List<Entity>(); // invoke domain methods on a few entities container.LoadEntities(_cities); _cities[0].CustomMethodInvocation = _reject; // submit changeset with hand-crafted entities (without calling Invoke) modifiedEntities.Add(_cities[0]); EntityChangeSet changeset = new EntityChangeSet(emptyList.AsReadOnly(), modifiedEntities.AsReadOnly(), emptyList.AsReadOnly()); SubmitCompletedResult submitResults = null; DomainOperationException expectedException = null; EnqueueCallback(delegate { client.BeginSubmit( changeset, delegate(IAsyncResult asyncResult) { try { submitResults = client.EndSubmit(asyncResult); } catch (DomainOperationException e) { expectedException = e; } }, null ); }); EnqueueConditional(() => expectedException != null); EnqueueCallback(delegate { Assert.IsNull(submitResults); Assert.AreEqual("This DomainService does not support operation 'Reject' for entity 'CityWithInfo'.", expectedException.Message); }); EnqueueTestComplete(); }
public void DomainClient_SubmitWithNullInvocation() { TestEntityContainer container = new TestEntityContainer(); //TODO: find a better way to not hardcode the list of known types WebDomainClient<CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities) { EntityTypes = new Type[] { typeof(City), typeof(ChangeSetEntry), typeof(EntityOperationType) } }; List<Entity> emptyList = new List<Entity>(); List<Entity> modifiedEntities = new List<Entity>(); // invoke domain methods on a few entities container.LoadEntities(_cities); _cities[1].AssignCityZone(_assignCityZone.Parameters.First().ToString()); // submit changeset with hand-crafted entities: valid invocation and null invocation modifiedEntities.Add(_cities[0]); modifiedEntities.Add(_cities[1]); modifiedEntities.Add(_cities[2]); Assert.AreEqual(EntityState.Modified, _cities[1].EntityState); EntityChangeSet changeset = new EntityChangeSet(emptyList.AsReadOnly(), modifiedEntities.AsReadOnly(), emptyList.AsReadOnly()); SubmitCompletedResult submitResults = null; client.BeginSubmit( changeset, delegate(IAsyncResult asyncResult) { submitResults = client.EndSubmit(asyncResult); }, null ); // wait for submit to complete EnqueueConditional(() => submitResults != null); EnqueueCallback(delegate { Assert.AreEqual(1, submitResults.Results.Count()); Assert.AreEqual(1, submitResults.Results.Where(e => e.Operation == EntityOperationType.Update).Count()); // REVIEW: Do we really need the operation data back from the server? // ChangeSetEntry returned = submitResults.Results.Single(e => e.OperationName == _assignCityZone.Name); // Assert.IsNotNull(returned); // Assert.AreEqual(1, returned.OperationData.Count()); }); EnqueueTestComplete(); }
public void DomainClient_SubmitWithInvalidInvocation() { TestEntityContainer container = new TestEntityContainer(); WebDomainClient<CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities) { EntityTypes = new Type[] { typeof(City) } }; List<Entity> emptyList = new List<Entity>(); List<Entity> modifiedEntities = new List<Entity>(); // verify exception is thrown when trying to invoke invalid action ExceptionHelper.ExpectArgumentException(delegate { _cities[0].InvokeAction(""); }, string.Format(CultureInfo.CurrentCulture, Resource.Parameter_NullOrEmpty,"actionName")); }
public void TestMethodQueryMismatch() { WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.EF_Catalog) { EntityTypes = new Type[] { typeof(Product), typeof(PurchaseOrder), typeof(PurchaseOrderDetail) } }; QueryCompletedResult queryResults = null; var query = new EntityQuery<PurchaseOrder>(new EntityQuery<Product>(dc, "GetProducts", null, true, false), new PurchaseOrder[0].AsQueryable().Take(2)); query.IncludeTotalCount = true; dc.BeginQuery( query, delegate(IAsyncResult asyncResult) { queryResults = dc.EndQuery(asyncResult); }, null ); EnqueueConditional(() => queryResults != null); EnqueueCallback(delegate { Assert.AreEqual(2, queryResults.Entities.Concat(queryResults.IncludedEntities).Count()); Assert.AreEqual(504, queryResults.TotalCount); }); EnqueueTestComplete(); }
/// <summary> /// Creates a channel factory for use by a DomainClient to communicate with the server. /// </summary> /// <remarks> /// This is not used if a ChannelFactory was passed to the ctor of the <see cref="WebDomainClient{TContract}"/> /// </remarks> /// <param name="endpoint">Absolute service URI without protocol suffix such as "/binary"</param> /// <param name="requiresSecureEndpoint"><c>true</c> if communication must be secured, otherwise <c>false</c></param> /// <param name="domainClient">the domainclient which request the channel factory</param> /// <returns>The channel used to communicate with the server.</returns> internal ChannelFactory <TContract> CreateChannelFactory <TContract>(Uri endpoint, bool requiresSecureEndpoint, WebDomainClient <TContract> domainClient) where TContract : class { ChannelFactory <TContract> channelFactory; ChannelFactoryKey key = new ChannelFactoryKey(typeof(TContract), endpoint, requiresSecureEndpoint); lock (_channelFactoryCacheLock) { if (_channelFactoryCache.TryGetValue(key, out var existingFactory) // This should never happen, but check anyway just to be safe && existingFactory.State != CommunicationState.Faulted) { channelFactory = (ChannelFactory <TContract>)existingFactory; } else { // Create and initialize a new channel factory channelFactory = CreateChannelFactory <TContract>(endpoint, requiresSecureEndpoint); InitializeChannelFactory(domainClient, channelFactory); _channelFactoryCache[key] = channelFactory; } } return(channelFactory); }
public void TestQuery() { QueryCompletedResult result = null; object userState = this; WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract> dc = new WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog) { EntityTypes = new Type[] { typeof(Product) } }; var query = from p in new Product[0].AsQueryable() where p.Weight < 10.5M orderby p.Weight select p; var entityQuery = new EntityQuery<Product>(new EntityQuery<Product>(dc, "GetProducts", null, true, false), query); entityQuery.IncludeTotalCount = true; dc.BeginQuery( entityQuery, delegate(IAsyncResult asyncResult) { result = dc.EndQuery(asyncResult); }, userState ); EnqueueConditional(delegate { return result != null; }); EnqueueCallback(delegate { Assert.AreEqual(79, result.Entities.Concat(result.IncludedEntities).Count()); Assert.AreEqual(result.Entities.Count(), result.TotalCount); }); EnqueueTestComplete(); }