Summary

Class:WireMock.Validation.Check
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Validation\Check.cs
Covered lines:27
Uncovered lines:44
Coverable lines:71
Total lines:139
Line coverage:38%
Branch coverage:35%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
Condition(...)2266.6766.67
NotNull(...)2257.1466.67
NotNull(...)2200
NotNullOrEmpty(...)2262.566.67
NotNullOrEmpty(...)4843.7557.14
NullButNotEmpty(...)3200
HasNoNulls(...)3262.566.67
ValidEntityType(...)2200

File(s)

C:\Users\azureuser\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] [
 220        {
 221            NotNull(condition, nameof(condition));
 222            NotNull(value, nameof(value));
 23
 224             if (!condition(value))
 025            {
 026                NotNullOrEmpty(parameterName, nameof(parameterName));
 27
 028                throw new ArgumentOutOfRangeException(parameterName);
 29            }
 30
 231            return value;
 232        }
 33
 34        [ContractAnnotation("value:null => halt")]
 35        public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
 185136        {
 185137             if (ReferenceEquals(value, null))
 038            {
 039                NotNullOrEmpty(parameterName, nameof(parameterName));
 40
 041                throw new ArgumentNullException(parameterName);
 42            }
 43
 185144            return value;
 185145        }
 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)
 28763        {
 28764            NotNull(value, parameterName);
 65
 28766             if (value.Count == 0)
 067            {
 068                NotNullOrEmpty(parameterName, nameof(parameterName));
 69
 070                throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
 71            }
 72
 28773            return value;
 28774        }
 75
 76        [ContractAnnotation("value:null => halt")]
 77        public static string NotNullOrEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 678        {
 679            Exception e = null;
 680             if (ReferenceEquals(value, null))
 081            {
 082                e = new ArgumentNullException(parameterName);
 083            }
 684             else if (value.Trim().Length == 0)
 085            {
 086                e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 087            }
 88
 689             if (e != null)
 090            {
 091                NotNullOrEmpty(parameterName, nameof(parameterName));
 92
 093                throw e;
 94            }
 95
 696            return value;
 697        }
 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
 15114        {
 15115            NotNull(value, parameterName);
 116
 32117             if (value.Any(e => e == null))
 0118            {
 0119                NotNullOrEmpty(parameterName, nameof(parameterName));
 120
 0121                throw new ArgumentException(parameterName);
 122            }
 123
 15124            return value;
 15125        }
 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}