Summary

Class:WireMock.Validation.Check
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Validation\Check.cs
Covered lines:39
Uncovered lines:32
Coverable lines:71
Total lines:139
Line coverage:54.9%
Branch coverage:54.1%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
Condition(...)0011
NotNull(...)0011
NotNull(...)0000
NotNullOrEmpty(...)000.6250.5
NotNullOrEmpty(...)000.8120.833
NullButNotEmpty(...)0000
HasNoNulls(...)000.6250.75
ValidEntityType(...)0000

File(s)

C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Validation\Check.cs

#LineLine coverage
 1// Copyright (c) .NET Foundation. All rights reserved.
 2// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Linq;
 8using System.Reflection;
 9using JetBrains.Annotations;
 10
 11// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
 12namespace WireMock.Validation
 13{
 14    // [ExcludeFromCodeCoverage]
 15    [DebuggerStepThrough]
 16    internal static class Check
 17    {
 18        [ContractAnnotation("value:null => halt")]
 19        public static T Condition<T>([NoEnumeration] T value, [NotNull] Predicate<T> condition, [InvokerParameterName] [
 2420        {
 2421            NotNull(condition, nameof(condition));
 2422            NotNull(value, nameof(value));
 23
 2424            if (!condition(value))
 125            {
 126                NotNullOrEmpty(parameterName, nameof(parameterName));
 27
 128                throw new ArgumentOutOfRangeException(parameterName);
 29            }
 30
 2331            return value;
 2332        }
 33
 34        [ContractAnnotation("value:null => halt")]
 35        public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
 405236        {
 405337            if (ReferenceEquals(value, null))
 238            {
 239                NotNullOrEmpty(parameterName, nameof(parameterName));
 40
 241                throw new ArgumentNullException(parameterName);
 42            }
 43
 405044            return value;
 405145        }
 46
 47        [ContractAnnotation("value:null => halt")]
 48        public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName, [NotN
 049        {
 050            if (ReferenceEquals(value, null))
 051            {
 052                NotNullOrEmpty(parameterName, nameof(parameterName));
 053                NotNullOrEmpty(propertyName, nameof(propertyName));
 54
 055                throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
 56            }
 57
 058            return value;
 059        }
 60
 61        [ContractAnnotation("value:null => halt")]
 62        public static IList<T> NotNullOrEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 45563        {
 45564            NotNull(value, parameterName);
 65
 45566            if (value.Count == 0)
 067            {
 068                NotNullOrEmpty(parameterName, nameof(parameterName));
 69
 070                throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
 71            }
 72
 45673            return value;
 45674        }
 75
 76        [ContractAnnotation("value:null => halt")]
 77        public static string NotNullOrEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 3678        {
 3679            Exception e = null;
 3680            if (ReferenceEquals(value, null))
 281            {
 282                e = new ArgumentNullException(parameterName);
 283            }
 3484            else if (value.Trim().Length == 0)
 085            {
 086                e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 087            }
 88
 3689            if (e != null)
 290            {
 291                NotNullOrEmpty(parameterName, nameof(parameterName));
 92
 293                throw e;
 94            }
 95
 3496            return value;
 3497        }
 98
 99        public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 0100        {
 0101            if (!ReferenceEquals(value, null)
 0102                && (value.Length == 0))
 0103            {
 0104                NotNullOrEmpty(parameterName, nameof(parameterName));
 105
 0106                throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 107            }
 108
 0109            return value;
 0110        }
 111
 112        public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 113            where T : class
 39114        {
 39115            NotNull(value, parameterName);
 116
 78117            if (value.Any(e => e == null))
 0118            {
 0119                NotNullOrEmpty(parameterName, nameof(parameterName));
 120
 0121                throw new ArgumentException(parameterName);
 122            }
 123
 39124            return value;
 39125        }
 126
 127        public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName)
 0128        {
 0129            if (!value.GetTypeInfo().IsClass)
 0130            {
 0131                NotNullOrEmpty(parameterName, nameof(parameterName));
 132
 0133                throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
 134            }
 135
 0136            return value;
 0137        }
 138    }
 139}