< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.TaskOperationDescriptionValidator
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/TaskOperationDescriptionValidator.cs
Line coverage
59%
Covered lines: 16
Uncovered lines: 11
Coverable lines: 27
Total lines: 73
Line coverage: 59.2%
Branch coverage
55%
Covered branches: 10
Total branches: 18
Branch coverage: 55.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Validate(...)75%4487.5%
EnsureNoSyncMethod(...)50%2240%
EnsureNoBeginEndMethod(...)50%2240%
EnsureParametersAreSupported(...)62.5%8883.33%
EnsureNoOutputParameters(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/TaskOperationDescriptionValidator.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Reflection;
 6
 7namespace CoreWCF.Description
 8{
 9    internal static class TaskOperationDescriptionValidator
 10    {
 11        internal static void Validate(OperationDescription operationDescription, bool isForService)
 12        {
 264513            MethodInfo taskMethod = operationDescription.TaskMethod;
 264514            if (taskMethod != null)
 15            {
 32916                if (isForService)
 17                {
 18                    // no other method (sync, async) is allowed to co-exist with a task-based method on the server-side.
 32919                    EnsureNoSyncMethod(operationDescription);
 32920                    EnsureNoBeginEndMethod(operationDescription);
 21                }
 22                else
 23                {
 24                    // no out/ref parameter is allowed on the client-side.
 025                    EnsureNoOutputParameters(taskMethod);
 26                }
 27
 32928                EnsureParametersAreSupported(taskMethod);
 29            }
 264530        }
 31
 32        private static void EnsureNoSyncMethod(OperationDescription operation)
 33        {
 32934            if (operation.SyncMethod != null)
 35            {
 036                string method1Name = operation.TaskMethod.Name;
 037                string method2Name = operation.SyncMethod.Name;
 038                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Can
 39            }
 32940        }
 41
 42        private static void EnsureNoBeginEndMethod(OperationDescription operation)
 43        {
 32944            if (operation.BeginMethod != null)
 45            {
 046                string method1Name = operation.TaskMethod.Name;
 047                string method2Name = operation.BeginMethod.Name;
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Can
 49            }
 32950        }
 51
 52        private static void EnsureParametersAreSupported(MethodInfo method)
 53        {
 122054            foreach (ParameterInfo parameter in method.GetParameters())
 55            {
 28156                Type parameterType = parameter.ParameterType;
 28157                if ((parameterType == ServiceReflector.CancellationTokenType) ||
 28158                    (parameterType.GetTypeInfo().IsGenericType && parameterType.GetGenericTypeDefinition() == ServiceRef
 59                {
 060                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Tas
 61                }
 62            }
 32963        }
 64
 65        private static void EnsureNoOutputParameters(MethodInfo method)
 66        {
 067            if (ServiceReflector.HasOutputParameters(method, false))
 68            {
 069                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.TaskMethodMus
 70            }
 071        }
 72    }
 73}