private void HandleResponse(LoadResult loadResult) { RequiresRetry = _loadOperation.SetResult(loadResult); if (RequiresRetry == false) { Result = _loadOperation.Complete <T>(); } }
public Task <T> LoadAsync <T>(string id) { object existingEntity; if (entitiesByKey.TryGetValue(id, out existingEntity)) { return(CompletedTask.With((T)existingEntity)); } IncrementRequestCount(); var shardRequestData = new ShardRequestData { EntityType = typeof(T), Keys = { id } }; var dbCommands = GetCommandsToOperateOn(shardRequestData); var results = shardStrategy.ShardAccessStrategy.ApplyAsync(dbCommands, shardRequestData, (commands, i) => { var loadOperation = new LoadOperation(this, commands.DisableAllCaching, id); Func <Task> executer = null; executer = () => { loadOperation.LogOperation(); var loadContext = loadOperation.EnterLoadContext(); return(commands.GetAsync(id).ContinueWith(task => { if (loadContext != null) { loadContext.Dispose(); } if (loadOperation.SetResult(task.Result)) { return executer(); } return new CompletedTask(); }).Unwrap()); }; return(executer().ContinueWith(_ => { _.AssertNotFailed(); return loadOperation.Complete <T>(); })); }); return(results.ContinueWith(task => { var shardsContainThisDocument = task.Result.Where(x => !Equals(x, default(T))).ToArray(); if (shardsContainThisDocument.Count() > 1) { throw new InvalidOperationException("Found document with id: " + id + " on more than a single shard, which is not allowed. Document keys have to be unique cluster-wide."); } return shardsContainThisDocument.FirstOrDefault(); })); }
/// <summary> /// Begins the async load operation /// </summary> public async Task <T[]> LoadAsyncInternal <T>(string[] ids, CancellationToken token = default(CancellationToken)) { if (ids.Length == 0) { return(new T[0]); } // only load documents that aren't already cached var idsOfNotExistingObjects = ids.Where(id => IsLoaded(id) == false && IsDeleted(id) == false) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); if (idsOfNotExistingObjects.Length > 0) { IncrementRequestCount(); var loadOperation = new LoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, idsOfNotExistingObjects, null); LoadResult loadResult; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { loadResult = await AsyncDatabaseCommands.GetAsync(idsOfNotExistingObjects, null).ConfigureAwait(false); } } while (loadOperation.SetResult(loadResult)); loadOperation.Complete <T>(); } var loadTasks = ids.Select(async id => await LoadAsync <T>(id, token).ConfigureAwait(false)).ToArray(); var loadedData = await Task.WhenAll(loadTasks).WithCancellation(token).ConfigureAwait(false); return(loadedData); }
/// <summary> /// Begins the async load operation /// </summary> public async Task <T[]> LoadAsyncInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, CancellationToken token = default(CancellationToken)) { if (CheckIfIdAlreadyIncluded(ids, includes)) { var loadTasks = ids.Select(id => LoadAsync <T>(id, token)).ToArray(); var loadedData = await Task.WhenAll(loadTasks).WithCancellation(token).ConfigureAwait(false); return(loadedData); } IncrementRequestCount(); var loadOperation = new LoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes); loadOperation.LogOperation(); var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null; LoadResult result; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { result = await AsyncDatabaseCommands.GetAsync(ids, includePaths, token : token).ConfigureAwait(false); } } while (loadOperation.SetResult(result)); return(loadOperation.Complete <T>()); }
public T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes) { if (ids.Length == 0) { return(new T[0]); } if (CheckIfIdAlreadyIncluded(ids, includes)) { return(ids.Select(Load <T>).ToArray()); } var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null; IncrementRequestCount(); var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, ids, includes); LoadResult loadResult; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { loadResult = DatabaseCommands.Get(ids, includePaths); } } while (loadOperation.SetResult(loadResult)); return(loadOperation.Complete <T>()); }
public T[] LoadInternal <T>(string[] ids) { if (ids.Length == 0) { return(new T[0]); } // only load documents that aren't already cached var idsOfNotExistingObjects = ids.Where(id => IsLoaded(id) == false && IsDeleted(id) == false) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); if (idsOfNotExistingObjects.Length > 0) { IncrementRequestCount(); var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, idsOfNotExistingObjects, null); LoadResult loadResult; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { loadResult = DatabaseCommands.Get(idsOfNotExistingObjects, null); } } while (loadOperation.SetResult(loadResult)); loadOperation.Complete <T>(); } return(ids.Select(Load <T>).ToArray()); }
/// <summary> /// Loads the specified entity with the specified id. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <returns></returns> public T Load <T>(string id) { if (id == null) { throw new ArgumentNullException("id", "The document id cannot be null"); } object existingEntity; if (entitiesByKey.TryGetValue(id, out existingEntity)) { return((T)existingEntity); } IncrementRequestCount(); var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, id); bool retry; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { retry = loadOperation.SetResult(DatabaseCommands.Get(id)); } } while (retry); return(loadOperation.Complete <T>()); }
private void HandleResponse(JsonDocument jsonDocument) { RequiresRetry = loadOperation.SetResult(jsonDocument); if (RequiresRetry == false) { Result = loadOperation.Complete <T>(); } }
public void UnhandledLoadOperationError() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery <Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, false); DomainOperationException expectedException = null; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); try { lo.Complete(ex); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.AreSame(ex, expectedException); // TODO: Add separate test with mock DomainClient which throws a specific exception // and move the following checks there /* * Assert.IsNotNull(expectedException); * Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "ThrowGeneralException", ex.Message), expectedException.Message); * Assert.AreEqual(ex.StackTrace, expectedException.StackTrace); * Assert.AreEqual(ex.Status, expectedException.Status); * Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode); */ Assert.AreEqual(false, lo.IsErrorHandled); // now test again with validation errors expectedException = null; ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) }; lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, false); ex = new DomainOperationException("expected", validationErrors); try { lo.Complete(ex); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.AreSame(expectedException, ex);; CollectionAssert.AreEqual(validationErrors, lo.ValidationErrors.ToList()); }
public T Load <T>(string id) { if (IsDeleted(id)) { return(default(T)); } object existingEntity; if (entitiesByKey.TryGetValue(id, out existingEntity)) { return((T)existingEntity); } JsonDocument value; if (includedDocumentsByKey.TryGetValue(id, out value)) { includedDocumentsByKey.Remove(id); return(TrackEntity <T>(value)); } IncrementRequestCount(); var shardRequestData = new ShardRequestData { EntityType = typeof(T), Keys = { id } }; var dbCommands = GetCommandsToOperateOn(shardRequestData); var results = shardStrategy.ShardAccessStrategy.Apply(dbCommands, shardRequestData, (commands, i) => { var loadOperation = new LoadOperation(this, commands.DisableAllCaching, id); bool retry; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { retry = loadOperation.SetResult(commands.Get(id)); } } while (retry); return(loadOperation.Complete <T>()); }); var shardsContainThisDocument = results.Where(x => !Equals(x, default(T))).ToArray(); if (shardsContainThisDocument.Count() > 1) { throw new InvalidOperationException("Found document with id: " + id + " on more than a single shard, which is not allowed. Document keys have to be unique cluster-wide."); } return(shardsContainThisDocument.FirstOrDefault()); }
public void HandleResponses(GetResponse[] responses, ShardStrategy shardStrategy) { var list = new List <LoadResult>( from response in responses let result = response.Result select new LoadResult { Includes = result.Value <RavenJArray>("Includes").Cast <RavenJObject>().ToList(), Results = result.Value <RavenJArray>("Results").Select(x => x as RavenJObject).ToList() }); var capacity = list.Max(x => x.Results.Count); var finalResult = new LoadResult { Includes = new List <RavenJObject>(), Results = new List <RavenJObject>(Enumerable.Range(0, capacity).Select(x => (RavenJObject)null)) }; foreach (var multiLoadResult in list) { finalResult.Includes.AddRange(multiLoadResult.Includes); for (int i = 0; i < multiLoadResult.Results.Count; i++) { if (finalResult.Results[i] == null) { finalResult.Results[i] = multiLoadResult.Results[i]; } } } RequiresRetry = loadOperation.SetResult(finalResult); if (RequiresRetry == false) { Result = loadOperation.Complete <T>(); } }
private async Task <T> CompleteLoadAsync <T>(string id, LoadOperation loadOperation, CancellationToken token = default(CancellationToken)) { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { var result = await AsyncDatabaseCommands.GetAsync(id, token); if (loadOperation.SetResult(result) == false) { return(loadOperation.Complete <T>()); } return(await CompleteLoadAsync <T>(id, loadOperation, token).WithCancellation(token)); } }
public void UnhandledLoadOperationError() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery <Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); DomainOperationException expectedException = null; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); try { lo.Complete(ex); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "ThrowGeneralException", ex.Message), expectedException.Message); Assert.AreEqual(ex.StackTrace, expectedException.StackTrace); Assert.AreEqual(ex.Status, expectedException.Status); Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode); Assert.AreEqual(false, lo.IsErrorHandled); // now test again with validation errors expectedException = null; ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) }; lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); try { lo.Complete(validationErrors); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed_Validation, "ThrowGeneralException"), expectedException.Message); }
private Task <T> CompleteLoadAsync <T>(string id, LoadOperation loadOperation) { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { return(AsyncDatabaseCommands.GetAsync(id) .ContinueWith(task => { if (loadOperation.SetResult(task.Result) == false) { return Task.Factory.StartNew(() => loadOperation.Complete <T>()); } return CompleteLoadAsync <T>(id, loadOperation); }) .Unwrap()); } }
/// <summary> /// Loads the specified entity with the specified id. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <returns></returns> public T Load <T>(string id) { if (id == null) { throw new ArgumentNullException("id", "The document id cannot be null"); } if (IsDeleted(id)) { return(default(T)); } object existingEntity; if (EntitiesById.TryGetValue(id, out existingEntity)) { return((T)existingEntity); } JsonDocument value; if (includedDocumentsByKey.TryGetValue(id, out value)) { includedDocumentsByKey.Remove(id); return(TrackEntity <T>(value)); } IncrementRequestCount(); var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, id); bool retry; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { retry = loadOperation.SetResult(DatabaseCommands.Get(id)); } } while (retry); return(loadOperation.Complete <T>().FirstOrDefault()); }
public void HandleResponse(GetResponse response) { if (response.Status == 404) { Result = null; RequiresRetry = false; return; } var headers = new NameValueCollection(); foreach (var header in response.Headers) { headers[header.Key] = header.Value; } var jsonDocument = SerializationHelper.DeserializeJsonDocument(key, response.Result, headers, (HttpStatusCode)response.Status); RequiresRetry = loadOperation.SetResult(jsonDocument); if (RequiresRetry == false) { Result = loadOperation.Complete <T>(); } }
/// <summary> /// Loads the specified entity with the specified id. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <returns></returns> public T Load <T>(string id) { object existingEntity; if (entitiesByKey.TryGetValue(id, out existingEntity)) { return((T)existingEntity); } IncrementRequestCount(); var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, id); bool retry; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { retry = loadOperation.SetResult(DatabaseCommands.Get(id)); } } while (retry); return(loadOperation.Complete <T>()); }
public static async Task <T[]> MoreLikeThisAsync <T>(this IAsyncAdvancedSessionOperations advancedSession, string index, string transformer, MoreLikeThisQuery parameters) { if (string.IsNullOrEmpty(index)) { throw new ArgumentException("Index name cannot be null or empty", "index"); } parameters.IndexName = index; parameters.Transformer = transformer; // /morelikethis/(index-name)/(ravendb-document-id)?fields=(fields) var cmd = ((AsyncDocumentSession)advancedSession).AsyncDatabaseCommands; var inMemoryDocumentSessionOperations = ((InMemoryDocumentSessionOperations)advancedSession); inMemoryDocumentSessionOperations.IncrementRequestCount(); var loadOperation = new LoadOperation(inMemoryDocumentSessionOperations, cmd.DisableAllCaching, null, null); LoadResult loadResult; do { loadOperation.LogOperation(); using (loadOperation.EnterLoadContext()) { var result = await cmd.MoreLikeThisAsync(parameters).ConfigureAwait(false); loadResult = new LoadResult { Includes = result.Includes, Results = result.Results }; } } while (loadOperation.SetResult(loadResult)); return(loadOperation.Complete <T>()); }
public void Operation_MarkAsHandled() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery <Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); EventHandler action = (o, e) => { LoadOperation loadOperation = (LoadOperation)o; if (loadOperation.HasError) { loadOperation.MarkErrorAsHandled(); } }; lo.Completed += action; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); lo.Complete(ex); // verify that calling MarkAsHandled again is a noop lo.MarkErrorAsHandled(); lo.MarkErrorAsHandled(); // verify that calling MarkAsHandled on an operation not in error // results in an exception lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); Assert.IsFalse(lo.HasError); Assert.IsTrue(lo.IsErrorHandled); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.MarkErrorAsHandled(); }, Resource.Operation_HasErrorMustBeTrue); }
public void Operation_MarkAsHandled() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null); EventHandler action = (o, e) => { LoadOperation loadOperation = (LoadOperation)o; if (loadOperation.HasError) { loadOperation.MarkErrorAsHandled(); } }; lo.Completed += action; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); lo.Complete(ex); // verify that calling MarkAsHandled again is a noop lo.MarkErrorAsHandled(); lo.MarkErrorAsHandled(); // verify that calling MarkAsHandled on an operation not in error // results in an exception lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null); Assert.IsFalse(lo.HasError); Assert.IsTrue(lo.IsErrorHandled); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.MarkErrorAsHandled(); }, Resource.Operation_HasErrorMustBeTrue); }
public void Exceptions() { Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities); Action <LoadOperation <City> > loCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action <SubmitOperation> soCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action <InvokeOperation> ioCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; var query = cities.GetCitiesQuery(); var loadBehaviour = LoadBehavior.MergeIntoCurrent; LoadOperation <City> lo = new LoadOperation <City>(query, loadBehaviour, loCallback, null, false); // verify completion callbacks that throw ExceptionHelper.ExpectInvalidOperationException(delegate { try { lo.Complete(new LoadResult <City>(query, loadBehaviour, Array.Empty <City>(), Array.Empty <Entity>(), 0)); } catch (Exception ex) { Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved."); throw; } }, "Fnord!"); // verify cancellation callbacks for all fx operation types lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, true); lo.CancellationToken.Register(() => throw new InvalidOperationException("Fnord!")); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.Cancel(); }, "Fnord!"); SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { so.Cancel(); }, "Fnord!"); InvokeOperation io = new InvokeOperation("Fnord", null, null, null, true); io.CancellationToken.Register(() => throw new InvalidOperationException("Fnord!")); ExceptionHelper.ExpectInvalidOperationException(delegate { io.Cancel(); }, "Fnord!"); }
public void Exceptions() { Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities); Action<LoadOperation<City>> loCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action<SubmitOperation> soCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action<InvokeOperation> ioCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; LoadOperation lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, loCallback, null, loCallback); // verify completion callbacks that throw ExceptionHelper.ExpectInvalidOperationException(delegate { try { lo.Complete(DomainClientResult.CreateQueryResult(new Entity[0], new Entity[0], 0, new ValidationResult[0])); } catch (Exception ex) { Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved."); throw; } }, "Fnord!"); // verify cancellation callbacks for all fx operation types lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, loCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.Cancel(); }, "Fnord!"); SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { so.Cancel(); }, "Fnord!"); InvokeOperation io = new InvokeOperation("Fnord", null, null, null, ioCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { io.Cancel(); }, "Fnord!"); }
public void Exceptions() { Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities); Action <LoadOperation <City> > loCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action <SubmitOperation> soCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; Action <InvokeOperation> ioCallback = (op) => { if (op.HasError) { op.MarkErrorAsHandled(); } throw new InvalidOperationException("Fnord!"); }; LoadOperation lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, loCallback, null, loCallback); // verify completion callbacks that throw ExceptionHelper.ExpectInvalidOperationException(delegate { try { lo.Complete(DomainClientResult.CreateQueryResult(new Entity[0], new Entity[0], 0, new ValidationResult[0])); } catch (Exception ex) { Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved."); throw; } }, "Fnord!"); // verify cancellation callbacks for all fx operation types lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, loCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.Cancel(); }, "Fnord!"); SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { so.Cancel(); }, "Fnord!"); InvokeOperation io = new InvokeOperation("Fnord", null, null, null, ioCallback); ExceptionHelper.ExpectInvalidOperationException(delegate { io.Cancel(); }, "Fnord!"); }
public void UnhandledLoadOperationError() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null); DomainOperationException expectedException = null; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); try { lo.Complete(ex); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "ThrowGeneralException", ex.Message), expectedException.Message); Assert.AreEqual(ex.StackTrace, expectedException.StackTrace); Assert.AreEqual(ex.Status, expectedException.Status); Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode); Assert.AreEqual(false, lo.IsErrorHandled); // now test again with validation errors expectedException = null; ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) }; lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null); try { lo.Complete(validationErrors); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed_Validation, "ThrowGeneralException"), expectedException.Message); }