Exemple #1
0
 /// <summary>
 /// Throws an exception if there are any validation errors
 /// </summary>
 /// <param name="context">The <see cref="OperationContext"/> of the validation errors</param>
 /// <param name="validationErrors">The validation errors</param>
 /// <exception cref="DomainServiceTestHostException">is thrown if there are any validation errors</exception>
 public static void AssertNoValidationErrors(OperationContext context, IEnumerable <ValidationResult> validationErrors)
 {
     if ((validationErrors != null) && validationErrors.Any())
     {
         ErrorUtility.ReportErrors(context, validationErrors.Select(vr => ErrorUtility.GetErrorMessageForValidation(vr)));
     }
 }
        /// <summary>
        /// Invokes one or several operation according to the specified <paramref name="changeSet"/>
        /// </summary>
        /// <param name="context"><see cref="OperationContext"/> for the current operation</param>
        /// <param name="changeSet">The <see cref="ChangeSet"/> identifying the operations to invoke.</param>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any <see cref="ChangeSet"/> errors</exception>
        private static void SubmitChangeSetCore(OperationContext context, ChangeSet changeSet)
        {
            // TODO: Remove blocking await
            context.DomainService.SubmitAsync(changeSet, CancellationToken.None)
            .GetAwaiter().GetResult();

            ErrorUtility.AssertNoChangeSetErrors(context, changeSet);
        }
        /// <summary>
        /// Invokes the specified <paramref name="invokeOperation"/> and returns the result
        /// </summary>
        /// <typeparam name="TResult">The result type</typeparam>
        /// <param name="invokeOperation">The <see cref="Expression"/> identifying the operation to invoke</param>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any validation errors</exception>
        private TResult InvokeCore <TResult>(Expression invokeOperation)
        {
            OperationContext context = this.CreateOperationContext(DomainOperationType.Invoke);

            InvokeDescription invokeDescription = Utility.GetInvokeDescription(context, invokeOperation);
            IEnumerable <ValidationResult> validationErrors;

            TResult result = (TResult)context.DomainService.Invoke(invokeDescription, out validationErrors);

            ErrorUtility.AssertNoValidationErrors(context, validationErrors);

            return(result);
        }
        /// <summary>
        /// Invokes the specified <paramref name="queryOperation"/> and returns the results
        /// </summary>
        /// <typeparam name="TEntity">The type of entity to return</typeparam>
        /// <param name="queryOperation">The <see cref="Expression"/> identifying the query operation to invoke</param>
        /// <returns>The entities returned from the specified operation</returns>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any validation errors</exception>
        private IEnumerable <TEntity> QueryCore <TEntity>(Expression queryOperation) where TEntity : class
        {
            OperationContext context = this.CreateOperationContext(DomainOperationType.Query);

            QueryDescription queryDescription = Utility.GetQueryDescription(context, queryOperation);
            IEnumerable <ValidationResult> validationErrors;
            int totalCount;

            IEnumerable entities = context.DomainService.Query(queryDescription, out validationErrors, out totalCount);

            ErrorUtility.AssertNoValidationErrors(context, validationErrors);

            return((entities == null) ? null : entities.Cast <TEntity>());
        }
        /// <summary>
        /// Invokes the specified <paramref name="invokeOperation"/> and returns the result
        /// </summary>
        /// <typeparam name="TResult">The result type</typeparam>
        /// <param name="invokeOperation">The <see cref="Expression"/> identifying the operation to invoke</param>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any validation errors</exception>
        private TResult InvokeCore <TResult>(Expression invokeOperation)
        {
            OperationContext context = this.CreateOperationContext(DomainOperationType.Invoke);

            InvokeDescription invokeDescription = Utility.GetInvokeDescription(context, invokeOperation);

            // TODO: Remove blocking wait
            var invokeResult = context.DomainService.InvokeAsync(invokeDescription, CancellationToken.None).GetAwaiter().GetResult();

            ErrorUtility.AssertNoValidationErrors(context, invokeResult.ValidationErrors);
            TResult result = (TResult)invokeResult.Result;

            return(result);
        }
        /// <summary>
        /// Invokes the specified <paramref name="queryOperation"/> and returns the results
        /// </summary>
        /// <typeparam name="TEntity">The type of entity to return</typeparam>
        /// <param name="queryOperation">The <see cref="Expression"/> identifying the query operation to invoke</param>
        /// <returns>The entities returned from the specified operation</returns>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any validation errors</exception>
        private IEnumerable <TEntity> QueryCore <TEntity>(Expression queryOperation) where TEntity : class
        {
            OperationContext context = this.CreateOperationContext(DomainOperationType.Query);

            QueryDescription queryDescription = Utility.GetQueryDescription(context, queryOperation);

            var queryTask = context.DomainService.QueryAsync <TEntity>(queryDescription, CancellationToken.None);
            // TODO: Remove blocking wait
            var queryResult = queryTask.GetAwaiter().GetResult();

            ErrorUtility.AssertNoValidationErrors(context, queryResult.ValidationErrors);

            IEnumerable entities = queryResult.Result;

            return((entities == null) ? null : entities.Cast <TEntity>());
        }
Exemple #7
0
 /// <summary>
 /// Throws an exception if there are any change set errors
 /// </summary>
 /// <param name="context">The <see cref="OperationContext"/> of the change set</param>
 /// <param name="changeSet">The change set</param>
 /// <exception cref="DomainServiceTestHostException">is thrown if there are any change set errors</exception>
 public static void AssertNoChangeSetErrors(OperationContext context, ChangeSet changeSet)
 {
     if (changeSet.HasError)
     {
         List <string> errorMessages = new List <string>();
         foreach (ChangeSetEntry entry in changeSet.ChangeSetEntries)
         {
             if ((entry.ValidationErrors != null) && entry.ValidationErrors.Any())
             {
                 errorMessages.Add(ErrorUtility.GetErrorMessageForValidation(entry));
             }
             if ((entry.ConflictMembers != null) && entry.ConflictMembers.Any())
             {
                 errorMessages.Add(ErrorUtility.GetErrorMessageForConflicts(entry));
             }
         }
         ErrorUtility.ReportErrors(context, errorMessages);
     }
 }
        /// <summary>
        /// Invokes one or several operation according to the specified <paramref name="changeSet"/>
        /// </summary>
        /// <param name="context"><see cref="OperationContext"/> for the current operation</param>
        /// <param name="changeSet">The <see cref="ChangeSet"/> identifying the operations to invoke.</param>
        /// <exception cref="DomainServiceTestHostException">is thrown if there are any <see cref="ChangeSet"/> errors</exception>
        private static void SubmitChangeSetCore(OperationContext context, ChangeSet changeSet)
        {
            context.DomainService.Submit(changeSet);

            ErrorUtility.AssertNoChangeSetErrors(context, changeSet);
        }
Exemple #9
0
 private static string GetErrorMessageForValidation(ChangeSetEntry changeSetEntry)
 {
     return(string.Format(
                CultureInfo.CurrentCulture,
                "Validation failed for the entity '{0}' with one or more errors: {1}.",
                changeSetEntry.Entity.GetType(),
                string.Join(", ", changeSetEntry.ValidationErrors.Select(vri => ErrorUtility.GetErrorMessageForValidation(vri)))));
 }