Summary

Class:WireMock.Validation.Check
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Validation\Check.cs
Covered lines:15
Uncovered lines:56
Coverable lines:71
Total lines:143
Line coverage:21.1%
Branch coverage:15%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
Condition(...)2266.6766.67
NotNull(...)2257.1466.67
NotNull(...)2200
NotEmpty(...)2262.566.67
NotEmpty(...)4800
NullButNotEmpty(...)3200
HasNoNulls(...)3200
ValidEntityType(...)2200

File(s)

C:\Users\Stef\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.Diagnostics.CodeAnalysis;
 8using System.Linq;
 9using System.Reflection;
 10using JetBrains.Annotations;
 11
 12// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
 13namespace WireMock.Validation
 14{
 15    [ExcludeFromCodeCoverage]
 16    [DebuggerStepThrough]
 17    internal static class Check
 18    {
 19        [ContractAnnotation("value:null => halt")]
 20        public static T Condition<T>([NoEnumeration] T value, [NotNull] Predicate<T> condition, [InvokerParameterName] [
 121        {
 122            NotNull(condition, nameof(condition));
 123            NotNull(value, nameof(value));
 24
 125             if (!condition(value))
 026            {
 027                NotEmpty(parameterName, nameof(parameterName));
 28
 029                throw new ArgumentOutOfRangeException(parameterName);
 30            }
 31
 132            return value;
 133        }
 34
 35        [ContractAnnotation("value:null => halt")]
 36        public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
 52937        {
 52938             if (ReferenceEquals(value, null))
 039            {
 040                NotEmpty(parameterName, nameof(parameterName));
 41
 042                throw new ArgumentNullException(parameterName);
 43            }
 44
 52945            return value;
 52946        }
 47
 48        [ContractAnnotation("value:null => halt")]
 49        public static T NotNull<T>(
 50            [NoEnumeration] T value,
 51            [InvokerParameterName] [NotNull] string parameterName,
 52            [NotNull] string propertyName)
 053        {
 054             if (ReferenceEquals(value, null))
 055            {
 056                NotEmpty(parameterName, nameof(parameterName));
 057                NotEmpty(propertyName, nameof(propertyName));
 58
 059                throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
 60            }
 61
 062            return value;
 063        }
 64
 65        [ContractAnnotation("value:null => halt")]
 66        public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 7267        {
 7268            NotNull(value, parameterName);
 69
 7270             if (value.Count == 0)
 071            {
 072                NotEmpty(parameterName, nameof(parameterName));
 73
 074                throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
 75            }
 76
 7277            return value;
 7278        }
 79
 80        [ContractAnnotation("value:null => halt")]
 81        public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 082        {
 083            Exception e = null;
 084             if (ReferenceEquals(value, null))
 085            {
 086                e = new ArgumentNullException(parameterName);
 087            }
 088             else if (value.Trim().Length == 0)
 089            {
 090                e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 091            }
 92
 093             if (e != null)
 094            {
 095                NotEmpty(parameterName, nameof(parameterName));
 96
 097                throw e;
 98            }
 99
 0100            return value;
 0101        }
 102
 103        public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 0104        {
 0105             if (!ReferenceEquals(value, null)
 0106                && (value.Length == 0))
 0107            {
 0108                NotEmpty(parameterName, nameof(parameterName));
 109
 0110                throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 111            }
 112
 0113            return value;
 0114        }
 115
 116        public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 117            where T : class
 0118        {
 0119            NotNull(value, parameterName);
 120
 0121             if (value.Any(e => e == null))
 0122            {
 0123                NotEmpty(parameterName, nameof(parameterName));
 124
 0125                throw new ArgumentException(parameterName);
 126            }
 127
 0128            return value;
 0129        }
 130
 131        public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName)
 0132        {
 0133             if (!value.GetTypeInfo().IsClass)
 0134            {
 0135                NotEmpty(parameterName, nameof(parameterName));
 136
 0137                throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
 138            }
 139
 0140            return value;
 0141        }
 142    }
 143}